Skip to content

Instantly share code, notes, and snippets.

@listm
Created July 26, 2017 22:34
Show Gist options
  • Save listm/f5018cfa486386785bed25de8c1723d1 to your computer and use it in GitHub Desktop.
Save listm/f5018cfa486386785bed25de8c1723d1 to your computer and use it in GitHub Desktop.
Get ciphers from openssl and convert the seperate parts into a python dictionary
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import subprocess
import os
ciphersuite_mapping = {}
raw_output = subprocess.check_output(["openssl", "ciphers", "-v"])[:-1]
raw_lines = raw_output.split(os.linesep)
for line in raw_lines:
line_parts = line.split()
kx = line_parts[2].split("=")
au = line_parts[3].split("=")
enc = line_parts[4].split("=")
mac = line_parts[5].split("=")
ciphersuite_mapping[line_parts[0]]={
'tls_version': line_parts[1],
kx[0]: kx[1],
au[0]: au[1],
enc[0]: enc[1],
mac[0]: mac[1],
}
# output is in ciphersuite_mapping
# example result: 'DHE-RSA-AES256-SHA256': {'Enc': 'AES(256)', 'tls_version': 'TLSv1.2', 'Mac': 'SHA256', 'Kx': 'DH', 'Au': 'RSA'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment