|
@@ -42,14 +42,28 @@ def get_cert(addr, port, starttls):
|
|
|
|
|
|
return cert
|
|
|
|
|
|
-def compute_fingerprints(cert):
|
|
|
+
|
|
|
+def capitalize_and_colons(in_hash):
|
|
|
+ in_hash = in_hash.upper()
|
|
|
+ new_hash = in_hash[0:2]
|
|
|
+ for i in range(2, len(in_hash), 2):
|
|
|
+ new_hash += ":" + in_hash[i:i+2]
|
|
|
+ return new_hash
|
|
|
+
|
|
|
+
|
|
|
+def compute_fingerprints(cert, with_colons):
|
|
|
thumb_md5 = hashlib.md5(cert).hexdigest()
|
|
|
thumb_sha1 = hashlib.sha1(cert).hexdigest()
|
|
|
thumb_sha256 = hashlib.sha256(cert).hexdigest()
|
|
|
logger.info("MD5: " + thumb_md5)
|
|
|
+ if with_colons:
|
|
|
+ logger.info(" " + capitalize_and_colons(thumb_md5))
|
|
|
logger.info("SHA1: " + thumb_sha1)
|
|
|
+ if with_colons:
|
|
|
+ logger.info(" " + capitalize_and_colons(thumb_sha1))
|
|
|
logger.info("SHA256: " + thumb_sha256)
|
|
|
-
|
|
|
+ if with_colons:
|
|
|
+ logger.info(" " + capitalize_and_colons(thumb_sha256))
|
|
|
|
|
|
|
|
|
@click.command()
|
|
@@ -58,7 +72,8 @@ def compute_fingerprints(cert):
|
|
|
@click.option('--starttls', is_flag=True, flag_value=True, help="Whether to use starttls on connection.")
|
|
|
@click.option('--debug/--nodebug', is_flag=True, flag_value=False, help="Debug output.")
|
|
|
@click.option('-o', '--output', help="Path to save the certificate to.")
|
|
|
-def doit(address, port, starttls, debug, output):
|
|
|
+@click.option('--colons/--nocolons', is_flag=True, flag_value=False, help="Whether to output also hashed with colons")
|
|
|
+def doit(address, port, starttls, debug, output, colons):
|
|
|
if debug:
|
|
|
logger.setLevel(logging.DEBUG)
|
|
|
cert = get_cert(address, port, starttls)
|
|
@@ -67,7 +82,7 @@ def doit(address, port, starttls, debug, output):
|
|
|
logger.debug("Opening file %s" % output)
|
|
|
f.write(ssl.DER_cert_to_PEM_cert(cert))
|
|
|
logger.info("The certificate has been saved to %s" % output)
|
|
|
- compute_fingerprints(cert)
|
|
|
+ compute_fingerprints(cert, colons)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
doit()
|