Joe Subbiani | 3ad5832 | 2021-07-21 16:48:54 +0100 | [diff] [blame^] | 1 | import re |
Joe Subbiani | 8394484 | 2021-07-20 18:26:03 +0100 | [diff] [blame] | 2 | |
| 3 | def translate_gnu(m_cipher): |
Joe Subbiani | 3ad5832 | 2021-07-21 16:48:54 +0100 | [diff] [blame^] | 4 | # Remove "TLS-" |
| 5 | # Replace "-WITH-" with ":+" |
| 6 | # Remove "EDE" |
Joe Subbiani | 8394484 | 2021-07-20 18:26:03 +0100 | [diff] [blame] | 7 | m_cipher = "+" + m_cipher[4:] |
| 8 | m_cipher = m_cipher.replace("-WITH-", ":+") |
| 9 | m_cipher = m_cipher.replace("-EDE", "") |
Joe Subbiani | 3ad5832 | 2021-07-21 16:48:54 +0100 | [diff] [blame^] | 10 | |
| 11 | # SHA == SHA1, if the last 3 chars are SHA append 1 |
| 12 | if m_cipher[-3:] == "SHA": |
Joe Subbiani | 8394484 | 2021-07-20 18:26:03 +0100 | [diff] [blame] | 13 | m_cipher = m_cipher+"1" |
Joe Subbiani | 3ad5832 | 2021-07-21 16:48:54 +0100 | [diff] [blame^] | 14 | |
| 15 | # CCM or CCM-8 should be followed by ":+AEAD" |
| 16 | if "CCM" in m_cipher: |
Joe Subbiani | 8394484 | 2021-07-20 18:26:03 +0100 | [diff] [blame] | 17 | m_cipher = m_cipher+":+AEAD" |
Joe Subbiani | 3ad5832 | 2021-07-21 16:48:54 +0100 | [diff] [blame^] | 18 | |
| 19 | # Replace the last "-" with ":+" |
| 20 | # Replace "GCM:+SHAxyz" with "GCM:+AEAD" |
Joe Subbiani | 8394484 | 2021-07-20 18:26:03 +0100 | [diff] [blame] | 21 | else: |
| 22 | index=m_cipher.rindex("-") |
| 23 | m_cipher = m_cipher[:index]+":+"+m_cipher[index+1:] |
Joe Subbiani | 3ad5832 | 2021-07-21 16:48:54 +0100 | [diff] [blame^] | 24 | m_cipher = re.sub(r"GCM\:\+SHA\d\d\d", "GCM:+AEAD", m_cipher) |
Joe Subbiani | 8394484 | 2021-07-20 18:26:03 +0100 | [diff] [blame] | 25 | |
| 26 | return m_cipher |
Joe Subbiani | 3ad5832 | 2021-07-21 16:48:54 +0100 | [diff] [blame^] | 27 | |
Joe Subbiani | 8394484 | 2021-07-20 18:26:03 +0100 | [diff] [blame] | 28 | def translate_ossl(m_cipher): |
Joe Subbiani | 3ad5832 | 2021-07-21 16:48:54 +0100 | [diff] [blame^] | 29 | # Remove "TLS-" |
| 30 | # Remove "WITH" |
Joe Subbiani | 8394484 | 2021-07-20 18:26:03 +0100 | [diff] [blame] | 31 | m_cipher = m_cipher[4:] |
| 32 | m_cipher = m_cipher.replace("-WITH", "") |
Joe Subbiani | 3ad5832 | 2021-07-21 16:48:54 +0100 | [diff] [blame^] | 33 | |
| 34 | # Remove the "-" from "ABC-xyz" |
Joe Subbiani | 8394484 | 2021-07-20 18:26:03 +0100 | [diff] [blame] | 35 | m_cipher = m_cipher.replace("AES-", "AES") |
| 36 | m_cipher = m_cipher.replace("CAMELLIA-", "CAMELLIA") |
| 37 | m_cipher = m_cipher.replace("ARIA-", "ARIA") |
Joe Subbiani | 8394484 | 2021-07-20 18:26:03 +0100 | [diff] [blame] | 38 | |
Joe Subbiani | 3ad5832 | 2021-07-21 16:48:54 +0100 | [diff] [blame^] | 39 | # Remove "RSA" if it is at the beginning |
Joe Subbiani | 8394484 | 2021-07-20 18:26:03 +0100 | [diff] [blame] | 40 | if m_cipher[:4] == "RSA-": |
| 41 | m_cipher = m_cipher[4:] |
| 42 | |
Joe Subbiani | 3ad5832 | 2021-07-21 16:48:54 +0100 | [diff] [blame^] | 43 | # 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 Subbiani | 8394484 | 2021-07-20 18:26:03 +0100 | [diff] [blame] | 55 | m_cipher = m_cipher.replace("ECDHE-RSA-ARIA", "ECDHE-ARIA") |
| 56 | |
Joe Subbiani | 3ad5832 | 2021-07-21 16:48:54 +0100 | [diff] [blame^] | 57 | # POLY1305 should not be followed by anything |
| 58 | if "POLY1305" in m_cipher: |
Joe Subbiani | 8394484 | 2021-07-20 18:26:03 +0100 | [diff] [blame] | 59 | index = m_cipher.rindex("POLY1305") |
| 60 | m_cipher=m_cipher[:index+8] |
Joe Subbiani | 3ad5832 | 2021-07-21 16:48:54 +0100 | [diff] [blame^] | 61 | |
| 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 Subbiani | 8394484 | 2021-07-20 18:26:03 +0100 | [diff] [blame] | 65 | |
| 66 | return m_cipher |