Documentation
¶
Overview ¶
Package tls partially implements TLS 1.2, as specified in RFC 5246, and TLS 1.3, as specified in RFC 8446.
Index ¶
- Constants
- func CipherSuiteName(id uint16) string
- func IsGREASE(v uint16) bool
- func Listen(network, laddr string, config *Config) (net.Listener, error)
- func NewListener(inner net.Listener, config *Config) net.Listener
- func VersionName(version uint16) string
- type AEAD
- type ALPNExtension
- func (*ALPNExtension) Clone() Extension
- func (*ALPNExtension) ExtensionId() uint16
- func (*ALPNExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*ALPNExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*ALPNExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*ALPNExtension) NegotiatedVersion(vers uint16)
- func (*ALPNExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type ALPSExtension
- func (*ALPSExtension) Clone() Extension
- func (*ALPSExtension) ExtensionId() uint16
- func (*ALPSExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*ALPSExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*ALPSExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*ALPSExtension) NegotiatedVersion(vers uint16)
- func (*ALPSExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type AlertError
- type CertCompressionAlgorithm
- type Certificate
- type CertificateRequestInfo
- type CertificateVerificationError
- type CipherSuite
- type ClientAuthType
- type ClientHelloInfo
- type ClientSessionCache
- type ClientSessionState
- type CompressedCertificateExtension
- func (*CompressedCertificateExtension) Clone() Extension
- func (*CompressedCertificateExtension) ExtensionId() uint16
- func (*CompressedCertificateExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*CompressedCertificateExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*CompressedCertificateExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*CompressedCertificateExtension) NegotiatedVersion(vers uint16)
- func (*CompressedCertificateExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type Config
- func (c *Config) BuildNameToCertificate()deprecated
- func (c *Config) Clone() *Config
- func (c *Config) DecryptTicket(identity []byte, cs ConnectionState) (*SessionState, error)
- func (c *Config) EncryptTicket(cs ConnectionState, ss *SessionState) ([]byte, error)
- func (c *Config) SetSessionTicketKeys(keys [][32]byte)
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) CloseWrite() error
- func (c *Conn) ConfirmHandshake() error
- func (c *Conn) ConnectionState() ConnectionState
- func (c *Conn) GREASE() uint16
- func (c *Conn) Handshake() error
- func (c *Conn) HandshakeContext(ctx context.Context) error
- func (c *Conn) KernelRX() bool
- func (c *Conn) KernelTX() bool
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) NetConn() net.Conn
- func (c *Conn) OCSPResponse() []byte
- func (c *Conn) Read(b []byte) (int, error)
- func (c *Conn) ReadFrom(r io.Reader) (int64, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) VerifyHostname(host string) error
- func (c *Conn) Write(b []byte) (int, error)
- func (c *Conn) WriteTo(w io.Writer) (int64, error)
- type ConnectionState
- type CookieExtension
- func (*CookieExtension) Clone() Extension
- func (*CookieExtension) ExtensionId() uint16
- func (*CookieExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*CookieExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*CookieExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*CookieExtension) NegotiatedVersion(vers uint16)
- func (*CookieExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type CurveID
- type Dialer
- type ECHCipher
- type ECHDummyConfig
- type ECHOuterExtension
- func (*ECHOuterExtension) Clone() Extension
- func (*ECHOuterExtension) ExtensionId() uint16
- func (*ECHOuterExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*ECHOuterExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*ECHOuterExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*ECHOuterExtension) NegotiatedVersion(vers uint16)
- func (*ECHOuterExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type ECHRejectionError
- type EarlyDataExtension
- func (*EarlyDataExtension) Clone() Extension
- func (*EarlyDataExtension) ExtensionId() uint16
- func (*EarlyDataExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*EarlyDataExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*EarlyDataExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*EarlyDataExtension) NegotiatedVersion(vers uint16)
- func (*EarlyDataExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type EncryptedClientHelloExtension
- func (*EncryptedClientHelloExtension) Clone() Extension
- func (*EncryptedClientHelloExtension) ExtensionId() uint16
- func (*EncryptedClientHelloExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*EncryptedClientHelloExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*EncryptedClientHelloExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*EncryptedClientHelloExtension) NegotiatedVersion(vers uint16)
- func (*EncryptedClientHelloExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type EncryptedClientHelloKey
- type ExtendedMasterSecretExtension
- func (*ExtendedMasterSecretExtension) Clone() Extension
- func (*ExtendedMasterSecretExtension) ExtensionId() uint16
- func (*ExtendedMasterSecretExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*ExtendedMasterSecretExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*ExtendedMasterSecretExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*ExtendedMasterSecretExtension) NegotiatedVersion(vers uint16)
- func (*ExtendedMasterSecretExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type Extension
- type GREASEExtension
- func (extension *GREASEExtension) Clone() Extension
- func (extension *GREASEExtension) ExtensionId() uint16
- func (extension *GREASEExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (extension *GREASEExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*GREASEExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*GREASEExtension) NegotiatedVersion(vers uint16)
- func (extension *GREASEExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type KDF
- type KEM
- type KeyShareExtension
- func (*KeyShareExtension) Clone() Extension
- func (*KeyShareExtension) ExtensionId() uint16
- func (*KeyShareExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*KeyShareExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*KeyShareExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*KeyShareExtension) NegotiatedVersion(vers uint16)
- func (*KeyShareExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type PSKModesExtension
- func (*PSKModesExtension) Clone() Extension
- func (*PSKModesExtension) ExtensionId() uint16
- func (*PSKModesExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*PSKModesExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*PSKModesExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*PSKModesExtension) NegotiatedVersion(vers uint16)
- func (*PSKModesExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type PaddingExtension
- func (extension *PaddingExtension) Clone() Extension
- func (*PaddingExtension) ExtensionId() uint16
- func (extension *PaddingExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (extension *PaddingExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*PaddingExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*PaddingExtension) NegotiatedVersion(vers uint16)
- func (extension *PaddingExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type PreSharedKeyExtension
- func (*PreSharedKeyExtension) Clone() Extension
- func (*PreSharedKeyExtension) ExtensionId() uint16
- func (*PreSharedKeyExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*PreSharedKeyExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*PreSharedKeyExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*PreSharedKeyExtension) NegotiatedVersion(vers uint16)
- func (*PreSharedKeyExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type QUICConfig
- type QUICConn
- func (q *QUICConn) Close() error
- func (q *QUICConn) ConnectionState() ConnectionState
- func (q *QUICConn) HandleData(level QUICEncryptionLevel, data []byte) error
- func (q *QUICConn) NextEvent() QUICEvent
- func (q *QUICConn) SendSessionTicket(opts QUICSessionTicketOptions) error
- func (q *QUICConn) SetTransportParameters(params []byte)
- func (q *QUICConn) Start(ctx context.Context) error
- func (q *QUICConn) StoreSession(session *SessionState) error
- type QUICEncryptionLevel
- type QUICEvent
- type QUICEventKind
- type QUICSessionTicketOptions
- type QUICTransportParametersExtension
- func (*QUICTransportParametersExtension) Clone() Extension
- func (*QUICTransportParametersExtension) ExtensionId() uint16
- func (*QUICTransportParametersExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*QUICTransportParametersExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*QUICTransportParametersExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*QUICTransportParametersExtension) NegotiatedVersion(vers uint16)
- func (*QUICTransportParametersExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type RecordHeaderError
- type RenegotiationInfoExtension
- func (*RenegotiationInfoExtension) Clone() Extension
- func (*RenegotiationInfoExtension) ExtensionId() uint16
- func (*RenegotiationInfoExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*RenegotiationInfoExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*RenegotiationInfoExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*RenegotiationInfoExtension) NegotiatedVersion(vers uint16)
- func (*RenegotiationInfoExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type RenegotiationSupport
- type SCTExtension
- func (*SCTExtension) Clone() Extension
- func (*SCTExtension) ExtensionId() uint16
- func (*SCTExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*SCTExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*SCTExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*SCTExtension) NegotiatedVersion(vers uint16)
- func (*SCTExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type ServerNameIndicationExtension
- func (*ServerNameIndicationExtension) Clone() Extension
- func (*ServerNameIndicationExtension) ExtensionId() uint16
- func (*ServerNameIndicationExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*ServerNameIndicationExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*ServerNameIndicationExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*ServerNameIndicationExtension) NegotiatedVersion(vers uint16)
- func (*ServerNameIndicationExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type SessionState
- type SessionTicketExtension
- func (*SessionTicketExtension) Clone() Extension
- func (*SessionTicketExtension) ExtensionId() uint16
- func (*SessionTicketExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*SessionTicketExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*SessionTicketExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*SessionTicketExtension) NegotiatedVersion(vers uint16)
- func (*SessionTicketExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type SignatureAlgorithmsCertExtension
- func (*SignatureAlgorithmsCertExtension) Clone() Extension
- func (*SignatureAlgorithmsCertExtension) ExtensionId() uint16
- func (*SignatureAlgorithmsCertExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*SignatureAlgorithmsCertExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*SignatureAlgorithmsCertExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*SignatureAlgorithmsCertExtension) NegotiatedVersion(vers uint16)
- func (*SignatureAlgorithmsCertExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type SignatureAlgorithmsExtension
- func (*SignatureAlgorithmsExtension) Clone() Extension
- func (*SignatureAlgorithmsExtension) ExtensionId() uint16
- func (*SignatureAlgorithmsExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*SignatureAlgorithmsExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*SignatureAlgorithmsExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*SignatureAlgorithmsExtension) NegotiatedVersion(vers uint16)
- func (*SignatureAlgorithmsExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type SignatureScheme
- type StatusRequestExtension
- func (*StatusRequestExtension) Clone() Extension
- func (*StatusRequestExtension) ExtensionId() uint16
- func (*StatusRequestExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*StatusRequestExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*StatusRequestExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*StatusRequestExtension) NegotiatedVersion(vers uint16)
- func (*StatusRequestExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type SupportedGroupsExtension
- func (*SupportedGroupsExtension) Clone() Extension
- func (*SupportedGroupsExtension) ExtensionId() uint16
- func (*SupportedGroupsExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*SupportedGroupsExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*SupportedGroupsExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*SupportedGroupsExtension) NegotiatedVersion(vers uint16)
- func (*SupportedGroupsExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type SupportedPointsExtension
- func (*SupportedPointsExtension) Clone() Extension
- func (*SupportedPointsExtension) ExtensionId() uint16
- func (*SupportedPointsExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*SupportedPointsExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*SupportedPointsExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*SupportedPointsExtension) NegotiatedVersion(vers uint16)
- func (*SupportedPointsExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type SupportedVersionsExtension
- func (*SupportedVersionsExtension) Clone() Extension
- func (*SupportedVersionsExtension) ExtensionId() uint16
- func (*SupportedVersionsExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (*SupportedVersionsExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*SupportedVersionsExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*SupportedVersionsExtension) NegotiatedVersion(vers uint16)
- func (*SupportedVersionsExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- type UnimplementedExtension
- func (extension *UnimplementedExtension) Clone() Extension
- func (extension *UnimplementedExtension) ExtensionId() uint16
- func (extension *UnimplementedExtension) Len(messageType uint8, encryptedClientHello bool) int
- func (extension *UnimplementedExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
- func (*UnimplementedExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
- func (*UnimplementedExtension) NegotiatedVersion(vers uint16)
- func (extension *UnimplementedExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
- Bugs
Examples ¶
Constants ¶
const ( // TLS 1.0 - 1.2 cipher suites. TLS_RSA_WITH_RC4_128_SHA uint16 = 0x0005 TLS_RSA_WITH_3DES_EDE_CBC_SHA uint16 = 0x000a TLS_RSA_WITH_AES_128_CBC_SHA uint16 = 0x002f TLS_RSA_WITH_AES_256_CBC_SHA uint16 = 0x0035 TLS_RSA_WITH_AES_128_CBC_SHA256 uint16 = 0x003c TLS_RSA_WITH_ARIA_128_CBC_SHA256 uint16 = 0xc03c TLS_RSA_WITH_ARIA_256_CBC_SHA384 uint16 = 0xc03d TLS_RSA_WITH_AES_128_GCM_SHA256 uint16 = 0x009c TLS_RSA_WITH_AES_256_GCM_SHA384 uint16 = 0x009d TLS_RSA_WITH_AES_128_CCM_SHA256 uint16 = 0xc09c TLS_RSA_WITH_AES_256_CCM_SHA256 uint16 = 0xc09d TLS_RSA_WITH_AES_128_CCM_8_SHA256 uint16 = 0xc0a0 TLS_RSA_WITH_AES_256_CCM_8_SHA256 uint16 = 0xc0a1 TLS_RSA_WITH_ARIA_128_GCM_SHA256 uint16 = 0xc050 TLS_RSA_WITH_ARIA_256_GCM_SHA384 uint16 = 0xc051 TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 uint16 = 0xc07a TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 uint16 = 0xc07b TLS_ECDHE_ECDSA_WITH_RC4_128_SHA uint16 = 0xc007 TLS_ECDHE_RSA_WITH_RC4_128_SHA uint16 = 0xc011 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA uint16 = 0xc009 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA uint16 = 0xc013 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA uint16 = 0xc00a TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 uint16 = 0xc024 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA uint16 = 0xc014 TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA uint16 = 0xc008 TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA uint16 = 0xc012 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 uint16 = 0xc023 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 uint16 = 0xc027 TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256 uint16 = 0xc048 TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256 uint16 = 0xc04c TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384 uint16 = 0xc049 TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384 uint16 = 0xc04d TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 uint16 = 0xc072 TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 uint16 = 0xc076 TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 uint16 = 0xc073 TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 uint16 = 0xc077 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 uint16 = 0xc02b TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 uint16 = 0xc02f TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 uint16 = 0xc02c TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 uint16 = 0xc030 TLS_ECDHE_ECDSA_WITH_AES_128_CCM_SHA256 uint16 = 0xc0ac TLS_ECDHE_ECDSA_WITH_AES_256_CCM_SHA256 uint16 = 0xc0ad TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8_SHA256 uint16 = 0xc0ae TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8_SHA256 uint16 = 0xc0af TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 uint16 = 0xcca9 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 uint16 = 0xcca8 TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256 uint16 = 0xc05c TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256 uint16 = 0xc060 TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384 uint16 = 0xc05d TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384 uint16 = 0xc061 TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 uint16 = 0xc086 TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 uint16 = 0xc08a TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 uint16 = 0xc08b TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 uint16 = 0xc087 // TLS 1.3 cipher suites. TLS_AES_128_GCM_SHA256 uint16 = 0x1301 TLS_AES_256_GCM_SHA384 uint16 = 0x1302 TLS_CHACHA20_POLY1305_SHA256 uint16 = 0x1303 TLS_AES_128_CCM_SHA256 uint16 = 0x1304 TLS_AES_128_CCM_8_SHA256 uint16 = 0x1305 // TLS_FALLBACK_SCSV isn't a standard cipher suite but an indicator // that the client is doing version fallback. See RFC 7507. TLS_FALLBACK_SCSV uint16 = 0x5600 // Legacy names for the corresponding cipher suites with the correct _SHA256 // suffix, retained for backward compatibility. TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305 = TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 = TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 )
A list of cipher suite IDs that are, or have been, implemented by this package.
See https://www.iana.org/assignments/tls-parameters/tls-parameters.xml
const ( TLS_CIPHER_AES_GCM_128 kernelCryptoCipherType = 51 TLS_CIPHER_AES_GCM_128_IV_SIZE kernelCryptoCipherType = 8 TLS_CIPHER_AES_GCM_128_KEY_SIZE kernelCryptoCipherType = 16 TLS_CIPHER_AES_GCM_128_SALT_SIZE kernelCryptoCipherType = 4 TLS_CIPHER_AES_GCM_128_TAG_SIZE kernelCryptoCipherType = 16 TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE kernelCryptoCipherType = 8 TLS_CIPHER_AES_GCM_256 kernelCryptoCipherType = 52 TLS_CIPHER_AES_GCM_256_IV_SIZE kernelCryptoCipherType = 8 TLS_CIPHER_AES_GCM_256_KEY_SIZE kernelCryptoCipherType = 32 TLS_CIPHER_AES_GCM_256_SALT_SIZE kernelCryptoCipherType = 4 TLS_CIPHER_AES_GCM_256_TAG_SIZE kernelCryptoCipherType = 16 TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE kernelCryptoCipherType = 8 TLS_CIPHER_AES_CCM_128 kernelCryptoCipherType = 53 TLS_CIPHER_AES_CCM_128_IV_SIZE kernelCryptoCipherType = 8 TLS_CIPHER_AES_CCM_128_KEY_SIZE kernelCryptoCipherType = 16 TLS_CIPHER_AES_CCM_128_SALT_SIZE kernelCryptoCipherType = 4 TLS_CIPHER_AES_CCM_128_TAG_SIZE kernelCryptoCipherType = 16 TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE kernelCryptoCipherType = 8 TLS_CIPHER_CHACHA20_POLY1305 kernelCryptoCipherType = 54 TLS_CIPHER_CHACHA20_POLY1305_IV_SIZE kernelCryptoCipherType = 12 TLS_CIPHER_CHACHA20_POLY1305_KEY_SIZE kernelCryptoCipherType = 32 TLS_CIPHER_CHACHA20_POLY1305_SALT_SIZE kernelCryptoCipherType = 0 TLS_CIPHER_CHACHA20_POLY1305_TAG_SIZE kernelCryptoCipherType = 16 TLS_CIPHER_CHACHA20_POLY1305_REC_SEQ_SIZE kernelCryptoCipherType = 8 TLS_CIPHER_ARIA_GCM_128 kernelCryptoCipherType = 57 TLS_CIPHER_ARIA_GCM_128_IV_SIZE kernelCryptoCipherType = 8 TLS_CIPHER_ARIA_GCM_128_KEY_SIZE kernelCryptoCipherType = 16 TLS_CIPHER_ARIA_GCM_128_SALT_SIZE kernelCryptoCipherType = 4 TLS_CIPHER_ARIA_GCM_128_TAG_SIZE kernelCryptoCipherType = 16 TLS_CIPHER_ARIA_GCM_128_REC_SEQ_SIZE kernelCryptoCipherType = 8 TLS_CIPHER_ARIA_GCM_256 kernelCryptoCipherType = 58 TLS_CIPHER_ARIA_GCM_256_IV_SIZE kernelCryptoCipherType = 8 TLS_CIPHER_ARIA_GCM_256_KEY_SIZE kernelCryptoCipherType = 32 TLS_CIPHER_ARIA_GCM_256_SALT_SIZE kernelCryptoCipherType = 4 TLS_CIPHER_ARIA_GCM_256_TAG_SIZE kernelCryptoCipherType = 16 TLS_CIPHER_ARIA_GCM_256_REC_SEQ_SIZE kernelCryptoCipherType = 8 )
const ( VersionTLS10 = 0x0301 VersionTLS11 = 0x0302 VersionTLS12 = 0x0303 VersionTLS13 = 0x0304 // Deprecated: SSLv3 is cryptographically broken, and is no longer // supported by this package. See golang.org/issue/32716. VersionSSL30 = 0x0300 )
const ( TLS_TX = 1 TLS_RX = 2 TLS_TX_ZEROCOPY_RO = 3 // TX zerocopy (only sendfile now) TLS_RX_EXPECT_NO_PAD = 4 // Attempt opportunistic zero-copy, TLS 1.3 only TLS_SET_RECORD_TYPE = 1 TLS_GET_RECORD_TYPE = 2 )
const ( QUICEncryptionLevelInitial = QUICEncryptionLevel(iota) QUICEncryptionLevelEarly QUICEncryptionLevelHandshake QUICEncryptionLevelApplication )
const GREASE_PLACEHOLDER = 0x0a0a
based on spec's GreaseStyle, GREASE_PLACEHOLDER may be replaced by another GREASE value https://tools.ietf.org/html/draft-ietf-tls-grease-01
Variables ¶
This section is empty.
Functions ¶
func CipherSuiteName ¶
CipherSuiteName returns the standard name for the passed cipher suite ID (e.g. "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"), or a fallback representation of the ID value if the cipher suite is not implemented by this package.
func Listen ¶
Listen creates a TLS listener accepting connections on the given network address using net.Listen. The configuration config must be non-nil and must include at least one certificate or else set GetCertificate.
func NewListener ¶
NewListener creates a Listener which accepts connections from an inner Listener and wraps each connection with Server. The configuration config must be non-nil and must include at least one certificate or else set GetCertificate.
func VersionName ¶
VersionName returns the name for the provided TLS version number (e.g. "TLS 1.3"), or a fallback representation of the value if the version is not implemented by this package.
Types ¶
type AEAD ¶
type AEAD uint16
const ( // AEAD_AES128GCM is AES-128 block cipher in Galois Counter Mode (GCM). AEAD_AES128GCM AEAD = 0x01 // AEAD_AES256GCM is AES-256 block cipher in Galois Counter Mode (GCM). AEAD_AES256GCM AEAD = 0x02 // AEAD_ChaCha20Poly1305 is ChaCha20 stream cipher and Poly1305 MAC. AEAD_ChaCha20Poly1305 AEAD = 0x03 )
type ALPNExtension ¶
type ALPNExtension struct {
// contains filtered or unexported fields
}
func (*ALPNExtension) Clone ¶
func (*ALPNExtension) Clone() Extension
func (*ALPNExtension) ExtensionId ¶
func (*ALPNExtension) ExtensionId() uint16
func (*ALPNExtension) Marshal ¶
func (*ALPNExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*ALPNExtension) NegotiatedVersion ¶
func (*ALPNExtension) NegotiatedVersion(vers uint16)
type ALPSExtension ¶
type ALPSExtension struct {
// contains filtered or unexported fields
}
func (*ALPSExtension) Clone ¶
func (*ALPSExtension) Clone() Extension
func (*ALPSExtension) ExtensionId ¶
func (*ALPSExtension) ExtensionId() uint16
func (*ALPSExtension) Marshal ¶
func (*ALPSExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*ALPSExtension) NegotiatedVersion ¶
func (*ALPSExtension) NegotiatedVersion(vers uint16)
type AlertError ¶
type AlertError uint8
An AlertError is a TLS alert.
When using a QUIC transport, QUICConn methods will return an error which wraps AlertError rather than sending a TLS alert.
func (AlertError) Error ¶
func (e AlertError) Error() string
type CertCompressionAlgorithm ¶
type CertCompressionAlgorithm uint16
TLS certificate compression types.
const ( Zlib CertCompressionAlgorithm = 0x0001 Brotli CertCompressionAlgorithm = 0x0002 Zstd CertCompressionAlgorithm = 0x0003 )
type Certificate ¶
type Certificate struct { Certificate [][]byte // PrivateKey contains the private key corresponding to the public key in // Leaf. This must implement crypto.Signer with an RSA, ECDSA or Ed25519 PublicKey. // For a server up to TLS 1.2, it can also implement crypto.Decrypter with // an RSA PublicKey. PrivateKey crypto.PrivateKey // SupportedSignatureAlgorithms is an optional list restricting what // signature algorithms the PrivateKey can be used for. SupportedSignatureAlgorithms []SignatureScheme // OCSPStaple contains an optional OCSP response which will be served // to clients that request it. OCSPStaple []byte // SignedCertificateTimestamps contains an optional list of Signed // Certificate Timestamps which will be served to clients that request it. SignedCertificateTimestamps [][]byte // Leaf is the parsed form of the leaf certificate, which may be initialized // using x509.ParseCertificate to reduce per-handshake processing. If nil, // the leaf certificate will be parsed as needed. Leaf *x509.Certificate }
A Certificate is a chain of one or more certificates, leaf first.
func LoadX509KeyPair ¶
func LoadX509KeyPair(certFile, keyFile string) (Certificate, error)
LoadX509KeyPair reads and parses a public/private key pair from a pair of files. The files must contain PEM encoded data. The certificate file may contain intermediate certificates following the leaf certificate to form a certificate chain. On successful return, Certificate.Leaf will be populated.
Example ¶
package main import ( "crypto/tls" "log" ) func main() { cert, err := tls.LoadX509KeyPair("testdata/example-cert.pem", "testdata/example-key.pem") if err != nil { log.Fatal(err) } cfg := &tls.Config{Certificates: []tls.Certificate{cert}} listener, err := tls.Listen("tcp", ":2000", cfg) if err != nil { log.Fatal(err) } _ = listener }
Output:
func X509KeyPair ¶
func X509KeyPair(certPEMBlock, keyPEMBlock []byte) (Certificate, error)
X509KeyPair parses a public/private key pair from a pair of PEM encoded data. On successful return, Certificate.Leaf will be populated.
Example ¶
package main import ( "crypto/tls" "log" ) func main() { certPem := []byte(`-----BEGIN CERTIFICATE----- MIIBhTCCASugAwIBAgIQIRi6zePL6mKjOipn+dNuaTAKBggqhkjOPQQDAjASMRAw DgYDVQQKEwdBY21lIENvMB4XDTE3MTAyMDE5NDMwNloXDTE4MTAyMDE5NDMwNlow EjEQMA4GA1UEChMHQWNtZSBDbzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABD0d 7VNhbWvZLWPuj/RtHFjvtJBEwOkhbN/BnnE8rnZR8+sbwnc/KhCk3FhnpHZnQz7B 5aETbbIgmuvewdjvSBSjYzBhMA4GA1UdDwEB/wQEAwICpDATBgNVHSUEDDAKBggr BgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1UdEQQiMCCCDmxvY2FsaG9zdDo1 NDUzgg4xMjcuMC4wLjE6NTQ1MzAKBggqhkjOPQQDAgNIADBFAiEA2zpJEPQyz6/l Wf86aX6PepsntZv2GYlA5UpabfT2EZICICpJ5h/iI+i341gBmLiAFQOyTDT+/wQc 6MF9+Yw1Yy0t -----END CERTIFICATE-----`) keyPem := []byte(`-----BEGIN EC PRIVATE KEY----- MHcCAQEEIIrYSSNQFaA2Hwf1duRSxKtLYX5CB04fSeQ6tF1aY/PuoAoGCCqGSM49 AwEHoUQDQgAEPR3tU2Fta9ktY+6P9G0cWO+0kETA6SFs38GecTyudlHz6xvCdz8q EKTcWGekdmdDPsHloRNtsiCa697B2O9IFA== -----END EC PRIVATE KEY-----`) cert, err := tls.X509KeyPair(certPem, keyPem) if err != nil { log.Fatal(err) } cfg := &tls.Config{Certificates: []tls.Certificate{cert}} listener, err := tls.Listen("tcp", ":2000", cfg) if err != nil { log.Fatal(err) } _ = listener }
Output:
Example (HttpServer) ¶
package main import ( "crypto/tls" "log" "net/http" "time" ) func main() { certPem := []byte(`-----BEGIN CERTIFICATE----- MIIBhTCCASugAwIBAgIQIRi6zePL6mKjOipn+dNuaTAKBggqhkjOPQQDAjASMRAw DgYDVQQKEwdBY21lIENvMB4XDTE3MTAyMDE5NDMwNloXDTE4MTAyMDE5NDMwNlow EjEQMA4GA1UEChMHQWNtZSBDbzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABD0d 7VNhbWvZLWPuj/RtHFjvtJBEwOkhbN/BnnE8rnZR8+sbwnc/KhCk3FhnpHZnQz7B 5aETbbIgmuvewdjvSBSjYzBhMA4GA1UdDwEB/wQEAwICpDATBgNVHSUEDDAKBggr BgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1UdEQQiMCCCDmxvY2FsaG9zdDo1 NDUzgg4xMjcuMC4wLjE6NTQ1MzAKBggqhkjOPQQDAgNIADBFAiEA2zpJEPQyz6/l Wf86aX6PepsntZv2GYlA5UpabfT2EZICICpJ5h/iI+i341gBmLiAFQOyTDT+/wQc 6MF9+Yw1Yy0t -----END CERTIFICATE-----`) keyPem := []byte(`-----BEGIN EC PRIVATE KEY----- MHcCAQEEIIrYSSNQFaA2Hwf1duRSxKtLYX5CB04fSeQ6tF1aY/PuoAoGCCqGSM49 AwEHoUQDQgAEPR3tU2Fta9ktY+6P9G0cWO+0kETA6SFs38GecTyudlHz6xvCdz8q EKTcWGekdmdDPsHloRNtsiCa697B2O9IFA== -----END EC PRIVATE KEY-----`) cert, err := tls.X509KeyPair(certPem, keyPem) if err != nil { log.Fatal(err) } cfg := &tls.Config{Certificates: []tls.Certificate{cert}} srv := &http.Server{ TLSConfig: cfg, ReadTimeout: time.Minute, WriteTimeout: time.Minute, } log.Fatal(srv.ListenAndServeTLS("", "")) }
Output:
type CertificateRequestInfo ¶
type CertificateRequestInfo struct { // AcceptableCAs contains zero or more, DER-encoded, X.501 // Distinguished Names. These are the names of root or intermediate CAs // that the server wishes the returned certificate to be signed by. An // empty slice indicates that the server has no preference. AcceptableCAs [][]byte // SignatureSchemes lists the signature schemes that the server is // willing to verify. SignatureSchemes []SignatureScheme // Version is the TLS version that was negotiated for this connection. Version uint16 // contains filtered or unexported fields }
CertificateRequestInfo contains information from a server's CertificateRequest message, which is used to demand a certificate and proof of control from a client.
func (*CertificateRequestInfo) Context ¶
func (c *CertificateRequestInfo) Context() context.Context
Context returns the context of the handshake that is in progress. This context is a child of the context passed to HandshakeContext, if any, and is canceled when the handshake concludes.
func (*CertificateRequestInfo) SupportsCertificate ¶
func (cri *CertificateRequestInfo) SupportsCertificate(c *Certificate) error
SupportsCertificate returns nil if the provided certificate is supported by the server that sent the CertificateRequest. Otherwise, it returns an error describing the reason for the incompatibility.
type CertificateVerificationError ¶
type CertificateVerificationError struct { // UnverifiedCertificates and its contents should not be modified. UnverifiedCertificates []*x509.Certificate Err error }
CertificateVerificationError is returned when certificate verification fails during the handshake.
func (*CertificateVerificationError) Error ¶
func (e *CertificateVerificationError) Error() string
func (*CertificateVerificationError) Unwrap ¶
func (e *CertificateVerificationError) Unwrap() error
type CipherSuite ¶
type CipherSuite struct { ID uint16 Name string // Supported versions is the list of TLS protocol versions that can // negotiate this cipher suite. SupportedVersions []uint16 // Insecure is true if the cipher suite has known security issues // due to its primitives, design, or implementation. Insecure bool }
CipherSuite is a TLS cipher suite. Note that most functions in this package accept and expose cipher suite IDs instead of this type.
func CipherSuites ¶
func CipherSuites() []*CipherSuite
CipherSuites returns a list of cipher suites currently implemented by this package, excluding those with security issues, which are returned by InsecureCipherSuites.
The list is sorted by ID. Note that the default cipher suites selected by this package might depend on logic that can't be captured by a static list, and might not match those returned by this function.
func InsecureCipherSuites ¶
func InsecureCipherSuites() []*CipherSuite
InsecureCipherSuites returns a list of cipher suites currently implemented by this package and which have security issues.
Most applications should not use the cipher suites in this list, and should only use those returned by CipherSuites.
type ClientAuthType ¶
type ClientAuthType int
ClientAuthType declares the policy the server will follow for TLS Client Authentication.
const ( // NoClientCert indicates that no client certificate should be requested // during the handshake, and if any certificates are sent they will not // be verified. NoClientCert ClientAuthType = iota // RequestClientCert indicates that a client certificate should be requested // during the handshake, but does not require that the client send any // certificates. RequestClientCert // RequireAnyClientCert indicates that a client certificate should be requested // during the handshake, and that at least one certificate is required to be // sent by the client, but that certificate is not required to be valid. RequireAnyClientCert // VerifyClientCertIfGiven indicates that a client certificate should be requested // during the handshake, but does not require that the client sends a // certificate. If the client does send a certificate it is required to be // valid. VerifyClientCertIfGiven // RequireAndVerifyClientCert indicates that a client certificate should be requested // during the handshake, and that at least one valid certificate is required // to be sent by the client. RequireAndVerifyClientCert )
func (ClientAuthType) String ¶
func (i ClientAuthType) String() string
type ClientHelloInfo ¶
type ClientHelloInfo struct { // CipherSuites lists the CipherSuites supported by the client (e.g. // TLS_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256). CipherSuites []uint16 // ServerName indicates the name of the server requested by the client // in order to support virtual hosting. ServerName is only set if the // client is using SNI (see RFC 4366, Section 3.1). ServerName string // SupportedCurves lists the key exchange mechanisms supported by the // client. It was renamed to "supported groups" in TLS 1.3, see RFC 8446, // Section 4.2.7 and [CurveID]. // // SupportedCurves may be nil in TLS 1.2 and lower if the Supported Elliptic // Curves Extension is not being used (see RFC 4492, Section 5.1.1). SupportedCurves []CurveID // SupportedPoints lists the point formats supported by the client. // SupportedPoints is set only if the Supported Point Formats Extension // is being used (see RFC 4492, Section 5.1.2). SupportedPoints []uint8 // SignatureSchemes lists the signature and hash schemes that the client // is willing to verify. SignatureSchemes is set only if the Signature // Algorithms Extension is being used (see RFC 5246, Section 7.4.1.4.1). SignatureSchemes []SignatureScheme // SupportedProtos lists the application protocols supported by the client. // SupportedProtos is set only if the Application-Layer Protocol // Negotiation Extension is being used (see RFC 7301, Section 3.1). // // Servers can select a protocol by setting Config.NextProtos in a // GetConfigForClient return value. SupportedProtos []string // SupportedVersions lists the TLS versions supported by the client. // For TLS versions less than 1.3, this is extrapolated from the max // version advertised by the client, so values other than the greatest // might be rejected if used. SupportedVersions []uint16 // Extensions lists the IDs of the extensions presented by the client // in the ClientHello. Extensions []uint16 // Extensions lists the TLS extensions send by the client. // If its nil, defaultExtension will be used. ExtensionList []Extension // Conn is the underlying net.Conn for the connection. Do not read // from, or write to, this connection; that will cause the TLS // connection to fail. Conn net.Conn // contains filtered or unexported fields }
ClientHelloInfo contains information from a ClientHello message in order to guide application logic in the GetCertificate and GetConfigForClient callbacks.
func (*ClientHelloInfo) Context ¶
func (c *ClientHelloInfo) Context() context.Context
Context returns the context of the handshake that is in progress. This context is a child of the context passed to HandshakeContext, if any, and is canceled when the handshake concludes.
func (*ClientHelloInfo) SupportsCertificate ¶
func (chi *ClientHelloInfo) SupportsCertificate(c *Certificate) error
SupportsCertificate returns nil if the provided certificate is supported by the client that sent the ClientHello. Otherwise, it returns an error describing the reason for the incompatibility.
If this ClientHelloInfo was passed to a GetConfigForClient or GetCertificate callback, this method will take into account the associated Config. Note that if GetConfigForClient returns a different Config, the change can't be accounted for by this method.
This function will call x509.ParseCertificate unless c.Leaf is set, which can incur a significant performance cost.
type ClientSessionCache ¶
type ClientSessionCache interface { // Get searches for a ClientSessionState associated with the given key. // On return, ok is true if one was found. Get(sessionKey string) (session *ClientSessionState, ok bool) // Put adds the ClientSessionState to the cache with the given key. It might // get called multiple times in a connection if a TLS 1.3 server provides // more than one session ticket. If called with a nil *ClientSessionState, // it should remove the cache entry. Put(sessionKey string, cs *ClientSessionState) }
ClientSessionCache is a cache of ClientSessionState objects that can be used by a client to resume a TLS session with a given server. ClientSessionCache implementations should expect to be called concurrently from different goroutines. Up to TLS 1.2, only ticket-based resumption is supported, not SessionID-based resumption. In TLS 1.3 they were merged into PSK modes, which are supported via this interface.
func NewLRUClientSessionCache ¶
func NewLRUClientSessionCache(capacity int) ClientSessionCache
NewLRUClientSessionCache returns a ClientSessionCache with the given capacity that uses an LRU strategy. If capacity is < 1, a default capacity is used instead.
type ClientSessionState ¶
type ClientSessionState struct {
// contains filtered or unexported fields
}
ClientSessionState contains the state needed by a client to resume a previous TLS session.
func NewResumptionState ¶
func NewResumptionState(ticket []byte, state *SessionState) (*ClientSessionState, error)
NewResumptionState returns a state value that can be returned by [ClientSessionCache.Get] to resume a previous session.
state needs to be returned by ParseSessionState, and the ticket and session state must have been returned by ClientSessionState.ResumptionState.
func (*ClientSessionState) ResumptionState ¶
func (cs *ClientSessionState) ResumptionState() (ticket []byte, state *SessionState, err error)
ResumptionState returns the session ticket sent by the server (also known as the session's identity) and the state necessary to resume this session.
It can be called by [ClientSessionCache.Put] to serialize (with SessionState.Bytes) and store the session.
type CompressedCertificateExtension ¶
type CompressedCertificateExtension struct {
// contains filtered or unexported fields
}
func (*CompressedCertificateExtension) Clone ¶
func (*CompressedCertificateExtension) Clone() Extension
func (*CompressedCertificateExtension) ExtensionId ¶
func (*CompressedCertificateExtension) ExtensionId() uint16
func (*CompressedCertificateExtension) Marshal ¶
func (*CompressedCertificateExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*CompressedCertificateExtension) NegotiatedVersion ¶
func (*CompressedCertificateExtension) NegotiatedVersion(vers uint16)
type Config ¶
type Config struct { // Rand provides the source of entropy for nonces and RSA blinding. // If Rand is nil, TLS uses the cryptographic random reader in package // crypto/rand. // The Reader must be safe for use by multiple goroutines. Rand io.Reader // Time returns the current time as the number of seconds since the epoch. // If Time is nil, TLS uses time.Now. Time func() time.Time // Certificates contains one or more certificate chains to present to the // other side of the connection. The first certificate compatible with the // peer's requirements is selected automatically. // // Server configurations must set one of Certificates, GetCertificate or // GetConfigForClient. Clients doing client-authentication may set either // Certificates or GetClientCertificate. // // Note: if there are multiple Certificates, and they don't have the // optional field Leaf set, certificate selection will incur a significant // per-handshake performance cost. Certificates []Certificate // NameToCertificate maps from a certificate name to an element of // Certificates. Note that a certificate name can be of the form // '*.example.com' and so doesn't have to be a domain name as such. // // Deprecated: NameToCertificate only allows associating a single // certificate with a given name. Leave this field nil to let the library // select the first compatible chain from Certificates. NameToCertificate map[string]*Certificate // GetCertificate returns a Certificate based on the given // ClientHelloInfo. It will only be called if the client supplies SNI // information or if Certificates is empty. // // If GetCertificate is nil or returns nil, then the certificate is // retrieved from NameToCertificate. If NameToCertificate is nil, the // best element of Certificates will be used. // // Once a Certificate is returned it should not be modified. GetCertificate func(*ClientHelloInfo) (*Certificate, error) // GetClientCertificate, if not nil, is called when a server requests a // certificate from a client. If set, the contents of Certificates will // be ignored. // // If GetClientCertificate returns an error, the handshake will be // aborted and that error will be returned. Otherwise // GetClientCertificate must return a non-nil Certificate. If // Certificate.Certificate is empty then no certificate will be sent to // the server. If this is unacceptable to the server then it may abort // the handshake. // // GetClientCertificate may be called multiple times for the same // connection if renegotiation occurs or if TLS 1.3 is in use. // // Once a Certificate is returned it should not be modified. GetClientCertificate func(*CertificateRequestInfo) (*Certificate, error) // GetConfigForClient, if not nil, is called after a ClientHello is // received from a client. It may return a non-nil Config in order to // change the Config that will be used to handle this connection. If // the returned Config is nil, the original Config will be used. The // Config returned by this callback may not be subsequently modified. // // If GetConfigForClient is nil, the Config passed to Server() will be // used for all connections. // // If SessionTicketKey was explicitly set on the returned Config, or if // SetSessionTicketKeys was called on the returned Config, those keys will // be used. Otherwise, the original Config keys will be used (and possibly // rotated if they are automatically managed). GetConfigForClient func(*ClientHelloInfo) (*Config, error) // VerifyPeerCertificate, if not nil, is called after normal // certificate verification by either a TLS client or server. It // receives the raw ASN.1 certificates provided by the peer and also // any verified chains that normal processing found. If it returns a // non-nil error, the handshake is aborted and that error results. // // If normal verification fails then the handshake will abort before // considering this callback. If normal verification is disabled (on the // client when InsecureSkipVerify is set, or on a server when ClientAuth is // RequestClientCert or RequireAnyClientCert), then this callback will be // considered but the verifiedChains argument will always be nil. When // ClientAuth is NoClientCert, this callback is not called on the server. // rawCerts may be empty on the server if ClientAuth is RequestClientCert or // VerifyClientCertIfGiven. // // This callback is not invoked on resumed connections, as certificates are // not re-verified on resumption. // // verifiedChains and its contents should not be modified. VerifyPeerCertificate func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error // VerifyConnection, if not nil, is called after normal certificate // verification and after VerifyPeerCertificate by either a TLS client // or server. If it returns a non-nil error, the handshake is aborted // and that error results. // // If normal verification fails then the handshake will abort before // considering this callback. This callback will run for all connections, // including resumptions, regardless of InsecureSkipVerify or ClientAuth // settings. VerifyConnection func(ConnectionState) error // RootCAs defines the set of root certificate authorities // that clients use when verifying server certificates. // If RootCAs is nil, TLS uses the host's root CA set. RootCAs *x509.CertPool // NextProtos is a list of supported application level protocols, in // order of preference. If both peers support ALPN, the selected // protocol will be one from this list, and the connection will fail // if there is no mutually supported protocol. If NextProtos is empty // or the peer doesn't support ALPN, the connection will succeed and // ConnectionState.NegotiatedProtocol will be empty. NextProtos []string // NextProtoSettings is a set of application settings (ALPS) to use // with each application protocol (ALPN). NextProtoSettings map[string][]byte // GetProtoSetting, if not nil, is called after a encrypted extension message // it need negotiate applocation setting // // It only works on the client. GetProtoSetting func(proto string, serverSetting []byte) ([]byte, bool) // ServerName is used to verify the hostname on the returned // certificates unless InsecureSkipVerify is given. It is also included // in the client's handshake to support virtual hosting unless it is // an IP address. ServerName string // ClientAuth determines the server's policy for // TLS Client Authentication. The default is NoClientCert. ClientAuth ClientAuthType // ClientCAs defines the set of root certificate authorities // that servers use if required to verify a client certificate // by the policy in ClientAuth. ClientCAs *x509.CertPool // InsecureSkipVerify controls whether a client verifies the server's // certificate chain and host name. If InsecureSkipVerify is true, crypto/tls // accepts any certificate presented by the server and any host name in that // certificate. In this mode, TLS is susceptible to machine-in-the-middle // attacks unless custom verification is used. This should be used only for // testing or in combination with VerifyConnection or VerifyPeerCertificate. InsecureSkipVerify bool // PreferCipherSuites control whether cipher suites would follow the hardware's preference. PreferCipherSuites bool // CipherSuites is a list of enabled TLS 1.0–1.2 cipher suites. The order of // the list is ignored. Note that TLS 1.3 ciphersuites are not configurable. // // If CipherSuites is nil, a safe default list is used. The default cipher // suites might change over time. CipherSuites []uint16 // PreferServerCipherSuites is a legacy field and has no effect. // // It used to control whether the server would follow the client's or the // server's preference. Servers now select the best mutually supported // cipher suite based on logic that takes into account inferred client // hardware, server hardware, and security. // // Deprecated: PreferServerCipherSuites is ignored. PreferServerCipherSuites bool // SessionTicketsDisabled may be set to true to disable session ticket and // PSK (resumption) support. Note that on clients, session ticket support is // also disabled if ClientSessionCache is nil. SessionTicketsDisabled bool // SessionTicketKey is used by TLS servers to provide session resumption. // See RFC 5077 and the PSK mode of RFC 8446. If zero, it will be filled // with random data before the first server handshake. // // Deprecated: if this field is left at zero, session ticket keys will be // automatically rotated every day and dropped after seven days. For // customizing the rotation schedule or synchronizing servers that are // terminating connections for the same host, use SetSessionTicketKeys. SessionTicketKey [32]byte // ClientSessionCache is a cache of ClientSessionState entries for TLS // session resumption. It is only used by clients. ClientSessionCache ClientSessionCache // UnwrapSession is called on the server to turn a ticket/identity // previously produced by [WrapSession] into a usable session. // // UnwrapSession will usually either decrypt a session state in the ticket // (for example with [Config.EncryptTicket]), or use the ticket as a handle // to recover a previously stored state. It must use [ParseSessionState] to // deserialize the session state. // // If UnwrapSession returns an error, the connection is terminated. If it // returns (nil, nil), the session is ignored. crypto/tls may still choose // not to resume the returned session. UnwrapSession func(identity []byte, cs ConnectionState) (*SessionState, error) // WrapSession is called on the server to produce a session ticket/identity. // // WrapSession must serialize the session state with [SessionState.Bytes]. // It may then encrypt the serialized state (for example with // [Config.DecryptTicket]) and use it as the ticket, or store the state and // return a handle for it. // // If WrapSession returns an error, the connection is terminated. // // Warning: the return value will be exposed on the wire and to clients in // plaintext. The application is in charge of encrypting and authenticating // it (and rotating keys) or returning high-entropy identifiers. Failing to // do so correctly can compromise current, previous, and future connections // depending on the protocol version. WrapSession func(ConnectionState, *SessionState) ([]byte, error) // MinVersion contains the minimum TLS version that is acceptable. // // By default, TLS 1.2 is currently used as the minimum. TLS 1.0 is the // minimum supported by this package. MinVersion uint16 // MaxVersion contains the maximum TLS version that is acceptable. // // By default, the maximum version supported by this package is used, // which is currently TLS 1.3. MaxVersion uint16 // SupportedVersion is a list of TLS version that is acceptable. // // By default, it will auto generate from MinVersion and MaxVersion. SupportedVersions []uint16 // CurvePreferences contains a set of supported key exchange mechanisms. // The name refers to elliptic curves for legacy reasons, see [CurveID]. // The order of the list is ignored, and key exchange mechanisms are chosen // from this list using an internal preference order. If empty, the default // will be used. CurvePreferences []CurveID // CertCompressionDisabled disables TLS certificate compressions. // When true, the certificate message will not be compressed. // // It only works on the TLS 1.3. CertCompressionDisabled bool // CertCompressionPreferences contains the compression that will be used in // a certificate message, in preference order. If empty, the default will // be used. The client will use the first preference as the type for // its compress certificate in TLS 1.3. CertCompressionPreferences []CertCompressionAlgorithm // SignatureAlgorithmsPreferences contains the signature algorithms that // will be used in an handshake, in preference order. If empty, the default // will be used. SignatureAlgorithmsPreferences []SignatureScheme // DynamicRecordSizingDisabled disables adaptive sizing of TLS records. // When true, the largest possible TLS record size is always used. When // false, the size of TLS records may be adjusted in an attempt to // improve latency. DynamicRecordSizingDisabled bool // Renegotiation controls what types of renegotiation are supported. // The default, none, is correct for the vast majority of applications. Renegotiation RenegotiationSupport // AllowEarlyData makes the 0-RTT data received from the client // immediately available to Read. 0-RTT data is subject to replay. // Use Conn.ConfirmHandshake to wait until the data is known not // to be replayed after reading it. // // See https://tools.ietf.org/html/rfc8446#section-2.3. AllowEarlyData bool // If MaxEarlyData is not zero, the client will be allowed to use // session tickets to send at most this number of bytes of 0-RTT data. // 0-RTT data is subject to replay and has memory DoS implications. // The server will later be able to refuse the 0-RTT data with // Allow0RTT, or wait for the client to prove that it's not // replayed with Conn.ConfirmHandshake. // // It only works on the server. // // See https://tools.ietf.org/html/rfc8446#section-2.3. MaxEarlyData uint32 // If MinClientHelloSize is not zero, whe client will use the padding // extension to pad the packet to the minimum size. // // It only works on the client. MinClientHelloSize uint16 // If ShuffleExtensions is true, whe client will shuffle // extensions to avoid fingerprinting. // // It only works on the client. ShuffleExtensions bool // Extensions contains the tls extensions that will be used in client hello. // If its nil, the default will be used. // Its can modify tls fingerprint. Extensions []Extension // KeyLogWriter optionally specifies a destination for TLS master secrets // in NSS key log format that can be used to allow external programs // such as Wireshark to decrypt TLS connections. // See https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format. // Use of KeyLogWriter compromises security and should only be // used for debugging. KeyLogWriter io.Writer // KernelTX and KernelRX control whether the kernel TLS module is enabled // If the kernel is not supported, it is automatically downgraded to the application implementation // // If this option is enabled, please mount the TLS module before you run application. KernelTX, KernelRX bool // EncryptedClientHelloDummyConfig are the parameters used by the client when it // offers the dummy ECH extension. EncryptedClientHelloDummyConfig *ECHDummyConfig // EncryptedClientHelloConfigList is a serialized ECHConfigList. If // provided, clients will attempt to connect to servers using Encrypted // Client Hello (ECH) using one of the provided ECHConfigs. // // Servers do not use this field. In order to configure ECH for servers, see // the EncryptedClientHelloKeys field. // // If the list contains no valid ECH configs, the handshake will fail // and return an error. // // If EncryptedClientHelloConfigList is set, MinVersion, if set, must // be VersionTLS13. // // When EncryptedClientHelloConfigList is set, the handshake will only // succeed if ECH is successfully negotiated. If the server rejects ECH, // an ECHRejectionError error will be returned, which may contain a new // ECHConfigList that the server suggests using. // // How this field is parsed may change in future Go versions, if the // encoding described in the final Encrypted Client Hello RFC changes. EncryptedClientHelloConfigList []byte // EncryptedClientHelloRejectionVerify, if not nil, is called when ECH is // rejected by the remote server, in order to verify the ECH provider // certificate in the outer ClientHello. If it returns a non-nil error, the // handshake is aborted and that error results. // // On the server side this field is not used. // // Unlike VerifyPeerCertificate and VerifyConnection, normal certificate // verification will not be performed before calling // EncryptedClientHelloRejectionVerify. // // If EncryptedClientHelloRejectionVerify is nil and ECH is rejected, the // roots in RootCAs will be used to verify the ECH providers public // certificate. VerifyPeerCertificate and VerifyConnection are not called // when ECH is rejected, even if set, and InsecureSkipVerify is ignored. EncryptedClientHelloRejectionVerify func(ConnectionState) error // EncryptedClientHelloKeys are the ECH keys to use when a client // attempts ECH. // // If EncryptedClientHelloKeys is set, MinVersion, if set, must be // VersionTLS13. // // If a client attempts ECH, but it is rejected by the server, the server // will send a list of configs to retry based on the set of // EncryptedClientHelloKeys which have the SendAsRetry field set. // // On the client side, this field is ignored. In order to configure ECH for // clients, see the EncryptedClientHelloConfigList field. EncryptedClientHelloKeys []EncryptedClientHelloKey // contains filtered or unexported fields }
A Config structure is used to configure a TLS client or server. After one has been passed to a TLS function it must not be modified. A Config may be reused; the tls package will also not modify it.
Example (KeyLogWriter) ¶
package main import ( "crypto/tls" "log" "net/http" "net/http/httptest" "os" ) // zeroSource is an io.Reader that returns an unlimited number of zero bytes. type zeroSource struct{} func (zeroSource) Read(b []byte) (n int, err error) { clear(b) return len(b), nil } func main() { // Debugging TLS applications by decrypting a network traffic capture. // WARNING: Use of KeyLogWriter compromises security and should only be // used for debugging. // Dummy test HTTP server for the example with insecure random so output is // reproducible. server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) server.TLS = &tls.Config{ Rand: zeroSource{}, // for example only; don't do this. } server.StartTLS() defer server.Close() // Typically the log would go to an open file: // w, err := os.OpenFile("tls-secrets.txt", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) w := os.Stdout client := &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{ KeyLogWriter: w, Rand: zeroSource{}, // for reproducible output; don't do this. InsecureSkipVerify: true, // test server certificate is not trusted. }, }, } resp, err := client.Get(server.URL) if err != nil { log.Fatalf("Failed to get URL: %v", err) } resp.Body.Close() // The resulting file can be used with Wireshark to decrypt the TLS // connection by setting (Pre)-Master-Secret log filename in SSL Protocol // preferences. }
Output:
Example (VerifyConnection) ¶
package main import ( "crypto/tls" "crypto/x509" ) func main() { // VerifyConnection can be used to replace and customize connection // verification. This example shows a VerifyConnection implementation that // will be approximately equivalent to what crypto/tls does normally to // verify the peer's certificate. // Client side configuration. _ = &tls.Config{ // Set InsecureSkipVerify to skip the default validation we are // replacing. This will not disable VerifyConnection. InsecureSkipVerify: true, VerifyConnection: func(cs tls.ConnectionState) error { opts := x509.VerifyOptions{ DNSName: cs.ServerName, Intermediates: x509.NewCertPool(), } for _, cert := range cs.PeerCertificates[1:] { opts.Intermediates.AddCert(cert) } _, err := cs.PeerCertificates[0].Verify(opts) return err }, } // Server side configuration. _ = &tls.Config{ // Require client certificates (or VerifyConnection will run anyway and // panic accessing cs.PeerCertificates[0]) but don't verify them with the // default verifier. This will not disable VerifyConnection. ClientAuth: tls.RequireAnyClientCert, VerifyConnection: func(cs tls.ConnectionState) error { opts := x509.VerifyOptions{ DNSName: cs.ServerName, Intermediates: x509.NewCertPool(), KeyUsages: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth}, } for _, cert := range cs.PeerCertificates[1:] { opts.Intermediates.AddCert(cert) } _, err := cs.PeerCertificates[0].Verify(opts) return err }, } // Note that when certificates are not handled by the default verifier // ConnectionState.VerifiedChains will be nil. }
Output:
func (*Config) BuildNameToCertificate
deprecated
func (c *Config) BuildNameToCertificate()
BuildNameToCertificate parses c.Certificates and builds c.NameToCertificate from the CommonName and SubjectAlternateName fields of each of the leaf certificates.
Deprecated: NameToCertificate only allows associating a single certificate with a given name. Leave that field nil to let the library select the first compatible chain from Certificates.
func (*Config) Clone ¶
Clone returns a shallow clone of c or nil if c is nil. It is safe to clone a Config that is being used concurrently by a TLS client or server.
func (*Config) DecryptTicket ¶
func (c *Config) DecryptTicket(identity []byte, cs ConnectionState) (*SessionState, error)
DecryptTicket decrypts a ticket encrypted by Config.EncryptTicket. It can be used as a [Config.UnwrapSession] implementation.
If the ticket can't be decrypted or parsed, DecryptTicket returns (nil, nil).
func (*Config) EncryptTicket ¶
func (c *Config) EncryptTicket(cs ConnectionState, ss *SessionState) ([]byte, error)
EncryptTicket encrypts a ticket with the Config's configured (or default) session ticket keys. It can be used as a [Config.WrapSession] implementation.
func (*Config) SetSessionTicketKeys ¶
SetSessionTicketKeys updates the session ticket keys for a server.
The first key will be used when creating new tickets, while all keys can be used for decrypting tickets. It is safe to call this function while the server is running in order to rotate the session ticket keys. The function will panic if keys is empty.
Calling this function will turn off automatic session ticket key rotation.
If multiple servers are terminating connections for the same host they should all have the same session ticket keys. If the session ticket keys leaks, previously recorded and future TLS connections using those keys might be compromised.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
A Conn represents a secured connection. It implements the net.Conn interface.
func Client ¶
Client returns a new TLS client side connection using conn as the underlying transport. The config cannot be nil: users must set either ServerName or InsecureSkipVerify in the config.
func Dial ¶
Dial connects to the given network address using net.Dial and then initiates a TLS handshake, returning the resulting TLS connection. Dial interprets a nil configuration as equivalent to the zero configuration; see the documentation of Config for the defaults.
Example ¶
package main import ( "crypto/tls" "crypto/x509" ) func main() { // Connecting with a custom root-certificate set. const rootPEM = ` -- GlobalSign Root R2, valid until Dec 15, 2021 -----BEGIN CERTIFICATE----- MIIDujCCAqKgAwIBAgILBAAAAAABD4Ym5g0wDQYJKoZIhvcNAQEFBQAwTDEgMB4G A1UECxMXR2xvYmFsU2lnbiBSb290IENBIC0gUjIxEzARBgNVBAoTCkdsb2JhbFNp Z24xEzARBgNVBAMTCkdsb2JhbFNpZ24wHhcNMDYxMjE1MDgwMDAwWhcNMjExMjE1 MDgwMDAwWjBMMSAwHgYDVQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMjETMBEG A1UEChMKR2xvYmFsU2lnbjETMBEGA1UEAxMKR2xvYmFsU2lnbjCCASIwDQYJKoZI hvcNAQEBBQADggEPADCCAQoCggEBAKbPJA6+Lm8omUVCxKs+IVSbC9N/hHD6ErPL v4dfxn+G07IwXNb9rfF73OX4YJYJkhD10FPe+3t+c4isUoh7SqbKSaZeqKeMWhG8 eoLrvozps6yWJQeXSpkqBy+0Hne/ig+1AnwblrjFuTosvNYSuetZfeLQBoZfXklq tTleiDTsvHgMCJiEbKjNS7SgfQx5TfC4LcshytVsW33hoCmEofnTlEnLJGKRILzd C9XZzPnqJworc5HGnRusyMvo4KD0L5CLTfuwNhv2GXqF4G3yYROIXJ/gkwpRl4pa zq+r1feqCapgvdzZX99yqWATXgAByUr6P6TqBwMhAo6CygPCm48CAwEAAaOBnDCB mTAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUm+IH V2ccHsBqBt5ZtJot39wZhi4wNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL2NybC5n bG9iYWxzaWduLm5ldC9yb290LXIyLmNybDAfBgNVHSMEGDAWgBSb4gdXZxwewGoG 3lm0mi3f3BmGLjANBgkqhkiG9w0BAQUFAAOCAQEAmYFThxxol4aR7OBKuEQLq4Gs J0/WwbgcQ3izDJr86iw8bmEbTUsp9Z8FHSbBuOmDAGJFtqkIk7mpM0sYmsL4h4hO 291xNBrBVNpGP+DTKqttVCL1OmLNIG+6KYnX3ZHu01yiPqFbQfXf5WRDLenVOavS ot+3i9DAgBkcRcAtjOj4LaR0VknFBbVPFd5uRHg5h6h+u/N5GJG79G+dwfCMNYxd AfvDbbnvRG15RjF+Cv6pgsH/76tuIMRQyV+dTZsXjAzlAcmgQWpzU/qlULRuJQ/7 TBj0/VLZjmmx6BEP3ojY+x1J96relc8geMJgEtslQIxq/H5COEBkEveegeGTLg== -----END CERTIFICATE-----` // First, create the set of root certificates. For this example we only // have one. It's also possible to omit this in order to use the // default root set of the current operating system. roots := x509.NewCertPool() ok := roots.AppendCertsFromPEM([]byte(rootPEM)) if !ok { panic("failed to parse root certificate") } conn, err := tls.Dial("tcp", "mail.google.com:443", &tls.Config{ RootCAs: roots, }) if err != nil { panic("failed to connect: " + err.Error()) } conn.Close() }
Output:
func DialWithDialer ¶
DialWithDialer connects to the given network address using dialer.Dial and then initiates a TLS handshake, returning the resulting TLS connection. Any timeout or deadline given in the dialer apply to connection and TLS handshake as a whole.
DialWithDialer interprets a nil configuration as equivalent to the zero configuration; see the documentation of Config for the defaults.
DialWithDialer uses context.Background internally; to specify the context, use Dialer.DialContext with NetDialer set to the desired dialer.
func Server ¶
Server returns a new TLS server side connection using conn as the underlying transport. The configuration config must be non-nil and must include at least one certificate or else set GetCertificate.
func (*Conn) CloseWrite ¶
CloseWrite shuts down the writing side of the connection. It should only be called once the handshake has completed and does not call CloseWrite on the underlying connection. Most callers should just use Conn.Close.
func (*Conn) ConfirmHandshake ¶
ConfirmHandshake waits for the handshake to reach a point at which the connection is certainly not replayed. That is, after receiving the Client Finished.
If ConfirmHandshake returns an error and until ConfirmHandshake returns, the 0-RTT data should not be trusted not to be replayed.
This is only meaningful in TLS 1.3 when Allow0RTT is true and the client sent valid 0-RTT data. In any other case it's equivalent to calling Handshake.
func (*Conn) ConnectionState ¶
func (c *Conn) ConnectionState() ConnectionState
ConnectionState returns basic TLS details about the connection.
func (*Conn) Handshake ¶
Handshake runs the client or server handshake protocol if it has not yet been run.
Most uses of this package need not call Handshake explicitly: the first Conn.Read or Conn.Write will call it automatically.
For control over canceling or setting a timeout on a handshake, use Conn.HandshakeContext or the Dialer's DialContext method instead.
In order to avoid denial of service attacks, the maximum RSA key size allowed in certificates sent by either the TLS server or client is limited to 8192 bits.
func (*Conn) HandshakeContext ¶
HandshakeContext runs the client or server handshake protocol if it has not yet been run.
The provided Context must be non-nil. If the context is canceled before the handshake is complete, the handshake is interrupted and an error is returned. Once the handshake has completed, cancellation of the context will not affect the connection.
Most uses of this package need not call HandshakeContext explicitly: the first Conn.Read or Conn.Write will call it automatically.
func (*Conn) NetConn ¶
NetConn returns the underlying connection that is wrapped by c. Note that writing to or reading from this connection directly will corrupt the TLS session.
func (*Conn) OCSPResponse ¶
OCSPResponse returns the stapled OCSP response from the TLS server, if any. (Only valid for client connections.)
func (*Conn) Read ¶
Read reads data from the connection.
As Read calls Conn.Handshake, in order to prevent indefinite blocking a deadline must be set for both Read and Conn.Write before Read is called when the handshake has not yet completed. See Conn.SetDeadline, Conn.SetReadDeadline, and Conn.SetWriteDeadline.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the remote network address.
func (*Conn) SetDeadline ¶
SetDeadline sets the read and write deadlines associated with the connection. A zero value for t means Conn.Read and Conn.Write will not time out. After a Write has timed out, the TLS state is corrupt and all future writes will return the same error.
func (*Conn) SetReadDeadline ¶
SetReadDeadline sets the read deadline on the underlying connection. A zero value for t means Conn.Read will not time out.
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline sets the write deadline on the underlying connection. A zero value for t means Conn.Write will not time out. After a Conn.Write has timed out, the TLS state is corrupt and all future writes will return the same error.
func (*Conn) VerifyHostname ¶
VerifyHostname checks that the peer certificate chain is valid for connecting to host. If so, it returns nil; if not, it returns an error describing the problem.
func (*Conn) Write ¶
Write writes data to the connection.
As Write calls Conn.Handshake, in order to prevent indefinite blocking a deadline must be set for both Conn.Read and Write before Write is called when the handshake has not yet completed. See Conn.SetDeadline, Conn.SetReadDeadline, and Conn.SetWriteDeadline.
type ConnectionState ¶
type ConnectionState struct { // Version is the TLS version used by the connection (e.g. VersionTLS12). Version uint16 // HandshakeComplete is true if the handshake has concluded. HandshakeComplete bool // DidResume is true if this connection was successfully resumed from a // previous session with a session ticket or similar mechanism. DidResume bool // CipherSuite is the cipher suite negotiated for the connection (e.g. // TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_AES_128_GCM_SHA256). CipherSuite uint16 // NegotiatedProtocol is the application protocol negotiated with ALPN. NegotiatedProtocol string // NegotiatedProtocolIsMutual used to indicate a mutual NPN negotiation. // // Deprecated: this value is always true. NegotiatedProtocolIsMutual bool // ClientProtocolSetting is the application protocol negotiated with ALPS. ClientProtocolSetting []byte // ServerProtocolSetting is the application protocol negotiated with ALPS. ServerProtocolSetting []byte // ServerName is the value of the Server Name Indication extension sent by // the client. It's available both on the server and on the client side. ServerName string // PeerCertificates are the parsed certificates sent by the peer, in the // order in which they were sent. The first element is the leaf certificate // that the connection is verified against. // // On the client side, it can't be empty. On the server side, it can be // empty if Config.ClientAuth is not RequireAnyClientCert or // RequireAndVerifyClientCert. // // PeerCertificates and its contents should not be modified. PeerCertificates []*x509.Certificate // VerifiedChains is a list of one or more chains where the first element is // PeerCertificates[0] and the last element is from Config.RootCAs (on the // client side) or Config.ClientCAs (on the server side). // // On the client side, it's set if Config.InsecureSkipVerify is false. On // the server side, it's set if Config.ClientAuth is VerifyClientCertIfGiven // (and the peer provided a certificate) or RequireAndVerifyClientCert. // // VerifiedChains and its contents should not be modified. VerifiedChains [][]*x509.Certificate // SignedCertificateTimestamps is a list of SCTs provided by the peer // through the TLS handshake for the leaf certificate, if any. SignedCertificateTimestamps [][]byte // OCSPResponse is a stapled Online Certificate Status Protocol (OCSP) // response provided by the peer for the leaf certificate, if any. OCSPResponse []byte // TLSUnique contains the "tls-unique" channel binding value (see RFC 5929, // Section 3). This value will be nil for TLS 1.3 connections and for // resumed connections that don't support Extended Master Secret (RFC 7627). TLSUnique []byte // ECHAccepted indicates if Encrypted Client Hello was offered by the client // and accepted by the server. Currently, ECH is supported only on the // client side. ECHAccepted bool // contains filtered or unexported fields }
ConnectionState records basic TLS details about the connection.
func ToConnectionState ¶
func ToConnectionState(tcs tls.ConnectionState) (cs ConnectionState)
func (ConnectionState) Compatible ¶
func (cs ConnectionState) Compatible() (tcs tls.ConnectionState)
func (*ConnectionState) ExportKeyingMaterial ¶
func (cs *ConnectionState) ExportKeyingMaterial(label string, context []byte, length int) ([]byte, error)
ExportKeyingMaterial returns length bytes of exported key material in a new slice as defined in RFC 5705. If context is nil, it is not used as part of the seed. If the connection was set to allow renegotiation via Config.Renegotiation, or if the connections supports neither TLS 1.3 nor Extended Master Secret, this function will return an error.
Exporting key material without Extended Master Secret or TLS 1.3 was disabled in Go 1.22 due to security issues (see the Security Considerations sections of RFC 5705 and RFC 7627), but can be re-enabled with the GODEBUG setting tlsunsafeekm=1.
type CookieExtension ¶
type CookieExtension struct {
// contains filtered or unexported fields
}
func (*CookieExtension) Clone ¶
func (*CookieExtension) Clone() Extension
func (*CookieExtension) ExtensionId ¶
func (*CookieExtension) ExtensionId() uint16
func (*CookieExtension) Marshal ¶
func (*CookieExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*CookieExtension) NegotiatedVersion ¶
func (*CookieExtension) NegotiatedVersion(vers uint16)
type CurveID ¶
type CurveID uint16
CurveID is the type of a TLS identifier for a key exchange mechanism. See https://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-8.
In TLS 1.2, this registry used to support only elliptic curves. In TLS 1.3, it was extended to other groups and renamed NamedGroup. See RFC 8446, Section 4.2.7. It was then also extended to other mechanisms, such as hybrid post-quantum KEMs.
type Dialer ¶
type Dialer struct { // NetDialer is the optional dialer to use for the TLS connections' // underlying TCP connections. // A nil NetDialer is equivalent to the net.Dialer zero value. NetDialer *net.Dialer // Config is the TLS configuration to use for new connections. // A nil configuration is equivalent to the zero // configuration; see the documentation of Config for the // defaults. Config *Config }
Dialer dials TLS connections given a configuration and a Dialer for the underlying connection.
func (*Dialer) Dial ¶
Dial connects to the given network address and initiates a TLS handshake, returning the resulting TLS connection.
The returned Conn, if any, will always be of type *Conn.
Dial uses context.Background internally; to specify the context, use Dialer.DialContext.
func (*Dialer) DialContext ¶
DialContext connects to the given network address and initiates a TLS handshake, returning the resulting TLS connection.
The provided Context must be non-nil. If the context expires before the connection is complete, an error is returned. Once successfully connected, any expiration of the context will not affect the connection.
type ECHDummyConfig ¶
type ECHDummyConfig struct { ConfigIds []uint8 CipherSuites []ECHCipher HelloInnerLens []uint16 // Pre-encryption. If 0, will pick 128 (+16=144) }
ECHDummyConfig represents an ECH dummy configuration.
type ECHOuterExtension ¶
type ECHOuterExtension struct {
// contains filtered or unexported fields
}
func (*ECHOuterExtension) Clone ¶
func (*ECHOuterExtension) Clone() Extension
func (*ECHOuterExtension) ExtensionId ¶
func (*ECHOuterExtension) ExtensionId() uint16
func (*ECHOuterExtension) Marshal ¶
func (*ECHOuterExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*ECHOuterExtension) NegotiatedVersion ¶
func (*ECHOuterExtension) NegotiatedVersion(vers uint16)
type ECHRejectionError ¶
type ECHRejectionError struct {
RetryConfigList []byte
}
ECHRejectionError is the error type returned when ECH is rejected by a remote server. If the server offered a ECHConfigList to use for retries, the RetryConfigList field will contain this list.
The client may treat an ECHRejectionError with an empty set of RetryConfigs as a secure signal from the server.
func (*ECHRejectionError) Error ¶
func (e *ECHRejectionError) Error() string
type EarlyDataExtension ¶
type EarlyDataExtension struct {
// contains filtered or unexported fields
}
func (*EarlyDataExtension) Clone ¶
func (*EarlyDataExtension) Clone() Extension
func (*EarlyDataExtension) ExtensionId ¶
func (*EarlyDataExtension) ExtensionId() uint16
func (*EarlyDataExtension) Marshal ¶
func (*EarlyDataExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*EarlyDataExtension) NegotiatedVersion ¶
func (*EarlyDataExtension) NegotiatedVersion(vers uint16)
type EncryptedClientHelloExtension ¶
type EncryptedClientHelloExtension struct {
// contains filtered or unexported fields
}
func (*EncryptedClientHelloExtension) Clone ¶
func (*EncryptedClientHelloExtension) Clone() Extension
func (*EncryptedClientHelloExtension) ExtensionId ¶
func (*EncryptedClientHelloExtension) ExtensionId() uint16
func (*EncryptedClientHelloExtension) Marshal ¶
func (*EncryptedClientHelloExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*EncryptedClientHelloExtension) NegotiatedVersion ¶
func (*EncryptedClientHelloExtension) NegotiatedVersion(vers uint16)
type EncryptedClientHelloKey ¶
type EncryptedClientHelloKey struct { // Config should be a marshalled ECHConfig associated with PrivateKey. This // must match the config provided to clients byte-for-byte. The config // should only specify the DHKEM(X25519, HKDF-SHA256) KEM ID (0x0020), the // HKDF-SHA256 KDF ID (0x0001), and a subset of the following AEAD IDs: // AES-128-GCM (0x0000), AES-256-GCM (0x0001), ChaCha20Poly1305 (0x0002). Config []byte // PrivateKey should be a marshalled private key. Currently, we expect // this to be the output of [ecdh.PrivateKey.Bytes]. PrivateKey []byte // SendAsRetry indicates if Config should be sent as part of the list of // retry configs when ECH is requested by the client but rejected by the // server. SendAsRetry bool }
EncryptedClientHelloKey holds a private key that is associated with a specific ECH config known to a client.
type ExtendedMasterSecretExtension ¶
type ExtendedMasterSecretExtension struct {
// contains filtered or unexported fields
}
func (*ExtendedMasterSecretExtension) Clone ¶
func (*ExtendedMasterSecretExtension) Clone() Extension
func (*ExtendedMasterSecretExtension) ExtensionId ¶
func (*ExtendedMasterSecretExtension) ExtensionId() uint16
func (*ExtendedMasterSecretExtension) Marshal ¶
func (*ExtendedMasterSecretExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*ExtendedMasterSecretExtension) NegotiatedVersion ¶
func (*ExtendedMasterSecretExtension) NegotiatedVersion(vers uint16)
type Extension ¶
type Extension interface { // TLS extension id ExtensionId() uint16 // It will be called after protocol negotiation NegotiatedVersion(vers uint16) // Return true if this extension needs to be negotiated. // It will call the Marshal function to generate the message. Negotiate(messageType uint8, encryptedClientHello bool) bool Len(messageType uint8, encryptedClientHello bool) int Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool // Clone returns a shallow clone of extension. It is safe to clone an // extension that is being used concurrently by a TLS client or server. Clone() Extension }
TLS Extension
type GREASEExtension ¶
type GREASEExtension struct { Id uint16 Data cryptobyte.String }
func (*GREASEExtension) Clone ¶
func (extension *GREASEExtension) Clone() Extension
func (*GREASEExtension) ExtensionId ¶
func (extension *GREASEExtension) ExtensionId() uint16
func (*GREASEExtension) Len ¶
func (extension *GREASEExtension) Len(messageType uint8, encryptedClientHello bool) int
func (*GREASEExtension) Marshal ¶
func (extension *GREASEExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*GREASEExtension) Negotiate ¶
func (*GREASEExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
func (*GREASEExtension) NegotiatedVersion ¶
func (*GREASEExtension) NegotiatedVersion(vers uint16)
func (*GREASEExtension) Unmarshal ¶
func (extension *GREASEExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
type KDF ¶
type KDF uint16
const ( // RFC 9180, Section 7.2 // KDF_HKDF_SHA256 is a KDF using HKDF with SHA-256. KDF_HKDF_SHA256 KDF = 0x01 )
type KEM ¶
type KEM uint16
const ( // RFC 9180, Section 7.2 // KEM_X25519_HKDF_SHA256 is a KEM using X25519 Diffie-Hellman function // and HKDF with SHA-256. KEM_X25519_HKDF_SHA256 KEM = 0x20 )
type KeyShareExtension ¶
type KeyShareExtension struct {
// contains filtered or unexported fields
}
func (*KeyShareExtension) Clone ¶
func (*KeyShareExtension) Clone() Extension
func (*KeyShareExtension) ExtensionId ¶
func (*KeyShareExtension) ExtensionId() uint16
func (*KeyShareExtension) Marshal ¶
func (*KeyShareExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*KeyShareExtension) NegotiatedVersion ¶
func (*KeyShareExtension) NegotiatedVersion(vers uint16)
type PSKModesExtension ¶
type PSKModesExtension struct {
// contains filtered or unexported fields
}
func (*PSKModesExtension) Clone ¶
func (*PSKModesExtension) Clone() Extension
func (*PSKModesExtension) ExtensionId ¶
func (*PSKModesExtension) ExtensionId() uint16
func (*PSKModesExtension) Marshal ¶
func (*PSKModesExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*PSKModesExtension) NegotiatedVersion ¶
func (*PSKModesExtension) NegotiatedVersion(vers uint16)
type PaddingExtension ¶
type PaddingExtension struct {
Length uint16
}
func (*PaddingExtension) Clone ¶
func (extension *PaddingExtension) Clone() Extension
func (*PaddingExtension) ExtensionId ¶
func (*PaddingExtension) ExtensionId() uint16
func (*PaddingExtension) Len ¶
func (extension *PaddingExtension) Len(messageType uint8, encryptedClientHello bool) int
func (*PaddingExtension) Marshal ¶
func (extension *PaddingExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*PaddingExtension) Negotiate ¶
func (*PaddingExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
func (*PaddingExtension) NegotiatedVersion ¶
func (*PaddingExtension) NegotiatedVersion(vers uint16)
func (*PaddingExtension) Unmarshal ¶
func (extension *PaddingExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
type PreSharedKeyExtension ¶
type PreSharedKeyExtension struct {
// contains filtered or unexported fields
}
func (*PreSharedKeyExtension) Clone ¶
func (*PreSharedKeyExtension) Clone() Extension
func (*PreSharedKeyExtension) ExtensionId ¶
func (*PreSharedKeyExtension) ExtensionId() uint16
func (*PreSharedKeyExtension) Marshal ¶
func (*PreSharedKeyExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*PreSharedKeyExtension) NegotiatedVersion ¶
func (*PreSharedKeyExtension) NegotiatedVersion(vers uint16)
type QUICConfig ¶
type QUICConfig struct { TLSConfig *Config // EnableSessionEvents may be set to true to enable the // [QUICStoreSession] and [QUICResumeSession] events for client connections. // When this event is enabled, sessions are not automatically // stored in the client session cache. // The application should use [QUICConn.StoreSession] to store sessions. EnableSessionEvents bool }
A QUICConfig configures a QUICConn.
type QUICConn ¶
type QUICConn struct {
// contains filtered or unexported fields
}
A QUICConn represents a connection which uses a QUIC implementation as the underlying transport as described in RFC 9001.
Methods of QUICConn are not safe for concurrent use.
func QUICClient ¶
func QUICClient(config *QUICConfig) *QUICConn
QUICClient returns a new TLS client side connection using QUICTransport as the underlying transport. The config cannot be nil.
The config's MinVersion must be at least TLS 1.3.
func QUICServer ¶
func QUICServer(config *QUICConfig) *QUICConn
QUICServer returns a new TLS server side connection using QUICTransport as the underlying transport. The config cannot be nil.
The config's MinVersion must be at least TLS 1.3.
func (*QUICConn) ConnectionState ¶
func (q *QUICConn) ConnectionState() ConnectionState
ConnectionState returns basic TLS details about the connection.
func (*QUICConn) HandleData ¶
func (q *QUICConn) HandleData(level QUICEncryptionLevel, data []byte) error
HandleData handles handshake bytes received from the peer. It may produce connection events, which may be read with QUICConn.NextEvent.
func (*QUICConn) NextEvent ¶
NextEvent returns the next event occurring on the connection. It returns an event with a Kind of QUICNoEvent when no events are available.
func (*QUICConn) SendSessionTicket ¶
func (q *QUICConn) SendSessionTicket(opts QUICSessionTicketOptions) error
SendSessionTicket sends a session ticket to the client. It produces connection events, which may be read with QUICConn.NextEvent. Currently, it can only be called once.
func (*QUICConn) SetTransportParameters ¶
SetTransportParameters sets the transport parameters to send to the peer.
Server connections may delay setting the transport parameters until after receiving the client's transport parameters. See QUICTransportParametersRequired.
func (*QUICConn) Start ¶
Start starts the client or server handshake protocol. It may produce connection events, which may be read with QUICConn.NextEvent.
Start must be called at most once.
func (*QUICConn) StoreSession ¶
func (q *QUICConn) StoreSession(session *SessionState) error
StoreSession stores a session previously received in a QUICStoreSession event in the ClientSessionCache. The application may process additional events or modify the SessionState before storing the session.
type QUICEncryptionLevel ¶
type QUICEncryptionLevel int
QUICEncryptionLevel represents a QUIC encryption level used to transmit handshake messages.
func (QUICEncryptionLevel) String ¶
func (l QUICEncryptionLevel) String() string
type QUICEvent ¶
type QUICEvent struct { Kind QUICEventKind // Set for QUICSetReadSecret, QUICSetWriteSecret, and QUICWriteData. Level QUICEncryptionLevel // Set for QUICTransportParameters, QUICSetReadSecret, QUICSetWriteSecret, and QUICWriteData. // The contents are owned by crypto/tls, and are valid until the next NextEvent call. Data []byte // Set for QUICSetReadSecret and QUICSetWriteSecret. Suite uint16 // Set for QUICResumeSession and QUICStoreSession. SessionState *SessionState }
A QUICEvent is an event occurring on a QUIC connection.
The type of event is specified by the Kind field. The contents of the other fields are kind-specific.
type QUICEventKind ¶
type QUICEventKind int
A QUICEventKind is a type of operation on a QUIC connection.
const ( // QUICNoEvent indicates that there are no events available. QUICNoEvent QUICEventKind = iota // QUICSetReadSecret and QUICSetWriteSecret provide the read and write // secrets for a given encryption level. // QUICEvent.Level, QUICEvent.Data, and QUICEvent.Suite are set. // // Secrets for the Initial encryption level are derived from the initial // destination connection ID, and are not provided by the QUICConn. QUICSetReadSecret QUICSetWriteSecret // QUICWriteData provides data to send to the peer in CRYPTO frames. // QUICEvent.Data is set. QUICWriteData // QUICTransportParameters provides the peer's QUIC transport parameters. // QUICEvent.Data is set. QUICTransportParameters // QUICTransportParametersRequired indicates that the caller must provide // QUIC transport parameters to send to the peer. The caller should set // the transport parameters with QUICConn.SetTransportParameters and call // QUICConn.NextEvent again. // // If transport parameters are set before calling QUICConn.Start, the // connection will never generate a QUICTransportParametersRequired event. QUICTransportParametersRequired // QUICRejectedEarlyData indicates that the server rejected 0-RTT data even // if we offered it. It's returned before QUICEncryptionLevelApplication // keys are returned. // This event only occurs on client connections. QUICRejectedEarlyData // QUICHandshakeDone indicates that the TLS handshake has completed. QUICHandshakeDone // QUICResumeSession indicates that a client is attempting to resume a previous session. // [QUICEvent.SessionState] is set. // // For client connections, this event occurs when the session ticket is selected. // For server connections, this event occurs when receiving the client's session ticket. // // The application may set [QUICEvent.SessionState.EarlyData] to false before the // next call to [QUICConn.NextEvent] to decline 0-RTT even if the session supports it. QUICResumeSession // QUICStoreSession indicates that the server has provided state permitting // the client to resume the session. // [QUICEvent.SessionState] is set. // The application should use [QUICConn.StoreSession] session to store the [SessionState]. // The application may modify the [SessionState] before storing it. // This event only occurs on client connections. QUICStoreSession )
type QUICTransportParametersExtension ¶
type QUICTransportParametersExtension struct {
// contains filtered or unexported fields
}
func (*QUICTransportParametersExtension) Clone ¶
func (*QUICTransportParametersExtension) Clone() Extension
func (*QUICTransportParametersExtension) ExtensionId ¶
func (*QUICTransportParametersExtension) ExtensionId() uint16
func (*QUICTransportParametersExtension) Marshal ¶
func (*QUICTransportParametersExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*QUICTransportParametersExtension) NegotiatedVersion ¶
func (*QUICTransportParametersExtension) NegotiatedVersion(vers uint16)
type RecordHeaderError ¶
type RecordHeaderError struct { // Msg contains a human readable string that describes the error. Msg string // RecordHeader contains the five bytes of TLS record header that // triggered the error. RecordHeader [5]byte // Conn provides the underlying net.Conn in the case that a client // sent an initial handshake that didn't look like TLS. // It is nil if there's already been a handshake or a TLS alert has // been written to the connection. Conn net.Conn }
RecordHeaderError is returned when a TLS record header is invalid.
func (RecordHeaderError) Error ¶
func (e RecordHeaderError) Error() string
type RenegotiationInfoExtension ¶
type RenegotiationInfoExtension struct {
// contains filtered or unexported fields
}
func (*RenegotiationInfoExtension) Clone ¶
func (*RenegotiationInfoExtension) Clone() Extension
func (*RenegotiationInfoExtension) ExtensionId ¶
func (*RenegotiationInfoExtension) ExtensionId() uint16
func (*RenegotiationInfoExtension) Marshal ¶
func (*RenegotiationInfoExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*RenegotiationInfoExtension) NegotiatedVersion ¶
func (*RenegotiationInfoExtension) NegotiatedVersion(vers uint16)
type RenegotiationSupport ¶
type RenegotiationSupport int
RenegotiationSupport enumerates the different levels of support for TLS renegotiation. TLS renegotiation is the act of performing subsequent handshakes on a connection after the first. This significantly complicates the state machine and has been the source of numerous, subtle security issues. Initiating a renegotiation is not supported, but support for accepting renegotiation requests may be enabled.
Even when enabled, the server may not change its identity between handshakes (i.e. the leaf certificate must be the same). Additionally, concurrent handshake and application data flow is not permitted so renegotiation can only be used with protocols that synchronise with the renegotiation, such as HTTPS.
Renegotiation is not defined in TLS 1.3.
const ( // RenegotiateNever disables renegotiation. RenegotiateNever RenegotiationSupport = iota // RenegotiateOnceAsClient allows a remote server to request // renegotiation once per connection. RenegotiateOnceAsClient // RenegotiateFreelyAsClient allows a remote server to repeatedly // request renegotiation. RenegotiateFreelyAsClient )
type SCTExtension ¶
type SCTExtension struct {
// contains filtered or unexported fields
}
func (*SCTExtension) Clone ¶
func (*SCTExtension) Clone() Extension
func (*SCTExtension) ExtensionId ¶
func (*SCTExtension) ExtensionId() uint16
func (*SCTExtension) Marshal ¶
func (*SCTExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*SCTExtension) NegotiatedVersion ¶
func (*SCTExtension) NegotiatedVersion(vers uint16)
type ServerNameIndicationExtension ¶
type ServerNameIndicationExtension struct {
// contains filtered or unexported fields
}
func (*ServerNameIndicationExtension) Clone ¶
func (*ServerNameIndicationExtension) Clone() Extension
func (*ServerNameIndicationExtension) ExtensionId ¶
func (*ServerNameIndicationExtension) ExtensionId() uint16
func (*ServerNameIndicationExtension) Marshal ¶
func (*ServerNameIndicationExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*ServerNameIndicationExtension) NegotiatedVersion ¶
func (*ServerNameIndicationExtension) NegotiatedVersion(vers uint16)
type SessionState ¶
type SessionState struct { // Extra is ignored by crypto/tls, but is encoded by [SessionState.Bytes] // and parsed by [ParseSessionState]. // // This allows [Config.UnwrapSession]/[Config.WrapSession] and // [ClientSessionCache] implementations to store and retrieve additional // data alongside this session. // // To allow different layers in a protocol stack to share this field, // applications must only append to it, not replace it, and must use entries // that can be recognized even if out of order (for example, by starting // with an id and version prefix). Extra [][]byte // MaxEarlyData indicates whether the ticket can be used for 0-RTT in a // connection. The application may set this to 0 if it is true to // decline to offer 0-RTT even if supported. MaxEarlyData uint32 // contains filtered or unexported fields }
A SessionState is a resumable session.
func ParseSessionState ¶
func ParseSessionState(data []byte) (*SessionState, error)
ParseSessionState parses a SessionState encoded by SessionState.Bytes.
func (*SessionState) Bytes ¶
func (s *SessionState) Bytes() ([]byte, error)
Bytes encodes the session, including any private fields, so that it can be parsed by ParseSessionState. The encoding contains secret values critical to the security of future and possibly past sessions.
The specific encoding should be considered opaque and may change incompatibly between Go versions.
type SessionTicketExtension ¶
type SessionTicketExtension struct {
// contains filtered or unexported fields
}
func (*SessionTicketExtension) Clone ¶
func (*SessionTicketExtension) Clone() Extension
func (*SessionTicketExtension) ExtensionId ¶
func (*SessionTicketExtension) ExtensionId() uint16
func (*SessionTicketExtension) Marshal ¶
func (*SessionTicketExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*SessionTicketExtension) NegotiatedVersion ¶
func (*SessionTicketExtension) NegotiatedVersion(vers uint16)
type SignatureAlgorithmsCertExtension ¶
type SignatureAlgorithmsCertExtension struct {
// contains filtered or unexported fields
}
func (*SignatureAlgorithmsCertExtension) Clone ¶
func (*SignatureAlgorithmsCertExtension) Clone() Extension
func (*SignatureAlgorithmsCertExtension) ExtensionId ¶
func (*SignatureAlgorithmsCertExtension) ExtensionId() uint16
func (*SignatureAlgorithmsCertExtension) Marshal ¶
func (*SignatureAlgorithmsCertExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*SignatureAlgorithmsCertExtension) NegotiatedVersion ¶
func (*SignatureAlgorithmsCertExtension) NegotiatedVersion(vers uint16)
type SignatureAlgorithmsExtension ¶
type SignatureAlgorithmsExtension struct {
// contains filtered or unexported fields
}
func (*SignatureAlgorithmsExtension) Clone ¶
func (*SignatureAlgorithmsExtension) Clone() Extension
func (*SignatureAlgorithmsExtension) ExtensionId ¶
func (*SignatureAlgorithmsExtension) ExtensionId() uint16
func (*SignatureAlgorithmsExtension) Marshal ¶
func (*SignatureAlgorithmsExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*SignatureAlgorithmsExtension) NegotiatedVersion ¶
func (*SignatureAlgorithmsExtension) NegotiatedVersion(vers uint16)
type SignatureScheme ¶
type SignatureScheme uint16
SignatureScheme identifies a signature algorithm supported by TLS. See RFC 8446, Section 4.2.3.
const ( // RSASSA-PKCS1-v1_5 algorithms. PKCS1WithSHA256 SignatureScheme = 0x0401 PKCS1WithSHA384 SignatureScheme = 0x0501 PKCS1WithSHA512 SignatureScheme = 0x0601 // RSASSA-PSS algorithms with public key OID rsaEncryption. PSSWithSHA256 SignatureScheme = 0x0804 PSSWithSHA384 SignatureScheme = 0x0805 PSSWithSHA512 SignatureScheme = 0x0806 // ECDSA algorithms. Only constrained to a specific curve in TLS 1.3. ECDSAWithP256AndSHA256 SignatureScheme = 0x0403 ECDSAWithP384AndSHA384 SignatureScheme = 0x0503 ECDSAWithP521AndSHA512 SignatureScheme = 0x0603 // EdDSA algorithms. Ed25519 SignatureScheme = 0x0807 // Legacy signature and hash algorithms for TLS 1.2. PKCS1WithSHA1 SignatureScheme = 0x0201 ECDSAWithSHA1 SignatureScheme = 0x0203 )
func (SignatureScheme) String ¶
func (i SignatureScheme) String() string
type StatusRequestExtension ¶
type StatusRequestExtension struct {
// contains filtered or unexported fields
}
func (*StatusRequestExtension) Clone ¶
func (*StatusRequestExtension) Clone() Extension
func (*StatusRequestExtension) ExtensionId ¶
func (*StatusRequestExtension) ExtensionId() uint16
func (*StatusRequestExtension) Marshal ¶
func (*StatusRequestExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*StatusRequestExtension) NegotiatedVersion ¶
func (*StatusRequestExtension) NegotiatedVersion(vers uint16)
type SupportedGroupsExtension ¶
type SupportedGroupsExtension struct {
// contains filtered or unexported fields
}
func (*SupportedGroupsExtension) Clone ¶
func (*SupportedGroupsExtension) Clone() Extension
func (*SupportedGroupsExtension) ExtensionId ¶
func (*SupportedGroupsExtension) ExtensionId() uint16
func (*SupportedGroupsExtension) Marshal ¶
func (*SupportedGroupsExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*SupportedGroupsExtension) NegotiatedVersion ¶
func (*SupportedGroupsExtension) NegotiatedVersion(vers uint16)
type SupportedPointsExtension ¶
type SupportedPointsExtension struct {
// contains filtered or unexported fields
}
func (*SupportedPointsExtension) Clone ¶
func (*SupportedPointsExtension) Clone() Extension
func (*SupportedPointsExtension) ExtensionId ¶
func (*SupportedPointsExtension) ExtensionId() uint16
func (*SupportedPointsExtension) Marshal ¶
func (*SupportedPointsExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*SupportedPointsExtension) NegotiatedVersion ¶
func (*SupportedPointsExtension) NegotiatedVersion(vers uint16)
type SupportedVersionsExtension ¶
type SupportedVersionsExtension struct {
// contains filtered or unexported fields
}
func (*SupportedVersionsExtension) Clone ¶
func (*SupportedVersionsExtension) Clone() Extension
func (*SupportedVersionsExtension) ExtensionId ¶
func (*SupportedVersionsExtension) ExtensionId() uint16
func (*SupportedVersionsExtension) Marshal ¶
func (*SupportedVersionsExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*SupportedVersionsExtension) NegotiatedVersion ¶
func (*SupportedVersionsExtension) NegotiatedVersion(vers uint16)
type UnimplementedExtension ¶
type UnimplementedExtension struct { Id uint16 Data cryptobyte.String }
func (*UnimplementedExtension) Clone ¶
func (extension *UnimplementedExtension) Clone() Extension
func (*UnimplementedExtension) ExtensionId ¶
func (extension *UnimplementedExtension) ExtensionId() uint16
func (*UnimplementedExtension) Len ¶
func (extension *UnimplementedExtension) Len(messageType uint8, encryptedClientHello bool) int
func (*UnimplementedExtension) Marshal ¶
func (extension *UnimplementedExtension) Marshal(messageType uint8, encryptedClientHello bool, b *cryptobyte.Builder)
func (*UnimplementedExtension) Negotiate ¶
func (*UnimplementedExtension) Negotiate(messageType uint8, encryptedClientHello bool) bool
func (*UnimplementedExtension) NegotiatedVersion ¶
func (*UnimplementedExtension) NegotiatedVersion(vers uint16)
func (*UnimplementedExtension) Unmarshal ¶
func (extension *UnimplementedExtension) Unmarshal(messageType uint8, encryptedClientHello bool, b cryptobyte.String) bool
Notes ¶
Bugs ¶
The crypto/tls package only implements some countermeasures against Lucky13 attacks on CBC-mode encryption, and only on SHA1 variants. See http://www.isg.rhul.ac.uk/tls/TLStiming.pdf and https://www.imperialviolet.org/2013/02/04/luckythirteen.html.
Source Files
¶
- alert.go
- auth.go
- cache.go
- cert_compress.go
- cipher_suites.go
- cipher_suites_kernel_linux.go
- common.go
- common_string.go
- compatible.go
- conn.go
- defaults.go
- ech.go
- ech_grease.go
- extension.go
- extension_grease.go
- handshake_client.go
- handshake_client_tls13.go
- handshake_messages.go
- handshake_server.go
- handshake_server_tls13.go
- kernel.go
- kernel_linux.go
- key_agreement.go
- key_schedule.go
- prf.go
- quic.go
- ticket.go
- tls.go