github.com/pion/dtls/v2@v2.2.12/internal/ciphersuite/ciphersuite.go (about)

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