Skip to content

Instantly share code, notes, and snippets.

@svetlyak40wt
Created March 14, 2017 17:56
Show Gist options
  • Save svetlyak40wt/86bc8f7cca378dc17cc0e424e3ebd421 to your computer and use it in GitHub Desktop.
Save svetlyak40wt/86bc8f7cca378dc17cc0e424e3ebd421 to your computer and use it in GitHub Desktop.
This utility prints information about all SSL certificates in one pem file. Useful to see what is inside of certificate chain.
#!/usr/bin/env python
# coding: utf-8
from __future__ import division, absolute_import
from __future__ import print_function
import sys
import subprocess
def print_cert(cert):
filename = '/tmp/temp.cert'
with open(filename, 'w') as f:
f.write(cert)
command = ['openssl', 'x509', '-in', filename, '-subject', '-issuer', '-noout']
output = subprocess.check_output(command)
output = output.decode('utf-8')
print(output)
def main():
filename = sys.argv[1]
with open(filename) as f:
lines = []
# считываем сертификаты по одному
for line in f:
lines.append(line)
if line == '-----END CERTIFICATE-----\n':
print_cert(''.join(lines))
lines[:] = []
if __name__ == '__main__':
main()
@juev
Copy link

juev commented Mar 14, 2017

Переписать на Lisp? ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment