Skip to content

Commit cca750e

Browse files
committed
re-enable dane web
1 parent 9933073 commit cca750e

File tree

1 file changed

+14
-78
lines changed

1 file changed

+14
-78
lines changed

checks/tasks/tls.py

Lines changed: 14 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
from celery import shared_task
1414
from celery.exceptions import SoftTimeLimitExceeded
1515
from celery.utils.log import get_task_logger
16-
from cryptography.hazmat.backends import default_backend
1716
from cryptography.hazmat.backends.openssl import rsa
1817
from cryptography.hazmat.primitives import hashes
18+
from cryptography.hazmat.primitives.serialization import Encoding
1919
from cryptography.hazmat.primitives.asymmetric import dsa, x25519, x448, ec
2020
from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePublicKey
2121
from cryptography.x509 import (
@@ -1034,7 +1034,7 @@ def build_summary_report(testtls, category):
10341034
testtls.report = report
10351035

10361036

1037-
def dane(url, port, chain, task, dane_cb_data, score_none, score_none_bogus, score_failed, score_validated):
1037+
def dane(url: str, port: int, chain: List[Certificate], task, dane_cb_data, score_none, score_none_bogus, score_failed, score_validated):
10381038
"""
10391039
Check if there are TLSA records, if they are valid and if a DANE rollover
10401040
scheme is currently in place.
@@ -1108,9 +1108,8 @@ def dane(url, port, chain, task, dane_cb_data, score_none, score_none_bogus, sco
11081108

11091109
chain_pem = []
11101110
for cert in chain:
1111-
chain_pem.append(cert.as_pem())
1111+
chain_pem.append(cert.public_bytes(Encoding.PEM).decode("ascii"))
11121112
chain_txt = "\n".join(chain_pem)
1113-
res = None
11141113
with subprocess.Popen(
11151114
[
11161115
settings.LDNS_DANE,
@@ -1191,74 +1190,6 @@ def get_common_name(cert):
11911190
pass
11921191
return value
11931192

1194-
1195-
class DebugCertChain:
1196-
"""
1197-
Class performing X509 cert checks NCSC Guidelines B3-*
1198-
1199-
"""
1200-
1201-
def __new__(cls, chain):
1202-
"""
1203-
In case the chain is None (ValueError from nassl) don't create an
1204-
instance. Instead return None and it will be handled during the
1205-
certificate checks.
1206-
1207-
"""
1208-
if chain is None:
1209-
return None
1210-
return super().__new__(cls)
1211-
1212-
def __init__(self, chain):
1213-
self.unparsed_chain = chain
1214-
self.chain = [
1215-
load_pem_x509_certificate(cert.as_pem().encode("ascii"), backend=default_backend()) for cert in chain
1216-
]
1217-
self.score_hostmatch_good = scoring.WEB_TLS_HOSTMATCH_GOOD
1218-
self.score_hostmatch_bad = scoring.WEB_TLS_HOSTMATCH_BAD
1219-
self.score_pubkey_good = scoring.WEB_TLS_PUBKEY_GOOD
1220-
self.score_pubkey_bad = scoring.WEB_TLS_PUBKEY_BAD
1221-
self.score_signature_good = scoring.WEB_TLS_SIGNATURE_GOOD
1222-
self.score_signature_bad = scoring.WEB_TLS_SIGNATURE_BAD
1223-
self.score_dane_none = scoring.WEB_TLS_DANE_NONE
1224-
self.score_dane_none_bogus = scoring.WEB_TLS_DANE_NONE_BOGUS
1225-
self.score_dane_failed = scoring.WEB_TLS_DANE_FAILED
1226-
self.score_dane_validated = scoring.WEB_TLS_DANE_VALIDATED
1227-
1228-
def check_dane(self, url, port, task, dane_cb_data=None):
1229-
return dane(
1230-
url,
1231-
port,
1232-
self.unparsed_chain,
1233-
task,
1234-
dane_cb_data,
1235-
self.score_dane_none,
1236-
self.score_dane_none_bogus,
1237-
self.score_dane_failed,
1238-
self.score_dane_validated,
1239-
)
1240-
1241-
1242-
class DebugCertChainMail(DebugCertChain):
1243-
"""
1244-
Subclass of DebugCertChain to define the scores used for the mailtest.
1245-
1246-
"""
1247-
1248-
def __init__(self, chain):
1249-
super().__init__(chain)
1250-
self.score_hostmatch_good = scoring.MAIL_TLS_HOSTMATCH_GOOD
1251-
self.score_hostmatch_bad = scoring.MAIL_TLS_HOSTMATCH_BAD
1252-
self.score_pubkey_good = scoring.MAIL_TLS_PUBKEY_GOOD
1253-
self.score_pubkey_bad = scoring.MAIL_TLS_PUBKEY_BAD
1254-
self.score_signature_good = scoring.MAIL_TLS_SIGNATURE_GOOD
1255-
self.score_signature_bad = scoring.MAIL_TLS_SIGNATURE_BAD
1256-
self.score_dane_none = scoring.MAIL_TLS_DANE_NONE
1257-
self.score_dane_none_bogus = scoring.MAIL_TLS_DANE_NONE_BOGUS
1258-
self.score_dane_failed = scoring.MAIL_TLS_DANE_FAILED
1259-
self.score_dane_validated = scoring.MAIL_TLS_DANE_VALIDATED
1260-
1261-
12621193
def do_web_cert(af_ip_pairs, url, task, *args, **kwargs):
12631194
"""
12641195
Check the web server's certificate.
@@ -1282,6 +1213,11 @@ def cert_checks(url, mode, task, af_ip_pair=None, dane_cb_data=None, *args, **kw
12821213
Perform certificate checks.
12831214
12841215
"""
1216+
# TODO: common property?
1217+
ports = {
1218+
ChecksMode.WEB: 443,
1219+
ChecksMode.MAIL: 25,
1220+
}
12851221
# TODO: this does use our trust store
12861222
if mode == ChecksMode.WEB:
12871223
print(f"starting sslyze scan for {url} {af_ip_pair[1]} {dane_cb_data}")
@@ -1379,11 +1315,11 @@ def cert_checks(url, mode, task, af_ip_pair=None, dane_cb_data=None, *args, **kw
13791315
for cert in cert_deployment.received_certificate_chain:
13801316
chain_str.append(get_common_name(cert))
13811317

1382-
# TODO: DANE
1383-
# if starttls_details:
1384-
# dane_results = debug_chain.check_dane(url, conn_port, task, dane_cb_data=starttls_details.dane_cb_data)
1385-
# else:
1386-
# dane_results = debug_chain.check_dane(url, conn_port, task)
1318+
dane_results = dane(url, ports[mode], cert_deployment.received_certificate_chain, task,
1319+
dane_cb_data, scoring.WEB_TLS_DANE_NONE,
1320+
scoring.WEB_TLS_DANE_NONE_BOGUS,
1321+
scoring.WEB_TLS_DANE_FAILED,
1322+
scoring.WEB_TLS_DANE_VALIDATED)
13871323

13881324
results = dict(
13891325
tls_cert=True,
@@ -1398,7 +1334,7 @@ def cert_checks(url, mode, task, af_ip_pair=None, dane_cb_data=None, *args, **kw
13981334
hostmatch_bad=hostmatch_bad,
13991335
hostmatch_score=hostmatch_score,
14001336
)
1401-
# results.update(dane_results)
1337+
results.update(dane_results)
14021338

14031339
return results
14041340

0 commit comments

Comments
 (0)