From fd5e50a2cb37181f37f037ebcf55717f359152fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Thu, 18 Jun 2020 08:57:50 +0200 Subject: [PATCH] Add DescribeTLS() --- pkg/cryptoutil/tls.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 pkg/cryptoutil/tls.go diff --git a/pkg/cryptoutil/tls.go b/pkg/cryptoutil/tls.go new file mode 100644 index 00000000..7dbd21f7 --- /dev/null +++ b/pkg/cryptoutil/tls.go @@ -0,0 +1,33 @@ +package cryptoutil + +import ( + "crypto/tls" + "strings" +) + +func DescribeTLS(version, cipherSuite uint16) string { + cs := tls.CipherSuiteName(cipherSuite) + cs = cs[:strings.LastIndexByte(cs, '_')] + cs = cipherSuiteReplacer.Replace(cs) + + return TLSVersionName(version) + " and " + cs +} + +func TLSVersionName(version uint16) string { + return tlsVersionNames[version] +} + +var ( + tlsVersionNames = map[uint16]string{ + tls.VersionTLS10: "TLS 1.0", + tls.VersionTLS11: "TLS 1.1", + tls.VersionTLS12: "TLS 1.2", + tls.VersionTLS13: "TLS 1.3", + } + + cipherSuiteReplacer = strings.NewReplacer( + "_WITH_", " with ", + "TLS_", "", + "_", "-", + ) +)