1package moxio
2
3import (
4 "crypto/tls"
5 "fmt"
6)
7
8// TLSInfo returns human-readable strings about the TLS connection, for use in
9// logging.
10func TLSInfo(conn *tls.Conn) (version, ciphersuite string) {
11 st := conn.ConnectionState()
12
13 versions := map[uint16]string{
14 tls.VersionTLS10: "TLS1.0",
15 tls.VersionTLS11: "TLS1.1",
16 tls.VersionTLS12: "TLS1.2",
17 tls.VersionTLS13: "TLS1.3",
18 }
19
20 v, ok := versions[st.Version]
21 if ok {
22 version = v
23 } else {
24 version = fmt.Sprintf("TLS %x", st.Version)
25 }
26
27 ciphersuite = tls.CipherSuiteName(st.CipherSuite)
28 return
29}
30