Cache call to openssl ciphers

This commit is contained in:
nemunaire 2015-02-01 22:11:42 +01:00 committed by nemunaire
parent 9cfd1e1831
commit c28b688943
1 changed files with 5 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import ssl
import subprocess
import sys
_cipher_cache = dict()
def get(subset="ALL:COMPLEMENTOFALL"):
"""Ask OpenSSL a list of ciphers
@ -14,12 +15,16 @@ def get(subset="ALL:COMPLEMENTOFALL"):
subset -- an openssl cipher list format string
"""
if subset in _cipher_cache:
return _cipher_cache[subset]
ciphers = []
with subprocess.Popen(["openssl", "ciphers", subset],
stdout=subprocess.PIPE) as raw_ciphers:
ciphers = re.findall(r"[^:]+",
raw_ciphers.stdout.read().strip().decode())
_cipher_cache[subset] = ciphers
return ciphers