1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

internal/tlsconst: Add a package with TLS constants

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.
This commit is contained in:
Alberto Bertogli
2016-10-01 14:04:10 +01:00
parent e138f0dc05
commit 16d9d45e06
3 changed files with 420 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
#!/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')