2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-27 03:49:57 +00:00

Add utility function to get certificate from file

This can be used to get our own certificate, for use in the
multimanager membership establishment.
This commit is contained in:
Jarrod Johnson 2018-03-15 18:59:49 -04:00
parent 6cba560f6a
commit 7ebe9da24b

View File

@ -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()