blob: e17d41c75bbbd672dfd8b7116c4d873d33a09037 [file] [log] [blame]
Joe Subbiani3ad58322021-07-21 16:48:54 +01001import re
Joe Subbiani83944842021-07-20 18:26:03 +01002
3def translate_gnu(m_cipher):
Joe Subbiani3ad58322021-07-21 16:48:54 +01004 # Remove "TLS-"
5 # Replace "-WITH-" with ":+"
6 # Remove "EDE"
Joe Subbiani83944842021-07-20 18:26:03 +01007 m_cipher = "+" + m_cipher[4:]
8 m_cipher = m_cipher.replace("-WITH-", ":+")
9 m_cipher = m_cipher.replace("-EDE", "")
Joe Subbiani3ad58322021-07-21 16:48:54 +010010
11 # SHA == SHA1, if the last 3 chars are SHA append 1
12 if m_cipher[-3:] == "SHA":
Joe Subbiani83944842021-07-20 18:26:03 +010013 m_cipher = m_cipher+"1"
Joe Subbiani3ad58322021-07-21 16:48:54 +010014
15 # CCM or CCM-8 should be followed by ":+AEAD"
16 if "CCM" in m_cipher:
Joe Subbiani83944842021-07-20 18:26:03 +010017 m_cipher = m_cipher+":+AEAD"
Joe Subbiani3ad58322021-07-21 16:48:54 +010018
19 # Replace the last "-" with ":+"
20 # Replace "GCM:+SHAxyz" with "GCM:+AEAD"
Joe Subbiani83944842021-07-20 18:26:03 +010021 else:
22 index=m_cipher.rindex("-")
23 m_cipher = m_cipher[:index]+":+"+m_cipher[index+1:]
Joe Subbiani3ad58322021-07-21 16:48:54 +010024 m_cipher = re.sub(r"GCM\:\+SHA\d\d\d", "GCM:+AEAD", m_cipher)
Joe Subbiani83944842021-07-20 18:26:03 +010025
26 return m_cipher
Joe Subbiani3ad58322021-07-21 16:48:54 +010027
Joe Subbiani83944842021-07-20 18:26:03 +010028def translate_ossl(m_cipher):
Joe Subbiani3ad58322021-07-21 16:48:54 +010029 # Remove "TLS-"
30 # Remove "WITH"
Joe Subbiani83944842021-07-20 18:26:03 +010031 m_cipher = m_cipher[4:]
32 m_cipher = m_cipher.replace("-WITH", "")
Joe Subbiani3ad58322021-07-21 16:48:54 +010033
34 # Remove the "-" from "ABC-xyz"
Joe Subbiani83944842021-07-20 18:26:03 +010035 m_cipher = m_cipher.replace("AES-", "AES")
36 m_cipher = m_cipher.replace("CAMELLIA-", "CAMELLIA")
37 m_cipher = m_cipher.replace("ARIA-", "ARIA")
Joe Subbiani83944842021-07-20 18:26:03 +010038
Joe Subbiani3ad58322021-07-21 16:48:54 +010039 # Remove "RSA" if it is at the beginning
Joe Subbiani83944842021-07-20 18:26:03 +010040 if m_cipher[:4] == "RSA-":
41 m_cipher = m_cipher[4:]
42
Joe Subbiani3ad58322021-07-21 16:48:54 +010043 # For all circumstances outside of PSK
44 if "PSK" not in m_cipher:
45 m_cipher = m_cipher.replace("-EDE", "")
46 m_cipher = m_cipher.replace("3DES-CBC", "DES-CBC3")
47
48 # Remove "CBC" if it is not prefixed by DES
49 if "CBC" in m_cipher:
50 index = m_cipher.rindex("CBC")
51 if m_cipher[index-4:index-1] != "DES":
52 m_cipher = m_cipher.replace("CBC-", "")
53
54 # ECDHE-RSA-ARIA does not exist in OpenSSL
Joe Subbiani83944842021-07-20 18:26:03 +010055 m_cipher = m_cipher.replace("ECDHE-RSA-ARIA", "ECDHE-ARIA")
56
Joe Subbiani3ad58322021-07-21 16:48:54 +010057 # POLY1305 should not be followed by anything
58 if "POLY1305" in m_cipher:
Joe Subbiani83944842021-07-20 18:26:03 +010059 index = m_cipher.rindex("POLY1305")
60 m_cipher=m_cipher[:index+8]
Joe Subbiani3ad58322021-07-21 16:48:54 +010061
62 # If DES is being used, Replace DHE with EDH
63 if "DES" in m_cipher and "DHE" in m_cipher and "ECDHE" not in m_cipher:
64 m_cipher = m_cipher.replace("DHE", "EDH")
Joe Subbiani83944842021-07-20 18:26:03 +010065
66 return m_cipher