ciphersuite.go 3.8 KB

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