blob: b9a2d537470c62b1bc885e6a7b7fc7618bbe6c23 [file] [log] [blame]
Joe Subbiani3ad58322021-07-21 16:48:54 +01001import re
Joe Subbiani97cd5992021-07-22 16:08:29 +01002import sys
Joe Subbiani83944842021-07-20 18:26:03 +01003
4def translate_gnu(m_cipher):
Joe Subbiani3ad58322021-07-21 16:48:54 +01005 # Remove "TLS-"
6 # Replace "-WITH-" with ":+"
7 # Remove "EDE"
Joe Subbiani83944842021-07-20 18:26:03 +01008 m_cipher = "+" + m_cipher[4:]
9 m_cipher = m_cipher.replace("-WITH-", ":+")
10 m_cipher = m_cipher.replace("-EDE", "")
Joe Subbiani3ad58322021-07-21 16:48:54 +010011
12 # SHA == SHA1, if the last 3 chars are SHA append 1
13 if m_cipher[-3:] == "SHA":
Joe Subbiani83944842021-07-20 18:26:03 +010014 m_cipher = m_cipher+"1"
Joe Subbiani3ad58322021-07-21 16:48:54 +010015
16 # CCM or CCM-8 should be followed by ":+AEAD"
17 if "CCM" in m_cipher:
Joe Subbiani83944842021-07-20 18:26:03 +010018 m_cipher = m_cipher+":+AEAD"
Joe Subbiani3ad58322021-07-21 16:48:54 +010019
20 # Replace the last "-" with ":+"
21 # Replace "GCM:+SHAxyz" with "GCM:+AEAD"
Joe Subbiani83944842021-07-20 18:26:03 +010022 else:
23 index=m_cipher.rindex("-")
24 m_cipher = m_cipher[:index]+":+"+m_cipher[index+1:]
Joe Subbiani3ad58322021-07-21 16:48:54 +010025 m_cipher = re.sub(r"GCM\:\+SHA\d\d\d", "GCM:+AEAD", m_cipher)
Joe Subbiani83944842021-07-20 18:26:03 +010026
27 return m_cipher
Joe Subbiani3ad58322021-07-21 16:48:54 +010028
Joe Subbiani83944842021-07-20 18:26:03 +010029def translate_ossl(m_cipher):
Joe Subbiani3ad58322021-07-21 16:48:54 +010030 # Remove "TLS-"
31 # Remove "WITH"
Joe Subbiani83944842021-07-20 18:26:03 +010032 m_cipher = m_cipher[4:]
33 m_cipher = m_cipher.replace("-WITH", "")
Joe Subbiani3ad58322021-07-21 16:48:54 +010034
35 # Remove the "-" from "ABC-xyz"
Joe Subbiani83944842021-07-20 18:26:03 +010036 m_cipher = m_cipher.replace("AES-", "AES")
37 m_cipher = m_cipher.replace("CAMELLIA-", "CAMELLIA")
38 m_cipher = m_cipher.replace("ARIA-", "ARIA")
Joe Subbiani83944842021-07-20 18:26:03 +010039
Joe Subbiani3ad58322021-07-21 16:48:54 +010040 # Remove "RSA" if it is at the beginning
Joe Subbiani83944842021-07-20 18:26:03 +010041 if m_cipher[:4] == "RSA-":
42 m_cipher = m_cipher[4:]
43
Joe Subbiani3ad58322021-07-21 16:48:54 +010044 # For all circumstances outside of PSK
45 if "PSK" not in m_cipher:
46 m_cipher = m_cipher.replace("-EDE", "")
47 m_cipher = m_cipher.replace("3DES-CBC", "DES-CBC3")
48
49 # Remove "CBC" if it is not prefixed by DES
50 if "CBC" in m_cipher:
51 index = m_cipher.rindex("CBC")
52 if m_cipher[index-4:index-1] != "DES":
53 m_cipher = m_cipher.replace("CBC-", "")
54
55 # ECDHE-RSA-ARIA does not exist in OpenSSL
Joe Subbiani83944842021-07-20 18:26:03 +010056 m_cipher = m_cipher.replace("ECDHE-RSA-ARIA", "ECDHE-ARIA")
57
Joe Subbiani3ad58322021-07-21 16:48:54 +010058 # POLY1305 should not be followed by anything
59 if "POLY1305" in m_cipher:
Joe Subbiani83944842021-07-20 18:26:03 +010060 index = m_cipher.rindex("POLY1305")
61 m_cipher=m_cipher[:index+8]
Joe Subbiani3ad58322021-07-21 16:48:54 +010062
63 # If DES is being used, Replace DHE with EDH
64 if "DES" in m_cipher and "DHE" in m_cipher and "ECDHE" not in m_cipher:
65 m_cipher = m_cipher.replace("DHE", "EDH")
Joe Subbiani83944842021-07-20 18:26:03 +010066
67 return m_cipher
Joe Subbiani97cd5992021-07-22 16:08:29 +010068
69def format_g(m_ciphers):
70 #ciphers = (re.findall(r"TLS-.+\s*\\", m_ciphers))
71 m_ciphers = m_ciphers.split()
72 g_ciphers = []
73 for i in m_ciphers:
74 g_ciphers.append(translate_gnu(i))
75 return " ".join(g_ciphers)
76
77def format_o(m_ciphers):
78 m_ciphers = m_ciphers.split()
79 o_ciphers = []
80 for i in m_ciphers:
81 o_ciphers.append(translate_ossl(i))
82 return " ".join(o_ciphers)
83
84def main():
85 # print command line arguments
86 if len(sys.argv) <= 2:
87 exit(1)
88 if sys.argv[1] == "g":
89 print(format_g(sys.argv[2]))
90 exit(0)
91 elif sys.argv[1] == "o":
92 print(format_o(sys.argv[2]))
93 exit(0)
94 else:
95 exit(1)
96
97if __name__ == "__main__":
98 main()