Commit 8fbe1cee authored by Adrian Georgescu's avatar Adrian Georgescu

Added utility to list TLS CAs

parent c6155483
#!/usr/bin/env python3
from gnutls.crypto import X509Certificate
from gnutls.errors import GNUTLSError
def trusted_cas(content):
trusted_cas = []
crt = ''
start = False
end = False
content = content or ''
content = content.decode() if isinstance(content, bytes) else content
for line in content.split("\n"):
if "BEGIN CERT" in line:
start = True
crt = line + "\n"
elif "END CERT" in line:
crt = crt + line + "\n"
end = True
start = False
try:
trusted_cas.append(X509Certificate(crt))
except (GNUTLSError, ValueError) as e:
continue
elif start:
crt = crt + line + "\n"
return trusted_cas
if __name__ == '__main__':
path = "./ca.crt"
content = open(path, 'r').read()
cas = trusted_cas(content)
i = 1
for certificate in cas:
print('%3d %s' % (i, certificate.subject))
i = i + 1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment