2021-07-21 16:48:54 +01:00
|
|
|
import re
|
2021-07-20 18:26:03 +01:00
|
|
|
|
|
|
|
def translate_gnu(m_cipher):
|
2021-07-21 16:48:54 +01:00
|
|
|
# Remove "TLS-"
|
|
|
|
# Replace "-WITH-" with ":+"
|
|
|
|
# Remove "EDE"
|
2021-07-20 18:26:03 +01:00
|
|
|
m_cipher = "+" + m_cipher[4:]
|
|
|
|
m_cipher = m_cipher.replace("-WITH-", ":+")
|
|
|
|
m_cipher = m_cipher.replace("-EDE", "")
|
2021-07-21 16:48:54 +01:00
|
|
|
|
|
|
|
# SHA == SHA1, if the last 3 chars are SHA append 1
|
|
|
|
if m_cipher[-3:] == "SHA":
|
2021-07-20 18:26:03 +01:00
|
|
|
m_cipher = m_cipher+"1"
|
2021-07-21 16:48:54 +01:00
|
|
|
|
|
|
|
# CCM or CCM-8 should be followed by ":+AEAD"
|
|
|
|
if "CCM" in m_cipher:
|
2021-07-20 18:26:03 +01:00
|
|
|
m_cipher = m_cipher+":+AEAD"
|
2021-07-21 16:48:54 +01:00
|
|
|
|
|
|
|
# Replace the last "-" with ":+"
|
|
|
|
# Replace "GCM:+SHAxyz" with "GCM:+AEAD"
|
2021-07-20 18:26:03 +01:00
|
|
|
else:
|
|
|
|
index=m_cipher.rindex("-")
|
|
|
|
m_cipher = m_cipher[:index]+":+"+m_cipher[index+1:]
|
2021-07-21 16:48:54 +01:00
|
|
|
m_cipher = re.sub(r"GCM\:\+SHA\d\d\d", "GCM:+AEAD", m_cipher)
|
2021-07-20 18:26:03 +01:00
|
|
|
|
|
|
|
return m_cipher
|
2021-07-21 16:48:54 +01:00
|
|
|
|
2021-07-20 18:26:03 +01:00
|
|
|
def translate_ossl(m_cipher):
|
2021-07-21 16:48:54 +01:00
|
|
|
# Remove "TLS-"
|
|
|
|
# Remove "WITH"
|
2021-07-20 18:26:03 +01:00
|
|
|
m_cipher = m_cipher[4:]
|
|
|
|
m_cipher = m_cipher.replace("-WITH", "")
|
2021-07-21 16:48:54 +01:00
|
|
|
|
|
|
|
# Remove the "-" from "ABC-xyz"
|
2021-07-20 18:26:03 +01:00
|
|
|
m_cipher = m_cipher.replace("AES-", "AES")
|
|
|
|
m_cipher = m_cipher.replace("CAMELLIA-", "CAMELLIA")
|
|
|
|
m_cipher = m_cipher.replace("ARIA-", "ARIA")
|
|
|
|
|
2021-07-21 16:48:54 +01:00
|
|
|
# Remove "RSA" if it is at the beginning
|
2021-07-20 18:26:03 +01:00
|
|
|
if m_cipher[:4] == "RSA-":
|
|
|
|
m_cipher = m_cipher[4:]
|
|
|
|
|
2021-07-21 16:48:54 +01:00
|
|
|
# For all circumstances outside of PSK
|
|
|
|
if "PSK" not in m_cipher:
|
|
|
|
m_cipher = m_cipher.replace("-EDE", "")
|
|
|
|
m_cipher = m_cipher.replace("3DES-CBC", "DES-CBC3")
|
|
|
|
|
|
|
|
# Remove "CBC" if it is not prefixed by DES
|
|
|
|
if "CBC" in m_cipher:
|
|
|
|
index = m_cipher.rindex("CBC")
|
|
|
|
if m_cipher[index-4:index-1] != "DES":
|
|
|
|
m_cipher = m_cipher.replace("CBC-", "")
|
|
|
|
|
|
|
|
# ECDHE-RSA-ARIA does not exist in OpenSSL
|
2021-07-20 18:26:03 +01:00
|
|
|
m_cipher = m_cipher.replace("ECDHE-RSA-ARIA", "ECDHE-ARIA")
|
|
|
|
|
2021-07-21 16:48:54 +01:00
|
|
|
# POLY1305 should not be followed by anything
|
|
|
|
if "POLY1305" in m_cipher:
|
2021-07-20 18:26:03 +01:00
|
|
|
index = m_cipher.rindex("POLY1305")
|
|
|
|
m_cipher=m_cipher[:index+8]
|
|
|
|
|
2021-07-21 16:48:54 +01:00
|
|
|
# If DES is being used, Replace DHE with EDH
|
|
|
|
if "DES" in m_cipher and "DHE" in m_cipher and "ECDHE" not in m_cipher:
|
|
|
|
m_cipher = m_cipher.replace("DHE", "EDH")
|
2021-07-20 18:26:03 +01:00
|
|
|
|
2021-07-21 16:48:54 +01:00
|
|
|
return m_cipher
|