ciphersuite.go 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Package ciphersuite provides TLS Ciphers as registered with the IANA https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-4
  2. package ciphersuite
  3. import (
  4. "errors"
  5. "fmt"
  6. "github.com/pion/dtls/v2/internal/ciphersuite/types"
  7. "github.com/pion/dtls/v2/pkg/protocol"
  8. )
  9. var errCipherSuiteNotInit = &protocol.TemporaryError{Err: errors.New("CipherSuite has not been initialized")} //nolint:goerr113
  10. // ID is an ID for our supported CipherSuites
  11. type ID uint16
  12. func (i ID) String() string {
  13. switch i {
  14. case TLS_ECDHE_ECDSA_WITH_AES_128_CCM:
  15. return "TLS_ECDHE_ECDSA_WITH_AES_128_CCM"
  16. case TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8:
  17. return "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8"
  18. case TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256:
  19. return "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"
  20. case TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:
  21. return "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
  22. case TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA:
  23. return "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA"
  24. case TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA:
  25. return "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"
  26. case TLS_PSK_WITH_AES_128_CCM:
  27. return "TLS_PSK_WITH_AES_128_CCM"
  28. case TLS_PSK_WITH_AES_128_CCM_8:
  29. return "TLS_PSK_WITH_AES_128_CCM_8"
  30. case TLS_PSK_WITH_AES_256_CCM_8:
  31. return "TLS_PSK_WITH_AES_256_CCM_8"
  32. case TLS_PSK_WITH_AES_128_GCM_SHA256:
  33. return "TLS_PSK_WITH_AES_128_GCM_SHA256"
  34. case TLS_PSK_WITH_AES_128_CBC_SHA256:
  35. return "TLS_PSK_WITH_AES_128_CBC_SHA256"
  36. case TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384:
  37. return "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"
  38. case TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384:
  39. return "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
  40. case TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256:
  41. return "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256"
  42. default:
  43. return fmt.Sprintf("unknown(%v)", uint16(i))
  44. }
  45. }
  46. // Supported Cipher Suites
  47. const (
  48. // AES-128-CCM
  49. TLS_ECDHE_ECDSA_WITH_AES_128_CCM ID = 0xc0ac //nolint:revive,stylecheck
  50. TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 ID = 0xc0ae //nolint:revive,stylecheck
  51. // AES-128-GCM-SHA256
  52. TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 ID = 0xc02b //nolint:revive,stylecheck
  53. TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ID = 0xc02f //nolint:revive,stylecheck
  54. TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 ID = 0xc02c //nolint:revive,stylecheck
  55. TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 ID = 0xc030 //nolint:revive,stylecheck
  56. // AES-256-CBC-SHA
  57. TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA ID = 0xc00a //nolint:revive,stylecheck
  58. TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA ID = 0xc014 //nolint:revive,stylecheck
  59. TLS_PSK_WITH_AES_128_CCM ID = 0xc0a4 //nolint:revive,stylecheck
  60. TLS_PSK_WITH_AES_128_CCM_8 ID = 0xc0a8 //nolint:revive,stylecheck
  61. TLS_PSK_WITH_AES_256_CCM_8 ID = 0xc0a9 //nolint:revive,stylecheck
  62. TLS_PSK_WITH_AES_128_GCM_SHA256 ID = 0x00a8 //nolint:revive,stylecheck
  63. TLS_PSK_WITH_AES_128_CBC_SHA256 ID = 0x00ae //nolint:revive,stylecheck
  64. TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 ID = 0xC037 //nolint:revive,stylecheck
  65. )
  66. // AuthenticationType controls what authentication method is using during the handshake
  67. type AuthenticationType = types.AuthenticationType
  68. // AuthenticationType Enums
  69. const (
  70. AuthenticationTypeCertificate AuthenticationType = types.AuthenticationTypeCertificate
  71. AuthenticationTypePreSharedKey AuthenticationType = types.AuthenticationTypePreSharedKey
  72. AuthenticationTypeAnonymous AuthenticationType = types.AuthenticationTypeAnonymous
  73. )
  74. // KeyExchangeAlgorithm controls what exchange algorithm was chosen.
  75. type KeyExchangeAlgorithm = types.KeyExchangeAlgorithm
  76. // KeyExchangeAlgorithm Bitmask
  77. const (
  78. KeyExchangeAlgorithmNone KeyExchangeAlgorithm = types.KeyExchangeAlgorithmNone
  79. KeyExchangeAlgorithmPsk KeyExchangeAlgorithm = types.KeyExchangeAlgorithmPsk
  80. KeyExchangeAlgorithmEcdhe KeyExchangeAlgorithm = types.KeyExchangeAlgorithmEcdhe
  81. )