1
0
tlshandshake/utils.go

54 linhas
1.7 KiB
Go
Em bruto Vista normal Histórico

2019-05-12 19:06:55 +01:00
package tlshandshake
import (
"encoding/hex"
"fmt"
"github.com/grantae/certinfo"
2019-05-23 18:59:58 +01:00
th5 "github.com/henrydcase/th5"
2019-05-12 19:06:55 +01:00
)
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)
}
2019-05-23 18:59:58 +01:00
func printTlsState(con *th5.Conn) {
2019-05-12 19:06:55 +01:00
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)
}
}