mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 15:43:32 +01:00
Try to make get_mozilla_ciphers output the right macros in the right order
This commit is contained in:
parent
092b9aca8c
commit
c5dca8f208
@ -54,11 +54,35 @@ fileA.close()
|
|||||||
|
|
||||||
# Parse the lines and put them into a dict
|
# Parse the lines and put them into a dict
|
||||||
ciphers = {}
|
ciphers = {}
|
||||||
|
cipher_pref = {}
|
||||||
for line in cipherLines:
|
for line in cipherLines:
|
||||||
m = re.search(r'^{\s*\"([^\"]+)\",\s*(\S*)\s*}', line)
|
m = re.search(r'^{\s*\"([^\"]+)\",\s*(\S*)\s*}', line)
|
||||||
if m:
|
if m:
|
||||||
key,value = m.groups()
|
key,value = m.groups()
|
||||||
ciphers[key] = value
|
ciphers[key] = value
|
||||||
|
cipher_pref[value] = key
|
||||||
|
|
||||||
|
####
|
||||||
|
# Now find the correct order for the ciphers
|
||||||
|
fileC = open(ff('security/nss/lib/ssl/sslenum.c'), 'r')
|
||||||
|
firefox_ciphers = []
|
||||||
|
inEnum=False
|
||||||
|
for line in fileC:
|
||||||
|
if not inEnum:
|
||||||
|
if "SSL_ImplementedCiphers[] =" in line:
|
||||||
|
inEnum = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
if line.startswith("};"):
|
||||||
|
break
|
||||||
|
|
||||||
|
m = re.match(r'^\s*([A-Z_0-9]+)\s*', line)
|
||||||
|
if m:
|
||||||
|
if m.group(1) == "0":
|
||||||
|
break
|
||||||
|
firefox_ciphers.append(m.group(1))
|
||||||
|
|
||||||
|
fileC.close()
|
||||||
|
|
||||||
#####
|
#####
|
||||||
# Read the JS file to understand what ciphers are enabled. The format is
|
# Read the JS file to understand what ciphers are enabled. The format is
|
||||||
@ -111,28 +135,59 @@ for x in used_ciphers:
|
|||||||
####
|
####
|
||||||
# Now read through all the openssl include files, and try to find the openssl
|
# Now read through all the openssl include files, and try to find the openssl
|
||||||
# macro names for those files.
|
# macro names for those files.
|
||||||
cipher_hex = {}
|
openssl_macro_by_hex = {}
|
||||||
|
all_openssl_macros = {}
|
||||||
for fl in oSSLinclude:
|
for fl in oSSLinclude:
|
||||||
fp = open(ossl(fl), 'r')
|
fp = open(ossl(fl), 'r')
|
||||||
for line in fp.readlines():
|
for line in fp.readlines():
|
||||||
m = re.match('#define\s+(\S+)\s+(\S+)', line)
|
m = re.match('#define\s+(\S+)\s+(\S+)', line)
|
||||||
if m:
|
if m:
|
||||||
value,key = m.groups()
|
value,key = m.groups()
|
||||||
if key.startswith('0x'):
|
if key.startswith('0x') and "_CK_" in value:
|
||||||
key = key.replace('0x0300','0x').lower()
|
key = key.replace('0x0300','0x').lower()
|
||||||
#print "%s %s" % (key, value)
|
#print "%s %s" % (key, value)
|
||||||
cipher_hex[key] = value
|
openssl_macro_by_hex[key] = value
|
||||||
|
all_openssl_macros[value]=key
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
# Now generate the output.
|
# Now generate the output.
|
||||||
for x in cipher_codes:
|
print """\
|
||||||
try:
|
/* This is an include file used to define the list of ciphers clients should
|
||||||
res = """#ifdef %s
|
* advertise. Before including it, you should define the CIPHER and XCIPHER
|
||||||
CIPHER(%s, %s)
|
* macros.
|
||||||
#else
|
*
|
||||||
XCIPHER(%s, %s)
|
* This file was automatically generated by get_mozilla_ciphers.py.
|
||||||
#endif""" % (cipher_hex[x], x, cipher_hex[x], x, cipher_hex[x])
|
*/"""
|
||||||
print res
|
# Go in order by the order in CipherPrefs
|
||||||
except KeyError:
|
for firefox_macro in firefox_ciphers:
|
||||||
print "Not found %s" % x
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
js_cipher_name = cipher_pref[firefox_macro]
|
||||||
|
except KeyError:
|
||||||
|
# This one has no javascript preference.
|
||||||
|
continue
|
||||||
|
|
||||||
|
# The cipher needs to be enabled in security-prefs.js
|
||||||
|
if enabled_ciphers.get(js_cipher_name, 'false') != 'true':
|
||||||
|
continue
|
||||||
|
|
||||||
|
hexval = sslProtoD[firefox_macro]
|
||||||
|
|
||||||
|
try:
|
||||||
|
openssl_macro = openssl_macro_by_hex[hexval.lower()]
|
||||||
|
openssl_macro = openssl_macro.replace("_CK_", "_TXT_")
|
||||||
|
if openssl_macro not in all_openssl_macros:
|
||||||
|
raise KeyError()
|
||||||
|
format = {'hex':hexval, 'macro':openssl_macro, 'note':""}
|
||||||
|
except KeyError:
|
||||||
|
# openssl doesn't have a macro for this.
|
||||||
|
format = {'hex':hexval, 'macro':firefox_macro,
|
||||||
|
'note':"/* No openssl macro found for "+hexval+" */\n"}
|
||||||
|
|
||||||
|
res = """\
|
||||||
|
%(note)s#ifdef %(macro)s
|
||||||
|
CIPHER(%(hex)s, %(macro)s)
|
||||||
|
#else
|
||||||
|
XCIPHER(%(hex)s, %(macro)s)
|
||||||
|
#endif""" % format
|
||||||
|
print res
|
||||||
|
Loading…
Reference in New Issue
Block a user