54 行
1.7 KiB
Go
54 行
1.7 KiB
Go
package tlshandshake
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"fmt"
|
|
"github.com/grantae/certinfo"
|
|
th5 "github.com/henrydcase/th5"
|
|
)
|
|
|
|
var tf = map[bool]string{
|
|
true: "TRUE",
|
|
false: "FALSE",
|
|
}
|
|
|
|
func toHex(b []byte) string {
|
|
str := make([]byte, hex.EncodedLen(len(b)))
|
|
hex.Encode(str, b[:])
|
|
return string(str)
|
|
}
|
|
|
|
func printTlsState(con *th5.Conn) {
|
|
state := con.ConnectionState()
|
|
fmt.Println("| TLS-Session:")
|
|
fmt.Println("-----------------------------------------------------------------")
|
|
fmt.Printf("\tProtocol\t\t: %s\n", TlsVersionToName[state.Version])
|
|
fmt.Printf("\tCipher\t\t\t: %s\n", CipherSuiteIdToName[state.CipherSuite])
|
|
fmt.Printf("\tNegotiated Group\t: %s\n", NamedGroupsToName[uint16(state.Group)])
|
|
fmt.Printf("\tConnection ID\t\t: %s\n", toHex(state.ConnectionID))
|
|
fmt.Printf("\tSCTs\t\t\t: %s\n", state.SignedCertificateTimestamps)
|
|
fmt.Printf("\tConnection resumed\t: %s\n", tf[state.DidResume])
|
|
//fmt.Printf("\tNext protocol\t\t: %s\n", state.NegotiatedProtocol)
|
|
fmt.Printf("\tEMS used\t\t: %s\n", tf[con.UsedEMS()])
|
|
fmt.Printf("\tStapled OCSP response\t: %s\n", toHex(state.OCSPResponse))
|
|
|
|
fmt.Println("\n| Connection:")
|
|
fmt.Println("-----------------------------------------------------------------")
|
|
fmt.Printf("\tLocal address\t\t: %s\n", con.LocalAddr())
|
|
fmt.Printf("\tRemote address\t\t: %s\n", con.RemoteAddr())
|
|
|
|
fmt.Println("\n| Server Certificates:")
|
|
fmt.Println("-----------------------------------------------------------------")
|
|
for i, cert := range state.PeerCertificates {
|
|
fmt.Printf("Depth : %d\n", i)
|
|
fmt.Printf("Issuer : %s\n", cert.Issuer)
|
|
res, err := certinfo.CertificateText(cert)
|
|
if err != nil {
|
|
panic("Error parsing received server certificate")
|
|
}
|
|
fmt.Println(res)
|
|
|
|
}
|
|
|
|
}
|