2024-05-15 23:15:00 +00:00
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
2022-03-10 09:44:48 +00:00
// Package ciphersuite provides TLS Ciphers as registered with the IANA https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-4
package ciphersuite
import (
"errors"
"fmt"
2024-05-15 23:15:00 +00:00
"github.com/pion/dtls/v2/internal/ciphersuite/types"
2022-03-10 09:44:48 +00:00
"github.com/pion/dtls/v2/pkg/protocol"
)
var errCipherSuiteNotInit = & protocol . TemporaryError { Err : errors . New ( "CipherSuite has not been initialized" ) } //nolint:goerr113
// ID is an ID for our supported CipherSuites
type ID uint16
func ( i ID ) String ( ) string {
switch i {
case TLS_ECDHE_ECDSA_WITH_AES_128_CCM :
return "TLS_ECDHE_ECDSA_WITH_AES_128_CCM"
case TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 :
return "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8"
case TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 :
return "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"
case TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 :
return "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
case TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA :
return "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA"
case TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA :
return "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"
case TLS_PSK_WITH_AES_128_CCM :
return "TLS_PSK_WITH_AES_128_CCM"
case TLS_PSK_WITH_AES_128_CCM_8 :
return "TLS_PSK_WITH_AES_128_CCM_8"
2024-05-15 23:15:00 +00:00
case TLS_PSK_WITH_AES_256_CCM_8 :
return "TLS_PSK_WITH_AES_256_CCM_8"
2022-03-10 09:44:48 +00:00
case TLS_PSK_WITH_AES_128_GCM_SHA256 :
return "TLS_PSK_WITH_AES_128_GCM_SHA256"
case TLS_PSK_WITH_AES_128_CBC_SHA256 :
return "TLS_PSK_WITH_AES_128_CBC_SHA256"
case TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 :
return "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"
case TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 :
return "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
2024-05-15 23:15:00 +00:00
case TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 :
return "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256"
2022-03-10 09:44:48 +00:00
default :
return fmt . Sprintf ( "unknown(%v)" , uint16 ( i ) )
}
}
// Supported Cipher Suites
const (
// AES-128-CCM
2024-05-15 23:15:00 +00:00
TLS_ECDHE_ECDSA_WITH_AES_128_CCM ID = 0xc0ac //nolint:revive,stylecheck
TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 ID = 0xc0ae //nolint:revive,stylecheck
2022-03-10 09:44:48 +00:00
// AES-128-GCM-SHA256
2024-05-15 23:15:00 +00:00
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 ID = 0xc02b //nolint:revive,stylecheck
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ID = 0xc02f //nolint:revive,stylecheck
2022-03-10 09:44:48 +00:00
2024-05-15 23:15:00 +00:00
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 ID = 0xc02c //nolint:revive,stylecheck
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 ID = 0xc030 //nolint:revive,stylecheck
2022-03-10 09:44:48 +00:00
// AES-256-CBC-SHA
2024-05-15 23:15:00 +00:00
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA ID = 0xc00a //nolint:revive,stylecheck
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA ID = 0xc014 //nolint:revive,stylecheck
TLS_PSK_WITH_AES_128_CCM ID = 0xc0a4 //nolint:revive,stylecheck
TLS_PSK_WITH_AES_128_CCM_8 ID = 0xc0a8 //nolint:revive,stylecheck
TLS_PSK_WITH_AES_256_CCM_8 ID = 0xc0a9 //nolint:revive,stylecheck
TLS_PSK_WITH_AES_128_GCM_SHA256 ID = 0x00a8 //nolint:revive,stylecheck
TLS_PSK_WITH_AES_128_CBC_SHA256 ID = 0x00ae //nolint:revive,stylecheck
2022-03-10 09:44:48 +00:00
2024-05-15 23:15:00 +00:00
TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 ID = 0xC037 //nolint:revive,stylecheck
2022-03-10 09:44:48 +00:00
)
// AuthenticationType controls what authentication method is using during the handshake
2024-05-15 23:15:00 +00:00
type AuthenticationType = types . AuthenticationType
2022-03-10 09:44:48 +00:00
// AuthenticationType Enums
const (
2024-05-15 23:15:00 +00:00
AuthenticationTypeCertificate AuthenticationType = types . AuthenticationTypeCertificate
AuthenticationTypePreSharedKey AuthenticationType = types . AuthenticationTypePreSharedKey
AuthenticationTypeAnonymous AuthenticationType = types . AuthenticationTypeAnonymous
)
// KeyExchangeAlgorithm controls what exchange algorithm was chosen.
type KeyExchangeAlgorithm = types . KeyExchangeAlgorithm
// KeyExchangeAlgorithm Bitmask
const (
KeyExchangeAlgorithmNone KeyExchangeAlgorithm = types . KeyExchangeAlgorithmNone
KeyExchangeAlgorithmPsk KeyExchangeAlgorithm = types . KeyExchangeAlgorithmPsk
KeyExchangeAlgorithmEcdhe KeyExchangeAlgorithm = types . KeyExchangeAlgorithmEcdhe
2022-03-10 09:44:48 +00:00
)