diff --git a/confluent_server/confluent/util.py b/confluent_server/confluent/util.py index 6da69603..07bd25ed 100644 --- a/confluent_server/confluent/util.py +++ b/confluent_server/confluent/util.py @@ -24,6 +24,7 @@ import netifaces import os import re import socket +import ssl import struct @@ -99,6 +100,20 @@ def monotonic_time(): return os.times()[4] +def get_certificate_from_file(certfile): + cert = open(certfile, 'rb').read() + inpemcert = False + prunedcert = '' + for line in cert.split('\n'): + if '-----BEGIN CERTIFICATE-----' in line: + inpemcert = True + if inpemcert: + prunedcert += line + if '-----END CERTIFICATE-----' in line: + break + return ssl.PEM_cert_to_DER_cert(prunedcert) + + def get_fingerprint(certificate, algo='sha512'): if algo == 'sha256': return 'sha256$' + hashlib.sha256(certificate).hexdigest()