tlshandshake - tool for testing and benchmarking TLS handshake
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

81 lignes
3.1 KiB

  1. package tlshandshake
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/henrydcase/th5"
  6. )
  7. type Client struct {
  8. TLS th5.Config
  9. Addr string
  10. }
  11. var TlsVersionToName = map[uint16]string{
  12. th5.VersionTLS10: "1.0",
  13. th5.VersionTLS11: "1.1",
  14. th5.VersionTLS12: "1.2",
  15. th5.VersionTLS13: "1.3",
  16. }
  17. var CipherSuiteIdToName = map[uint16]string{
  18. th5.TLS_AES_128_GCM_SHA256: "TLS_AES_128_GCM_SHA256",
  19. th5.TLS_AES_256_GCM_SHA384: "TLS_AES_256_GCM_SHA384",
  20. th5.TLS_CHACHA20_POLY1305_SHA256: "TLS_CHACHA20_POLY1305_SHA256",
  21. th5.TLS_RSA_WITH_RC4_128_SHA: "TLS_RSA_WITH_RC4_128_SHA",
  22. th5.TLS_RSA_WITH_3DES_EDE_CBC_SHA: "TLS_RSA_WITH_3DES_EDE_CBC_SHA",
  23. th5.TLS_RSA_WITH_AES_128_CBC_SHA: "TLS_RSA_WITH_AES_128_CBC_SHA",
  24. th5.TLS_RSA_WITH_AES_256_CBC_SHA: "TLS_RSA_WITH_AES_256_CBC_SHA",
  25. th5.TLS_RSA_WITH_AES_128_CBC_SHA256: "TLS_RSA_WITH_AES_128_CBC_SHA256",
  26. th5.TLS_RSA_WITH_AES_128_GCM_SHA256: "TLS_RSA_WITH_AES_128_GCM_SHA256",
  27. th5.TLS_RSA_WITH_AES_256_GCM_SHA384: "TLS_RSA_WITH_AES_256_GCM_SHA384",
  28. th5.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA: "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA",
  29. th5.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA: "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
  30. th5.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA: "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
  31. th5.TLS_ECDHE_RSA_WITH_RC4_128_SHA: "TLS_ECDHE_RSA_WITH_RC4_128_SHA",
  32. th5.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA: "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
  33. th5.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA: "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
  34. th5.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA: "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
  35. th5.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256: "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
  36. th5.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256: "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
  37. th5.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
  38. th5.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
  39. th5.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384: "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
  40. th5.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384: "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
  41. th5.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305: "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305",
  42. th5.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305: "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305",
  43. }
  44. var NamedGroupsToName = map[uint16]string{
  45. uint16(th5.HybridSIDHp503Curve25519): "X25519-SIDHp503",
  46. uint16(th5.HybridSIKEp503Curve25519): "X25519-SIKEp503",
  47. uint16(th5.X25519): "X25519",
  48. uint16(th5.CurveP256): "P-256",
  49. uint16(th5.CurveP384): "P-384",
  50. uint16(th5.CurveP521): "P-521",
  51. }
  52. func NewClient() *Client {
  53. var c Client
  54. c.TLS.InsecureSkipVerify = true
  55. return &c
  56. }
  57. func (c *Client) Run() {
  58. con, err := th5.Dial("tcp", c.Addr, &c.TLS)
  59. if err != nil {
  60. fmt.Printf("handshake failed: %v\n\n", err)
  61. os.Exit(1)
  62. }
  63. defer con.Close()
  64. printTlsState(con)
  65. }
  66. func (c *Client) Clone() *Client {
  67. var clone Client
  68. clone.TLS = *c.TLS.Clone()
  69. clone.Addr = c.Addr
  70. return &clone
  71. }