mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-18 14:47:03 +00:00
There are a couple of places where it's handy to print TLS constants in human-readable form. To do so, we need functions that take TLS constants (usually in uint16 form) and give us friendly strings. Go's crypto/tls package does not provide us with this, so this patch introduces a new module with that purpose.
55 lines
1.2 KiB
Python
Executable File
55 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
#
|
|
# This hacky script generates a go file with a map of version -> name for the
|
|
# entries in the TLS Cipher Suite Registry.
|
|
|
|
import csv
|
|
import urllib.request
|
|
import sys
|
|
|
|
# Where to get the TLS parameters from.
|
|
# See http://www.iana.org/assignments/tls-parameters/tls-parameters.xml.
|
|
URL = "https://www.iana.org/assignments/tls-parameters/tls-parameters-4.csv"
|
|
|
|
|
|
def getCiphers():
|
|
req = urllib.request.urlopen(URL)
|
|
data = req.read().decode('utf-8')
|
|
|
|
ciphers = []
|
|
reader = csv.DictReader(data.splitlines())
|
|
for row in reader:
|
|
desc = row["Description"]
|
|
rawval = row["Value"]
|
|
|
|
# Just plain TLS values for now, to keep it simple.
|
|
if "-" in rawval or not desc.startswith("TLS"):
|
|
continue
|
|
|
|
rv1, rv2 = rawval.split(",")
|
|
rv1, rv2 = int(rv1, 16), int(rv2, 16)
|
|
|
|
val = "0x%02x%02x" % (rv1, rv2)
|
|
ciphers.append((val, desc))
|
|
|
|
return ciphers
|
|
|
|
|
|
ciphers = getCiphers()
|
|
|
|
out = open(sys.argv[1], 'w')
|
|
out.write("""\
|
|
package tlsconst
|
|
|
|
// AUTOGENERATED - DO NOT EDIT
|
|
//
|
|
// This file was autogenerated by generate-ciphers.py.
|
|
|
|
var cipherSuiteName = map[uint16]string{
|
|
""")
|
|
|
|
for ver, desc in ciphers:
|
|
out.write('\t%s: "%s",\n' % (ver, desc))
|
|
|
|
out.write('}\n')
|