Skip to content

Commit ed618e2

Browse files
committed
Switch to smtplib.SMTP for more compliant SMTP handling
The current "client" did not wait for the greeting to finish before sending commands, and took some other liberties with the SMTP standard. This causes issues with some servers.
1 parent 7c38a4e commit ed618e2

File tree

9 files changed

+20932
-20504
lines changed

9 files changed

+20932
-20504
lines changed

sslyze/connection_helpers/opportunistic_tls_helpers.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import struct
33
from abc import abstractmethod, ABC
44
from enum import Enum
5+
from smtplib import SMTP, SMTPException
56
from typing import ClassVar, Optional
67

78

@@ -65,19 +66,37 @@ def __init__(self, smtp_ehlo_hostname: str):
6566
self._smtp_ehlo_hostname = smtp_ehlo_hostname
6667

6768
def prepare_socket_for_tls_handshake(self, sock: socket.socket) -> None:
68-
# Get the SMTP banner
69-
sock.recv(2048)
69+
# SMTP parsing has some complicated areas and some unusual but legal
70+
# server behavior - this code uses Python's smtplib to handle the protocol.
71+
smtp = SMTP(local_hostname=self._smtp_ehlo_hostname)
72+
smtp.sock = sock
7073

71-
# Send a EHLO and wait for the 250 status
72-
sock.send(f"EHLO {self._smtp_ehlo_hostname}\r\n".encode("ascii"))
73-
data = sock.recv(2048)
74-
if b"250 " not in data:
75-
raise OpportunisticTlsError(f"SMTP EHLO was rejected: {repr(data)}")
74+
try:
75+
code, server_reply = smtp.getreply()
76+
message = server_reply.decode()
77+
except SMTPException as exc:
78+
code, message = -1, str(exc)
79+
if code != 220:
80+
raise OpportunisticTlsError(f"Unable to find 220 service ready response: {message}")
81+
82+
try:
83+
code, server_reply = smtp.getreply()
84+
message = server_reply.decode()
85+
except SMTPException as exc:
86+
code, message = -1, str(exc)
87+
if code != 250:
88+
raise OpportunisticTlsError(f"SMTP EHLO was rejected: {message}")
89+
90+
if not smtp.has_extn("starttls"):
91+
raise OpportunisticTlsError(f"Server does not support STARTTLS: {message}")
7692

77-
# Send a STARTTLS
78-
sock.send(b"STARTTLS\r\n")
79-
if b"220" not in sock.recv(2048):
80-
raise OpportunisticTlsError("SMTP STARTTLS not supported")
93+
try:
94+
code, server_reply = smtp.getreply()
95+
message = server_reply.decode()
96+
except SMTPException as exc:
97+
code, message = -1, str(exc)
98+
if code != 220:
99+
raise OpportunisticTlsError(f"SMTP STARTTLS rejected: {message}")
81100

82101

83102
class _XmppHelper(_OpportunisticTlsHelper):

sslyze/plugins/certificate_info/trust_stores/pem_files/apple.pem

Lines changed: 3730 additions & 3730 deletions
Large diffs are not rendered by default.

sslyze/plugins/certificate_info/trust_stores/pem_files/google_aosp.pem

Lines changed: 3221 additions & 2964 deletions
Large diffs are not rendered by default.

