mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 08:08:00 +02:00
Collect certs in a subdir.
This commit is contained in:
+10
-10
@@ -14,6 +14,7 @@ from M2Crypto import X509
|
|||||||
from publicsuffix import PublicSuffixList
|
from publicsuffix import PublicSuffixList
|
||||||
|
|
||||||
public_suffix_list = PublicSuffixList()
|
public_suffix_list = PublicSuffixList()
|
||||||
|
CERTS_OBSERVED = 'certs-observed'
|
||||||
|
|
||||||
def mkdirp(path):
|
def mkdirp(path):
|
||||||
try:
|
try:
|
||||||
@@ -63,7 +64,7 @@ def tls_connect(mx_host, mail_domain):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Save a copy of the certificate for later analysis
|
# Save a copy of the certificate for later analysis
|
||||||
with open(os.path.join(mail_domain, mx_host), "w") as f:
|
with open(os.path.join(CERTS_OBSERVED, mail_domain, mx_host), "w") as f:
|
||||||
f.write(output)
|
f.write(output)
|
||||||
|
|
||||||
def valid_cert(filename):
|
def valid_cert(filename):
|
||||||
@@ -90,9 +91,12 @@ def check_certs(mail_domain):
|
|||||||
Return "" if any certs for any mx domains pointed to by mail_domain
|
Return "" if any certs for any mx domains pointed to by mail_domain
|
||||||
were invalid, and a public suffix for one if they were all valid
|
were invalid, and a public suffix for one if they were all valid
|
||||||
"""
|
"""
|
||||||
|
dir = os.path.join(CERTS_OBSERVED, mail_domain)
|
||||||
|
if not os.path.exists(dir):
|
||||||
|
collect(mail_domain)
|
||||||
names = set()
|
names = set()
|
||||||
for mx_hostname in os.listdir(mail_domain):
|
for mx_hostname in os.listdir(dir):
|
||||||
filename = os.path.join(mail_domain, mx_hostname)
|
filename = os.path.join(dir, mx_hostname)
|
||||||
if not valid_cert(filename):
|
if not valid_cert(filename):
|
||||||
return ""
|
return ""
|
||||||
else:
|
else:
|
||||||
@@ -137,8 +141,8 @@ def supports_starttls(mx_host):
|
|||||||
|
|
||||||
def min_tls_version(mail_domain):
|
def min_tls_version(mail_domain):
|
||||||
protocols = []
|
protocols = []
|
||||||
for mx_hostname in os.listdir(mail_domain):
|
for mx_hostname in os.listdir(os.path.join(CERTS_OBSERVED, mail_domain)):
|
||||||
filename = os.path.join(mail_domain, mx_hostname)
|
filename = os.path.join(CERTS_OBSERVED, mail_domain, mx_hostname)
|
||||||
contents = open(filename).read()
|
contents = open(filename).read()
|
||||||
protocol = re.findall("Protocol : (.*)", contents)[0]
|
protocol = re.findall("Protocol : (.*)", contents)[0]
|
||||||
protocols.append(protocol)
|
protocols.append(protocol)
|
||||||
@@ -151,7 +155,7 @@ def collect(mail_domain):
|
|||||||
subsequent analysis faster.
|
subsequent analysis faster.
|
||||||
"""
|
"""
|
||||||
print "Checking domain %s" % mail_domain
|
print "Checking domain %s" % mail_domain
|
||||||
mkdirp(mail_domain)
|
mkdirp(os.path.join(CERTS_OBSERVED, mail_domain))
|
||||||
answers = dns.resolver.query(mail_domain, 'MX')
|
answers = dns.resolver.query(mail_domain, 'MX')
|
||||||
for rdata in answers:
|
for rdata in answers:
|
||||||
mx_host = str(rdata.exchange).rstrip(".")
|
mx_host = str(rdata.exchange).rstrip(".")
|
||||||
@@ -167,10 +171,6 @@ if __name__ == '__main__':
|
|||||||
for input in sys.argv[1:]:
|
for input in sys.argv[1:]:
|
||||||
for domain in open(input).readlines():
|
for domain in open(input).readlines():
|
||||||
domain = domain.strip()
|
domain = domain.strip()
|
||||||
if not os.path.exists(domain):
|
|
||||||
collect(domain)
|
|
||||||
if len(os.listdir(domain)) == 0:
|
|
||||||
continue
|
|
||||||
suffix = check_certs(domain)
|
suffix = check_certs(domain)
|
||||||
min_version = min_tls_version(domain)
|
min_version = min_tls_version(domain)
|
||||||
if suffix != "":
|
if suffix != "":
|
||||||
|
|||||||
Reference in New Issue
Block a user