tlshandshake - tool for testing and benchmarking TLS handshake
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

54 rindas
1.7 KiB

  1. package tlshandshake
  2. import (
  3. "encoding/hex"
  4. "fmt"
  5. "github.com/grantae/certinfo"
  6. th5 "github.com/henrydcase/th5"
  7. )
  8. var tf = map[bool]string{
  9. true: "TRUE",
  10. false: "FALSE",
  11. }
  12. func toHex(b []byte) string {
  13. str := make([]byte, hex.EncodedLen(len(b)))
  14. hex.Encode(str, b[:])
  15. return string(str)
  16. }
  17. func printTlsState(con *th5.Conn) {
  18. state := con.ConnectionState()
  19. fmt.Println("| TLS-Session:")
  20. fmt.Println("-----------------------------------------------------------------")
  21. fmt.Printf("\tProtocol\t\t: %s\n", TlsVersionToName[state.Version])
  22. fmt.Printf("\tCipher\t\t\t: %s\n", CipherSuiteIdToName[state.CipherSuite])
  23. fmt.Printf("\tNegotiated Group\t: %s\n", NamedGroupsToName[uint16(state.Group)])
  24. fmt.Printf("\tConnection ID\t\t: %s\n", toHex(state.ConnectionID))
  25. fmt.Printf("\tSCTs\t\t\t: %s\n", state.SignedCertificateTimestamps)
  26. fmt.Printf("\tConnection resumed\t: %s\n", tf[state.DidResume])
  27. //fmt.Printf("\tNext protocol\t\t: %s\n", state.NegotiatedProtocol)
  28. fmt.Printf("\tEMS used\t\t: %s\n", tf[con.UsedEMS()])
  29. fmt.Printf("\tStapled OCSP response\t: %s\n", toHex(state.OCSPResponse))
  30. fmt.Println("\n| Connection:")
  31. fmt.Println("-----------------------------------------------------------------")
  32. fmt.Printf("\tLocal address\t\t: %s\n", con.LocalAddr())
  33. fmt.Printf("\tRemote address\t\t: %s\n", con.RemoteAddr())
  34. fmt.Println("\n| Server Certificates:")
  35. fmt.Println("-----------------------------------------------------------------")
  36. for i, cert := range state.PeerCertificates {
  37. fmt.Printf("Depth : %d\n", i)
  38. fmt.Printf("Issuer : %s\n", cert.Issuer)
  39. res, err := certinfo.CertificateText(cert)
  40. if err != nil {
  41. panic("Error parsing received server certificate")
  42. }
  43. fmt.Println(res)
  44. }
  45. }