sslyze/plugins/certificate_info/trust_stores/pem_files/google_aosp.yaml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
platform: GOOGLE_AOSP
2-
version: 14.0.0_r9
2+
version: 15.0.0_r1
33
url: https://android.googlesource.com/platform/system/ca-certificates
4-
date_fetched: 2023-10-15
5-
trusted_certificates_count: 134
4+
date_fetched: 2024-09-08
5+
trusted_certificates_count: 145
66
trusted_certificates:
77
- subject_name: AAA Certificate Services
88
fingerprint: d7a7a0fb5d7e2731d771e9484ebcdef71d5f0c3e0a2948782bc83ee0ea699ef4
@@ -34,10 +34,16 @@ trusted_certificates:
3434
fingerprint: e35d28419ed02025cfa69038cd623962458da5c695fbdea3c22b0bfb25897092
3535
- subject_name: Atos TrustedRoot 2011
3636
fingerprint: f356bea244b7a91eb35d53ca9ad7864ace018e2d35d5f8f96ddf68a6f41aa474
37-
- subject_name: Autoridad de Certificacion Firmaprofesional CIF A62634068
38-
fingerprint: 04048028bf1f2864d48f9ad4d83294366a828856553f3b14303f90147f5d40ef
37+
- subject_name: Atos TrustedRoot Root CA ECC TLS 2021
38+
fingerprint: b2fae53e14ccd7ab9212064701ae279c1d8988facb775fa8a008914e663988a8
39+
- subject_name: Atos TrustedRoot Root CA RSA TLS 2021
40+
fingerprint: 81a9088ea59fb364c548a6f85559099b6f0405efbf18e5324ec9f457ba00112f
3941
- subject_name: Autoridad de Certificacion Firmaprofesional CIF A62634068
4042
fingerprint: 57de0583efd2b26e0361da99da9df4648def7ee8441c3b728afa9bcde0f9b26a
43+
- subject_name: BJCA Global Root CA1
44+
fingerprint: f3896f88fe7c0a882766a7fa6ad2749fb57a7f3e98fb769c1fa7b09c2c44d5ae
45+
- subject_name: BJCA Global Root CA2
46+
fingerprint: 574df6931e278039667b720afdc1600fc27eb66dd3092979fb73856487212882
4147
- subject_name: Baltimore CyberTrust Root
4248
fingerprint: 16af57a9f676b0ab126095aa5ebadef22ab31119d644ac95cd4b93dbf3f26aeb
4349
- subject_name: Buypass Class 2 Root CA
@@ -70,6 +76,14 @@ trusted_certificates:
7076
fingerprint: b676f2eddae8775cd36cb0f63cd1d4603961f49e6265ba013a2f0307b6d0b804
7177
- subject_name: Certum Trusted Root CA
7278
fingerprint: fe7696573855773e37a95e7ad4d9cc96c30157c15d31765ba9b15704e1ae78fd
79+
- subject_name: CommScope Public Trust ECC Root-01
80+
fingerprint: 11437cda7bb45e41365f45b39a38986b0de00def348e0c7bb0873633800bc38b
81+
- subject_name: CommScope Public Trust ECC Root-02
82+
fingerprint: 2ffb7f813bbbb3c89ab4e8162d0f16d71509a830cc9d73c262e5140875d1ad4a
83+
- subject_name: CommScope Public Trust RSA Root-01
84+
fingerprint: 02bdf96e2a45dd9bf18fc7e1dbdf21a0379ba3c9c2610344cfd8d606fec1ed81
85+
- subject_name: CommScope Public Trust RSA Root-02
86+
fingerprint: ffe943d793424b4f7c440c1c3d648d5363f34b82dc87aa7a9f118fc5dee101f1
7387
- subject_name: D-TRUST BR Root CA 1 2020
7488
fingerprint: e59aaa816009c22bff5b25bad37df306f049797c1f81d85ab089e657bd8f0044
7589
- subject_name: D-TRUST EV Root CA 1 2020
@@ -148,8 +162,6 @@ trusted_certificates:
148162
fingerprint: a040929a02ce53b4acf4f2ffc6981ce4496f755e6d45fe0b2a692bcd52523f36
149163
- subject_name: HiPKI Root CA - G1
150164
fingerprint: f015ce3cc239bfef064be9f1d2c417e1a0264a0a94be1f0c8d121864eb6949cc
151-
- subject_name: Hongkong Post Root CA 1
152-
fingerprint: f9e67d336c51002ac054c632022d66dda2e7e3fff10ad061ed31d8bbb410cfb2
153165
- subject_name: Hongkong Post Root CA 3
154166
fingerprint: 5a2fc03f0c83b090bbfa40604b0988446c7636183df9846e17101a447fb8efd6
155167
- subject_name: ISRG Root X1
@@ -194,8 +206,16 @@ trusted_certificates:
194206
fingerprint: 3417bb06cc6007da1b961c920b8ab4ce3fad820e4aa30b9acbc4a74ebdcebc65
195207
- subject_name: SSL.com Root Certification Authority RSA
196208
fingerprint: 85666a562ee0be5ce925c1d8890a6f76a87ec16d4d7d5f29ea7419cf20123b69
209+
- subject_name: SSL.com TLS ECC Root CA 2022
210+
fingerprint: c32ffd9f46f936d16c3673990959434b9ad60aafbb9e7cf33654f144cc1ba143
211+
- subject_name: SSL.com TLS RSA Root CA 2022
212+
fingerprint: 8faf7d2e2cb4709bb8e0b33666bf75a5dd45b5de480f8ea8d4bfe6bebc17f2ed
197213
- subject_name: SZAFIR ROOT CA2
198214
fingerprint: a1339d33281a0b56e557d3d32b1ce7f9367eb094bd5fa72a7e5004c8ded7cafe
215+
- subject_name: Sectigo Public Server Authentication Root E46
216+
fingerprint: c90f26f0fb1b4018b22227519b5ca2b53e2ca5b3be5cf18efe1bef47380c5383
217+
- subject_name: Sectigo Public Server Authentication Root R46
218+
fingerprint: 7bb647a62aeeac88bf257aa522d01ffea395e0ab45c73f93f65654ec38f25a06
199219
- subject_name: Secure Global CA
200220
fingerprint: 4200f5043ac8590ebb527d209ed1503029fbcbd41ca1b506ec27f15ade7dac69
201221
- subject_name: SecureSign RootCA11
@@ -204,8 +224,6 @@ trusted_certificates:
204224
fingerprint: f1c1b50ae5a20dd8030ec9f6bc24823dd367b5255759b4e71b61fce9f7375d73
205225
- subject_name: Security Communication ECC RootCA1
206226
fingerprint: e74fbda55bd564c473a36b441aa799c8a68e077440e8288b9fa1e50e4bbaca11
207-
- subject_name: Security Communication RootCA1
208-
fingerprint: e75e72ed9f560eec6eb4800073a43fc3ad19195a392282017895974a99026b6c
209227
- subject_name: Security Communication RootCA2
210228
fingerprint: 513b2cecb810d4cde5dd85391adfc6c2dd60d87bb736d2b521484aa47a0ebef6
211229
- subject_name: Security Communication RootCA3
@@ -234,6 +252,10 @@ trusted_certificates:
234252
fingerprint: 242b69742fcb1e5b2abf98898b94572187544e5b4d9911786573621f6a74b82c
235253
- subject_name: TeliaSonera Root CA v1
236254
fingerprint: dd6936fe21f8f077c123a1a521c12224f72255b73e03a7260693e8a24b0fa389
255+
- subject_name: TrustAsia Global Root CA G3
256+
fingerprint: e0d3226aeb1163c2e48ff9be3b50b4c6431be7bb1eacc5c36b5d5ec509039a08
257+
- subject_name: TrustAsia Global Root CA G4
258+
fingerprint: be4b56cb5056c0136a526df444508daa36a0b54f42e4ac38f72af470e479654c
237259
- subject_name: Trustwave Global Certification Authority
238260
fingerprint: 97552015f5ddfc3c8788c006944555408894450084f100867086bc1a2bb58dc8
239261
- subject_name: Trustwave Global ECC P256 Certification Authority

0 commit comments

Comments
 (0)