1// Copyright 2009 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package runner 6 7import ( 8 "container/list" 9 "crypto" 10 "crypto/ecdsa" 11 "crypto/rand" 12 "crypto/x509" 13 "fmt" 14 "io" 15 "math/big" 16 "sync" 17 "time" 18 19 "boringssl.googlesource.com/boringssl.git/ssl/test/runner/hpke" 20) 21 22const ( 23 VersionSSL30 = 0x0300 24 VersionTLS10 = 0x0301 25 VersionTLS11 = 0x0302 26 VersionTLS12 = 0x0303 27 VersionTLS13 = 0x0304 28) 29 30const ( 31 VersionDTLS10 = 0xfeff 32 VersionDTLS12 = 0xfefd 33 VersionDTLS13 = 0xfefc 34) 35 36var allTLSWireVersions = []uint16{ 37 VersionTLS13, 38 VersionTLS12, 39 VersionTLS11, 40 VersionTLS10, 41 VersionSSL30, 42} 43 44var allDTLSWireVersions = []uint16{ 45 VersionDTLS13, 46 VersionDTLS12, 47 VersionDTLS10, 48} 49 50const ( 51 maxPlaintext = 16384 // maximum plaintext payload length 52 maxCiphertext = 16384 + 2048 // maximum ciphertext payload length 53 tlsRecordHeaderLen = 5 // record header length 54 dtlsMaxRecordHeaderLen = 13 55 maxHandshake = 65536 // maximum handshake we support (protocol max is 16 MB) 56 57 minVersion = VersionSSL30 58 maxVersion = VersionTLS13 59) 60 61// TLS record types. 62type recordType uint8 63 64const ( 65 recordTypeChangeCipherSpec recordType = 20 66 recordTypeAlert recordType = 21 67 recordTypeHandshake recordType = 22 68 recordTypeApplicationData recordType = 23 69 recordTypePlaintextHandshake recordType = 24 70 recordTypeACK recordType = 26 71) 72 73// TLS handshake message types. 74const ( 75 typeHelloRequest uint8 = 0 76 typeClientHello uint8 = 1 77 typeServerHello uint8 = 2 78 typeHelloVerifyRequest uint8 = 3 79 typeNewSessionTicket uint8 = 4 80 typeEndOfEarlyData uint8 = 5 81 typeEncryptedExtensions uint8 = 8 82 typeCertificate uint8 = 11 83 typeServerKeyExchange uint8 = 12 84 typeCertificateRequest uint8 = 13 85 typeServerHelloDone uint8 = 14 86 typeCertificateVerify uint8 = 15 87 typeClientKeyExchange uint8 = 16 88 typeFinished uint8 = 20 89 typeCertificateStatus uint8 = 22 90 typeKeyUpdate uint8 = 24 91 typeCompressedCertificate uint8 = 25 92 typeNextProtocol uint8 = 67 // Not IANA assigned 93 typeChannelID uint8 = 203 // Not IANA assigned 94 typeMessageHash uint8 = 254 95) 96 97func messageTypeToString(typ uint8) string { 98 switch typ { 99 case typeHelloRequest: 100 return "HelloRequest" 101 case typeClientHello: 102 return "ClientHello" 103 case typeServerHello: 104 return "ServerHello" 105 case typeHelloVerifyRequest: 106 return "HelloVerifyRequest" 107 case typeNewSessionTicket: 108 return "NewSessionTicket" 109 case typeEndOfEarlyData: 110 return "EndOfEarlyData" 111 case typeEncryptedExtensions: 112 return "EncryptedExtensions" 113 case typeCertificate: 114 return "Certificate" 115 case typeServerKeyExchange: 116 return "ServerKeyExchange" 117 case typeCertificateRequest: 118 return "CertificateRequest" 119 case typeServerHelloDone: 120 return "ServerHelloDone" 121 case typeCertificateVerify: 122 return "CertificateVerify" 123 case typeClientKeyExchange: 124 return "ClientKeyExchange" 125 case typeFinished: 126 return "Finished" 127 case typeCertificateStatus: 128 return "CertificateStatus" 129 case typeKeyUpdate: 130 return "KeyUpdate" 131 case typeCompressedCertificate: 132 return "CompressedCertificate" 133 case typeNextProtocol: 134 return "NextProtocol" 135 case typeChannelID: 136 return "ChannelID" 137 case typeMessageHash: 138 return "MessageHash" 139 } 140 return fmt.Sprintf("unknown(%d)", typ) 141} 142 143// TLS compression types. 144const ( 145 compressionNone uint8 = 0 146) 147 148// TLS extension numbers 149const ( 150 extensionServerName uint16 = 0 151 extensionStatusRequest uint16 = 5 152 extensionSupportedCurves uint16 = 10 153 extensionSupportedPoints uint16 = 11 154 extensionSignatureAlgorithms uint16 = 13 155 extensionUseSRTP uint16 = 14 156 extensionALPN uint16 = 16 157 extensionSignedCertificateTimestamp uint16 = 18 158 extensionPadding uint16 = 21 159 extensionExtendedMasterSecret uint16 = 23 160 extensionCompressedCertAlgs uint16 = 27 161 extensionDelegatedCredential uint16 = 34 162 extensionSessionTicket uint16 = 35 163 extensionPreSharedKey uint16 = 41 164 extensionEarlyData uint16 = 42 165 extensionSupportedVersions uint16 = 43 166 extensionCookie uint16 = 44 167 extensionPSKKeyExchangeModes uint16 = 45 168 extensionCertificateAuthorities uint16 = 47 169 extensionSignatureAlgorithmsCert uint16 = 50 170 extensionKeyShare uint16 = 51 171 extensionQUICTransportParams uint16 = 57 172 extensionTLSFlags uint16 = 62 173 extensionCustom uint16 = 1234 // not IANA assigned 174 extensionNextProtoNeg uint16 = 13172 // not IANA assigned 175 extensionApplicationSettingsOld uint16 = 17513 // not IANA assigned 176 extensionApplicationSettings uint16 = 17613 // not IANA assigned 177 extensionRenegotiationInfo uint16 = 0xff01 178 extensionQUICTransportParamsLegacy uint16 = 0xffa5 // draft-ietf-quic-tls-32 and earlier 179 extensionChannelID uint16 = 30032 // not IANA assigned 180 extensionPAKE uint16 = 35387 // not IANA assigned 181 extensionTrustAnchors uint16 = 0xca34 // not IANA assigned 182 extensionDuplicate uint16 = 0xffff // not IANA assigned 183 extensionEncryptedClientHello uint16 = 0xfe0d // not IANA assigned 184 extensionECHOuterExtensions uint16 = 0xfd00 // not IANA assigned 185) 186 187const ( 188 flagResumptionAcrossNames = 8 189) 190 191// TLS signaling cipher suite values 192const ( 193 scsvRenegotiation uint16 = 0x00ff 194) 195 196var tls13HelloRetryRequest = []uint8{ 197 0xcf, 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 198 0x02, 0x1e, 0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 199 0x8c, 0x5e, 0x07, 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 200} 201 202// CurveID is the type of a TLS identifier for an elliptic curve. See 203// http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-8 204type CurveID uint16 205 206const ( 207 CurveP256 CurveID = 23 208 CurveP384 CurveID = 24 209 CurveP521 CurveID = 25 210 CurveX25519 CurveID = 29 211 CurveX25519MLKEM768 CurveID = 0x11ec 212 CurveX25519Kyber768 CurveID = 0x6399 213 CurveMLKEM1024 CurveID = 0x0202 214) 215 216// TLS Elliptic Curve Point Formats 217// http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-9 218const ( 219 pointFormatUncompressed uint8 = 0 220 pointFormatCompressedPrime uint8 = 1 221) 222 223// TLS CertificateStatusType (RFC 3546) 224const ( 225 statusTypeOCSP uint8 = 1 226) 227 228// Certificate types (for certificateRequestMsg) 229const ( 230 CertTypeRSASign = 1 // A certificate containing an RSA key 231 CertTypeDSSSign = 2 // A certificate containing a DSA key 232 CertTypeRSAFixedDH = 3 // A certificate containing a static DH key 233 CertTypeDSSFixedDH = 4 // A certificate containing a static DH key 234 235 // See RFC 4492 sections 3 and 5.5. 236 CertTypeECDSASign = 64 // A certificate containing an ECDSA-capable public key, signed with ECDSA. 237 CertTypeRSAFixedECDH = 65 // A certificate containing an ECDH-capable public key, signed with RSA. 238 CertTypeECDSAFixedECDH = 66 // A certificate containing an ECDH-capable public key, signed with ECDSA. 239 240 // Rest of these are reserved by the TLS spec 241) 242 243// signatureAlgorithm corresponds to a SignatureScheme value from TLS 1.3. Note 244// that TLS 1.3 names the production 'SignatureScheme' to avoid colliding with 245// TLS 1.2's SignatureAlgorithm but otherwise refers to them as 'signature 246// algorithms' throughout. We match the latter. 247type signatureAlgorithm uint16 248 249const ( 250 // RSASSA-PKCS1-v1_5 algorithms 251 signatureRSAPKCS1WithMD5 signatureAlgorithm = 0x0101 252 signatureRSAPKCS1WithSHA1 signatureAlgorithm = 0x0201 253 signatureRSAPKCS1WithSHA256 signatureAlgorithm = 0x0401 254 signatureRSAPKCS1WithSHA384 signatureAlgorithm = 0x0501 255 signatureRSAPKCS1WithSHA512 signatureAlgorithm = 0x0601 256 257 // ECDSA algorithms 258 signatureECDSAWithSHA1 signatureAlgorithm = 0x0203 259 signatureECDSAWithP256AndSHA256 signatureAlgorithm = 0x0403 260 signatureECDSAWithP384AndSHA384 signatureAlgorithm = 0x0503 261 signatureECDSAWithP521AndSHA512 signatureAlgorithm = 0x0603 262 263 // RSASSA-PSS algorithms 264 signatureRSAPSSWithSHA256 signatureAlgorithm = 0x0804 265 signatureRSAPSSWithSHA384 signatureAlgorithm = 0x0805 266 signatureRSAPSSWithSHA512 signatureAlgorithm = 0x0806 267 268 // EdDSA algorithms 269 signatureEd25519 signatureAlgorithm = 0x0807 270 signatureEd448 signatureAlgorithm = 0x0808 271 272 // draft-ietf-tls-tls13-pkcs1-00 273 signatureRSAPKCS1WithSHA256Legacy signatureAlgorithm = 0x0420 274 275 // signatureRSAPKCS1WithMD5AndSHA1 is the internal value BoringSSL uses to 276 // represent the TLS 1.0/1.1 RSA MD5/SHA1 concatenation. We define the 277 // constant here to test that this doesn't leak into the protocol. 278 signatureRSAPKCS1WithMD5AndSHA1 signatureAlgorithm = 0xff01 279) 280 281// supportedSignatureAlgorithms contains the default supported signature 282// algorithms. 283var supportedSignatureAlgorithms = []signatureAlgorithm{ 284 signatureRSAPSSWithSHA256, 285 signatureRSAPSSWithSHA384, 286 signatureRSAPKCS1WithSHA256, 287 signatureECDSAWithP256AndSHA256, 288 signatureECDSAWithP384AndSHA384, 289 signatureRSAPKCS1WithSHA1, 290 signatureRSAPKCS1WithSHA256, 291 signatureRSAPKCS1WithSHA384, 292 signatureECDSAWithSHA1, 293 signatureEd25519, 294} 295 296// SRTP protection profiles (See RFC 5764, section 4.1.2) 297const ( 298 SRTP_AES128_CM_HMAC_SHA1_80 uint16 = 0x0001 299 SRTP_AES128_CM_HMAC_SHA1_32 = 0x0002 300) 301 302// PskKeyExchangeMode values (see RFC 8446, section 4.2.9) 303const ( 304 pskKEMode = 0 305 pskDHEKEMode = 1 306) 307 308// KeyUpdateRequest values (see RFC 8446, section 4.6.3) 309const ( 310 keyUpdateNotRequested = 0 311 keyUpdateRequested = 1 312) 313 314// draft-ietf-tls-esni-13, sections 7.2 and 7.2.1. 315const echAcceptConfirmationLength = 8 316 317// Temporary value; pre RFC. 318const spakeID uint16 = 0x7d96 319 320// ConnectionState records basic TLS details about the connection. 321type ConnectionState struct { 322 Version uint16 // TLS version used by the connection (e.g. VersionTLS12) 323 HandshakeComplete bool // TLS handshake is complete 324 DidResume bool // connection resumes a previous TLS connection 325 CipherSuite uint16 // cipher suite in use (TLS_RSA_WITH_RC4_128_SHA, ...) 326 NegotiatedProtocol string // negotiated next protocol (from Config.NextProtos) 327 NegotiatedProtocolIsMutual bool // negotiated protocol was advertised by server 328 NegotiatedProtocolFromALPN bool // protocol negotiated with ALPN 329 ServerName string // server name requested by client, if any (server side only) 330 ServerNameAck bool // whether the server acknowledged the server name (client side only) 331 PeerCertificates []*x509.Certificate // certificate chain presented by remote peer 332 PeerDelegatedCredential []byte // delegated credential presented by remote peer 333 VerifiedChains [][]*x509.Certificate // verified chains built from PeerCertificates 334 OCSPResponse []byte // stapled OCSP response from the peer, if any 335 ChannelID *ecdsa.PublicKey // the channel ID for this connection 336 SRTPProtectionProfile uint16 // the negotiated DTLS-SRTP protection profile 337 TLSUnique []byte // the tls-unique channel binding 338 SCTList []byte // signed certificate timestamp list 339 PeerSignatureAlgorithm signatureAlgorithm // algorithm used by the peer in the handshake 340 CurveID CurveID // the curve used in ECDHE 341 QUICTransportParams []byte // the QUIC transport params received from the peer 342 QUICTransportParamsLegacy []byte // the legacy QUIC transport params received from the peer 343 HasApplicationSettings bool // whether ALPS was negotiated 344 PeerApplicationSettings []byte // application settings received from the peer 345 HasApplicationSettingsOld bool // whether ALPS old codepoint was negotiated 346 PeerApplicationSettingsOld []byte // the old application settings received from the peer 347 ECHAccepted bool // whether ECH was accepted on this connection 348} 349 350// ClientAuthType declares the policy the server will follow for 351// TLS Client Authentication. 352type ClientAuthType int 353 354const ( 355 NoClientCert ClientAuthType = iota 356 RequestClientCert 357 RequireAnyClientCert 358 VerifyClientCertIfGiven 359 RequireAndVerifyClientCert 360) 361 362// ClientSessionState contains the state needed by clients to resume TLS 363// sessions. 364type ClientSessionState struct { 365 sessionID []uint8 // Session ID supplied by the server. nil if the session has a ticket. 366 sessionTicket []uint8 // Encrypted ticket used for session resumption with server 367 vers uint16 // SSL/TLS version negotiated for the session 368 wireVersion uint16 // Wire SSL/TLS version negotiated for the session 369 cipherSuite *cipherSuite // Ciphersuite negotiated for the session 370 secret []byte // Secret associated with the session 371 handshakeHash []byte // Handshake hash for Channel ID purposes. 372 serverCertificates []*x509.Certificate // Certificate chain presented by the server 373 serverDelegatedCredential []byte 374 extendedMasterSecret bool // Whether an extended master secret was used to generate the session 375 sctList []byte 376 ocspResponse []byte 377 earlyALPN string 378 ticketCreationTime time.Time 379 ticketExpiration time.Time 380 ticketAgeAdd uint32 381 maxEarlyDataSize uint32 382 hasApplicationSettings bool 383 localApplicationSettings []byte 384 peerApplicationSettings []byte 385 hasApplicationSettingsOld bool 386 localApplicationSettingsOld []byte 387 peerApplicationSettingsOld []byte 388 resumptionAcrossNames bool 389} 390 391// ClientSessionCache is a cache of ClientSessionState objects that can be used 392// by a client to resume a TLS session with a given server. ClientSessionCache 393// implementations should expect to be called concurrently from different 394// goroutines. 395type ClientSessionCache interface { 396 // Get searches for a ClientSessionState associated with the given key. 397 // On return, ok is true if one was found. 398 Get(sessionKey string) (session *ClientSessionState, ok bool) 399 400 // Put adds the ClientSessionState to the cache with the given key. 401 Put(sessionKey string, cs *ClientSessionState) 402} 403 404// ServerSessionCache is a cache of sessionState objects that can be used by a 405// client to resume a TLS session with a given server. ServerSessionCache 406// implementations should expect to be called concurrently from different 407// goroutines. 408type ServerSessionCache interface { 409 // Get searches for a sessionState associated with the given session 410 // ID. On return, ok is true if one was found. 411 Get(sessionID string) (session *sessionState, ok bool) 412 413 // Put adds the sessionState to the cache with the given session ID. 414 Put(sessionID string, session *sessionState) 415} 416 417// CertCompressionAlg is a certificate compression algorithm, specified as a 418// pair of functions for compressing and decompressing certificates. 419type CertCompressionAlg struct { 420 // Compress returns a compressed representation of the input. 421 Compress func([]byte) []byte 422 // Decompress depresses the contents of in and writes the result to out, which 423 // will be the correct size. It returns true on success and false otherwise. 424 Decompress func(out, in []byte) bool 425} 426 427// QUICUseCodepoint controls which TLS extension codepoint is used to convey the 428// QUIC transport parameters. QUICUseCodepointStandard means use 57, 429// QUICUseCodepointLegacy means use legacy value 0xff5a, QUICUseCodepointBoth 430// means use both. QUICUseCodepointNeither means do not send transport 431// parameters. 432type QUICUseCodepoint int 433 434const ( 435 QUICUseCodepointStandard QUICUseCodepoint = iota 436 QUICUseCodepointLegacy 437 QUICUseCodepointBoth 438 QUICUseCodepointNeither 439 NumQUICUseCodepoints 440) 441 442func (c QUICUseCodepoint) IncludeStandard() bool { 443 return c == QUICUseCodepointStandard || c == QUICUseCodepointBoth 444} 445 446func (c QUICUseCodepoint) IncludeLegacy() bool { 447 return c == QUICUseCodepointLegacy || c == QUICUseCodepointBoth 448} 449 450func (c QUICUseCodepoint) String() string { 451 switch c { 452 case QUICUseCodepointStandard: 453 return "Standard" 454 case QUICUseCodepointLegacy: 455 return "Legacy" 456 case QUICUseCodepointBoth: 457 return "Both" 458 case QUICUseCodepointNeither: 459 return "Neither" 460 } 461 panic("unknown value") 462} 463 464// ALPSUseCodepoint controls which TLS extension codepoint is used to convey the 465// ApplicationSettings. ALPSUseCodepointNew means use 17613, 466// ALPSUseCodepointOld means use old value 17513. 467type ALPSUseCodepoint int 468 469const ( 470 ALPSUseCodepointNew ALPSUseCodepoint = iota 471 ALPSUseCodepointOld 472 NumALPSUseCodepoints 473) 474 475func (c ALPSUseCodepoint) IncludeNew() bool { 476 return c == ALPSUseCodepointNew 477} 478 479func (c ALPSUseCodepoint) IncludeOld() bool { 480 return c == ALPSUseCodepointOld 481} 482 483func (c ALPSUseCodepoint) String() string { 484 switch c { 485 case ALPSUseCodepointNew: 486 return "New" 487 case ALPSUseCodepointOld: 488 return "Old" 489 } 490 panic("unknown value") 491} 492 493// A Config structure is used to configure a TLS client or server. 494// After one has been passed to a TLS function it must not be 495// modified. A Config may be reused; the tls package will also not 496// modify it. 497type Config struct { 498 // Rand provides the source of entropy for nonces and RSA blinding. 499 // If Rand is nil, TLS uses the cryptographic random reader in package 500 // crypto/rand. 501 // The Reader must be safe for use by multiple goroutines. 502 Rand io.Reader 503 504 // Time returns the current time as the number of seconds since the epoch. 505 // If Time is nil, TLS uses time.Now. 506 Time func() time.Time 507 508 // Credential contains the credential to present to the other side of 509 // the connection. Server configurations must include this field. 510 Credential *Credential 511 512 // RootCAs defines the set of root certificate authorities 513 // that clients use when verifying server certificates. 514 // If RootCAs is nil, TLS uses the host's root CA set. 515 RootCAs *x509.CertPool 516 517 // SendRootCAs, if true, causes the client to send the list of 518 // supported root CAs in the certificate_authorities extension. 519 SendRootCAs bool 520 521 // NextProtos is a list of supported, application level protocols. 522 NextProtos []string 523 524 // NoFallbackNextProto, if true, causes the client to decline to pick an NPN 525 // protocol, instead of picking an opportunistic, fallback protocol. 526 NoFallbackNextProto bool 527 528 // NegotiateNPNWithNoProtos, if true, causes the server to negotiate NPN 529 // despite having no protocols configured. 530 NegotiateNPNWithNoProtos bool 531 532 // ApplicationSettings is a set of application settings to use which each 533 // application protocol. 534 ApplicationSettings map[string][]byte 535 536 // ALPSUseNewCodepoint controls which TLS extension codepoint is used to 537 // convey the ApplicationSettings. 538 ALPSUseNewCodepoint ALPSUseCodepoint 539 540 // ServerName is used to verify the hostname on the returned 541 // certificates unless InsecureSkipVerify is given. It is also included 542 // in the client's handshake to support virtual hosting. 543 ServerName string 544 545 // ClientECHConfig, when non-nil, is the ECHConfig the client will use to 546 // attempt ECH. 547 ClientECHConfig *ECHConfig 548 549 // ECHCipherSuites, for the client, is the list of HPKE cipher suites in 550 // decreasing order of preference. If empty, the default will be used. 551 ECHCipherSuites []HPKECipherSuite 552 553 // ServerECHConfigs is the server's list of ECHConfig values with 554 // corresponding secret keys. 555 ServerECHConfigs []ServerECHConfig 556 557 // ECHOuterExtensions is the list of extensions that the client will 558 // compress with the ech_outer_extensions extension. If empty, no extensions 559 // will be compressed. 560 ECHOuterExtensions []uint16 561 562 // ClientAuth determines the server's policy for 563 // TLS Client Authentication. The default is NoClientCert. 564 ClientAuth ClientAuthType 565 566 // ClientCAs defines the set of root certificate authorities 567 // that servers use if required to verify a client certificate 568 // by the policy in ClientAuth. 569 ClientCAs *x509.CertPool 570 571 // ClientCertificateTypes defines the set of allowed client certificate 572 // types. The default is CertTypeRSASign and CertTypeECDSASign. 573 ClientCertificateTypes []byte 574 575 // InsecureSkipVerify controls whether a client verifies the 576 // server's certificate chain and host name. 577 // If InsecureSkipVerify is true, TLS accepts any certificate 578 // presented by the server and any host name in that certificate. 579 // In this mode, TLS is susceptible to man-in-the-middle attacks. 580 // This should be used only for testing. 581 InsecureSkipVerify bool 582 583 // CipherSuites is a list of supported cipher suites. If CipherSuites 584 // is nil, TLS uses a list of suites supported by the implementation. 585 CipherSuites []uint16 586 587 // PreferServerCipherSuites controls whether the server selects the 588 // client's most preferred ciphersuite, or the server's most preferred 589 // ciphersuite. If true then the server's preference, as expressed in 590 // the order of elements in CipherSuites, is used. 591 PreferServerCipherSuites bool 592 593 // SessionTicketsDisabled may be set to true to disable session ticket 594 // (resumption) support. 595 SessionTicketsDisabled bool 596 597 // SessionTicketKey is used by TLS servers to provide session 598 // resumption. See RFC 5077. If zero, it will be filled with 599 // random data before the first server handshake. 600 // 601 // If multiple servers are terminating connections for the same host 602 // they should all have the same SessionTicketKey. If the 603 // SessionTicketKey leaks, previously recorded and future TLS 604 // connections using that key are compromised. 605 SessionTicketKey [32]byte 606 607 // ClientSessionCache is a cache of ClientSessionState entries 608 // for TLS session resumption. 609 ClientSessionCache ClientSessionCache 610 611 // ServerSessionCache is a cache of sessionState entries for TLS session 612 // resumption. 613 ServerSessionCache ServerSessionCache 614 615 // MinVersion contains the minimum SSL/TLS version that is acceptable. 616 // If zero, then SSLv3 is taken as the minimum. 617 MinVersion uint16 618 619 // MaxVersion contains the maximum SSL/TLS version that is acceptable. 620 // If zero, then the maximum version supported by this package is used, 621 // which is currently TLS 1.2. 622 MaxVersion uint16 623 624 // CurvePreferences contains the elliptic curves that will be used in 625 // an ECDHE handshake, in preference order. If empty, the default will 626 // be used. 627 CurvePreferences []CurveID 628 629 // DefaultCurves contains the elliptic curves for which public values will 630 // be sent in the ClientHello's KeyShare extension. If this value is nil, 631 // all supported curves will have public values sent. This field is ignored 632 // on servers. 633 DefaultCurves []CurveID 634 635 // ChannelID contains the ECDSA key for the client to use as 636 // its TLS Channel ID. 637 ChannelID *ecdsa.PrivateKey 638 639 // RequestChannelID controls whether the server requests a TLS 640 // Channel ID. If negotiated, the client's public key is 641 // returned in the ConnectionState. 642 RequestChannelID bool 643 644 // PreSharedKey, if not nil, is the pre-shared key to use with 645 // the PSK cipher suites. 646 PreSharedKey []byte 647 648 // PreSharedKeyIdentity, if not empty, is the identity to use 649 // with the PSK cipher suites. 650 PreSharedKeyIdentity string 651 652 // MaxEarlyDataSize controls the maximum number of bytes that the 653 // server will accept in early data and advertise in a 654 // NewSessionTicketMsg. If 0, no early data will be accepted and 655 // the early_data extension in the NewSessionTicketMsg will be omitted. 656 MaxEarlyDataSize uint32 657 658 // SRTPProtectionProfiles, if not nil, is the list of SRTP 659 // protection profiles to offer in DTLS-SRTP. 660 SRTPProtectionProfiles []uint16 661 662 // VerifySignatureAlgorithms, if not nil, overrides the default set of 663 // supported signature algorithms that are accepted. 664 VerifySignatureAlgorithms []signatureAlgorithm 665 666 // DelegatedCredentialAlgorithms, if not empty, is the set of signature 667 // algorithms allowed for the delegated credential key. If empty, delegated 668 // credentials are disabled. 669 DelegatedCredentialAlgorithms []signatureAlgorithm 670 671 // QUICTransportParams, if not empty, will be sent in the QUIC 672 // transport parameters extension. 673 QUICTransportParams []byte 674 675 // QUICTransportParamsUseLegacyCodepoint controls which TLS extension 676 // codepoint is used to convey the QUIC transport parameters. 677 QUICTransportParamsUseLegacyCodepoint QUICUseCodepoint 678 679 CertCompressionAlgs map[uint16]CertCompressionAlg 680 681 // DTLSUseShortSeqNums specifies whether the DTLS 1.3 record header 682 // should use short (8-bit) or long (16-bit) sequence numbers. The 683 // default is to use long sequence numbers. 684 DTLSUseShortSeqNums bool 685 686 // DTLSRecordHeaderOmitLength specified whether the DTLS 1.3 record 687 // header includes a length field. The default is to include the length 688 // field. 689 DTLSRecordHeaderOmitLength bool 690 691 // RequestTrustAnchors, if not nil, is the list of trust anchor IDs to 692 // request in ClientHello. 693 RequestTrustAnchors [][]byte 694 695 // AvailableTrustAnchors, if not empty, is the list of trust anchor IDs 696 // to report as available in EncryptedExtensions. 697 AvailableTrustAnchors [][]byte 698 699 // ResumptionAcrossNames specifies whether session tickets issued by the TLS 700 // server should be marked as compatable with cross-name resumption. 701 ResumptionAcrossNames bool 702 703 // Bugs specifies optional misbehaviour to be used for testing other 704 // implementations. 705 Bugs ProtocolBugs 706 707 serverInitOnce sync.Once // guards calling (*Config).serverInit 708} 709 710type BadValue int 711 712const ( 713 BadValueNone BadValue = iota 714 BadValueNegative 715 BadValueZero 716 BadValueLimit 717 BadValueLarge 718 NumBadValues 719) 720 721type RSABadValue int 722 723const ( 724 RSABadValueNone RSABadValue = iota 725 RSABadValueCorrupt 726 RSABadValueTooLong 727 RSABadValueTooShort 728 RSABadValueWrongVersion1 729 RSABadValueWrongVersion2 730 RSABadValueWrongBlockType 731 RSABadValueWrongLeadingByte 732 RSABadValueNoZero 733 NumRSABadValues 734) 735 736type ProtocolBugs struct { 737 // InvalidSignature specifies that the signature in a ServerKeyExchange 738 // or CertificateVerify message should be invalid. 739 InvalidSignature bool 740 741 // SendCurve, if non-zero, causes the server to send the specified curve 742 // ID in ServerKeyExchange (TLS 1.2) or ServerHello (TLS 1.3) rather 743 // than the negotiated one. 744 SendCurve CurveID 745 746 // ECDHPointNotOnCurve, if true, causes the ECDH points to not be on the 747 // curve. 748 ECDHPointNotOnCurve bool 749 750 // TruncateKeyShare, if true, causes key shares to be truncated by one byte. 751 TruncateKeyShare bool 752 753 // PadKeyShare, if true, causes key shares to be truncated to one byte. 754 PadKeyShare bool 755 756 // BadECDSAR controls ways in which the 'r' value of an ECDSA signature 757 // can be invalid. 758 BadECDSAR BadValue 759 BadECDSAS BadValue 760 761 // MaxPadding causes CBC records to have the maximum possible padding. 762 MaxPadding bool 763 // PaddingFirstByteBad causes the first byte of the padding to be 764 // incorrect. 765 PaddingFirstByteBad bool 766 // PaddingFirstByteBadIf255 causes the first byte of padding to be 767 // incorrect if there's a maximum amount of padding (i.e. 255 bytes). 768 PaddingFirstByteBadIf255 bool 769 770 // FailIfNotFallbackSCSV causes a server handshake to fail if the 771 // client doesn't send the fallback SCSV value. 772 FailIfNotFallbackSCSV bool 773 774 // DuplicateExtension causes an extra empty extension of bogus type to 775 // be emitted in either the ClientHello or the ServerHello. 776 DuplicateExtension bool 777 778 // UnauthenticatedECDH causes the server to pretend ECDHE_RSA 779 // and ECDHE_ECDSA cipher suites are actually ECDH_anon. No 780 // Certificate message is sent and no signature is added to 781 // ServerKeyExchange. 782 UnauthenticatedECDH bool 783 784 // SkipHelloVerifyRequest causes a DTLS server to skip the 785 // HelloVerifyRequest message. 786 SkipHelloVerifyRequest bool 787 788 // ForceHelloVerifyRequest causes a DTLS server to send a 789 // HelloVerifyRequest message in DTLS 1.3 or other cases where it 790 // otherwise wouldn't. 791 ForceHelloVerifyRequest bool 792 793 // HelloVerifyRequestCookieLength, if non-zero, is the length of the cookie 794 // to request in HelloVerifyRequest. 795 HelloVerifyRequestCookieLength int 796 797 // EmptyHelloVerifyRequestCookie, if true, causes a DTLS server to request 798 // an empty cookie in HelloVerifyRequest. 799 EmptyHelloVerifyRequestCookie bool 800 801 // SkipCertificateStatus, if true, causes the server to skip the 802 // CertificateStatus message. This is legal because CertificateStatus is 803 // optional, even with a status_request in ServerHello. 804 SkipCertificateStatus bool 805 806 // SkipServerKeyExchange causes the server to skip sending 807 // ServerKeyExchange messages. 808 SkipServerKeyExchange bool 809 810 // SkipNewSessionTicket causes the server to skip sending the 811 // NewSessionTicket message despite promising to in ServerHello. 812 SkipNewSessionTicket bool 813 814 // UseFirstSessionTicket causes the client to cache only the first session 815 // ticket received. 816 UseFirstSessionTicket bool 817 818 // SkipClientCertificate causes the client to skip the Certificate 819 // message. 820 SkipClientCertificate bool 821 822 // SkipChangeCipherSpec causes the implementation to skip 823 // sending the ChangeCipherSpec message (and adjusting cipher 824 // state accordingly for the Finished message). 825 SkipChangeCipherSpec bool 826 827 // SkipFinished causes the implementation to skip sending the Finished 828 // message. 829 SkipFinished bool 830 831 // SkipEndOfEarlyData causes the implementation to skip 832 // end_of_early_data. 833 SkipEndOfEarlyData bool 834 835 // NonEmptyEndOfEarlyData causes the implementation to end an extra byte in the 836 // EndOfEarlyData. 837 NonEmptyEndOfEarlyData bool 838 839 // SendEndOfEarlyDataInQUICAndDTLS causes the implementation to send 840 // EndOfEarlyData even in QUIC and DTLS, which do not use the message. 841 SendEndOfEarlyDataInQUICAndDTLS bool 842 843 // SkipCertificateVerify, if true causes peer to skip sending a 844 // CertificateVerify message after the Certificate message. 845 SkipCertificateVerify bool 846 847 // EarlyChangeCipherSpec causes the client to send an early 848 // ChangeCipherSpec message before the ClientKeyExchange. A value of 849 // zero disables this behavior. One and two configure variants for 850 // 1.0.1 and 0.9.8 modes, respectively. 851 EarlyChangeCipherSpec int 852 853 // FragmentAcrossChangeCipherSpec causes the implementation to fragment 854 // the Finished (or NextProto) message around the ChangeCipherSpec 855 // messages. 856 FragmentAcrossChangeCipherSpec bool 857 858 // SendExtraChangeCipherSpec causes the implementation to send extra 859 // ChangeCipherSpec messages. 860 SendExtraChangeCipherSpec int 861 862 // SendPostHandshakeChangeCipherSpec causes the implementation to send 863 // a ChangeCipherSpec record before every application data record. 864 SendPostHandshakeChangeCipherSpec bool 865 866 // PartialEncryptedExtensionsWithServerHello, if true, causes the TLS 867 // 1.3 server to send part of EncryptedExtensions unencrypted 868 // in the same record as ServerHello. 869 PartialEncryptedExtensionsWithServerHello bool 870 871 // PartialClientFinishedWithClientHello, if true, causes the TLS 1.2 872 // or TLS 1.3 client to send part of Finished unencrypted in the same 873 // record as ClientHello. 874 PartialClientFinishedWithClientHello bool 875 876 // PartialClientFinishedWithSecondClientHello, if true, causes the 877 // TLS 1.3 client to send part of Finished unencrypted in the same 878 // record as the second ClientHello. 879 PartialClientFinishedWithSecondClientHello bool 880 881 // PartialEndOfEarlyDataWithClientHello, if true, causes the TLS 1.3 882 // client to send part of EndOfEarlyData unencrypted in the same record 883 // as ClientHello. 884 PartialEndOfEarlyDataWithClientHello bool 885 886 // PartialSecondClientHelloAfterFirst, if true, causes the TLS 1.3 client 887 // to send part of the second ClientHello in the same record as the first 888 // one. 889 PartialSecondClientHelloAfterFirst bool 890 891 // PartialClientKeyExchangeWithClientHello, if true, causes the TLS 1.2 892 // client to send part of the ClientKeyExchange in the same record as 893 // the ClientHello. 894 PartialClientKeyExchangeWithClientHello bool 895 896 // PartialNewSessionTicketWithServerHelloDone, if true, causes the TLS 1.2 897 // server to send part of the NewSessionTicket in the same record as 898 // ServerHelloDone. 899 PartialNewSessionTicketWithServerHelloDone bool 900 901 // PartialNewSessionTicketWithServerHelloDone, if true, causes the TLS 1.2 902 // server to send part of the Finshed in the same record as ServerHelloDone. 903 PartialFinishedWithServerHelloDone bool 904 905 // PartialServerHelloWithHelloRetryRequest, if true, causes the TLS 1.3 906 // server to send part of the ServerHello in the same record as 907 // HelloRetryRequest. 908 PartialServerHelloWithHelloRetryRequest bool 909 910 // TrailingDataWithFinished, if true, causes the record containing the 911 // Finished message to include an extra byte of data at the end. 912 TrailingDataWithFinished bool 913 914 // SendV2ClientHello causes the client to send a V2ClientHello 915 // instead of a normal ClientHello. 916 SendV2ClientHello bool 917 918 // V2ClientHelloChallengeLength is the length of the challenge field to send 919 // in V2ClientHello. 920 V2ClientHelloChallengeLength int 921 922 // SendFallbackSCSV causes the client to include 923 // TLS_FALLBACK_SCSV in the ClientHello. 924 SendFallbackSCSV bool 925 926 // SendRenegotiationSCSV causes the client to include the renegotiation 927 // SCSV in the ClientHello. 928 SendRenegotiationSCSV bool 929 930 // MaxHandshakeRecordLength, if non-zero, is the maximum size of a 931 // handshake record. Handshake messages will be split into multiple 932 // records at the specified size. For DTLS, it is the maximum handshake 933 // fragment size, not record size; DTLS allows multiple handshake fragments 934 // in a single handshake record. See |PackHandshakeFragments|. 935 MaxHandshakeRecordLength int 936 937 // FragmentAlert will cause all alerts to be fragmented across 938 // two records. 939 FragmentAlert bool 940 941 // DoubleAlert will cause all alerts to be sent as two copies packed 942 // within one record. 943 DoubleAlert bool 944 945 // SendSpuriousAlert, if non-zero, will cause an spurious, unwanted 946 // alert to be sent. 947 SendSpuriousAlert alert 948 949 // BadRSAClientKeyExchange causes the client to send a corrupted RSA 950 // ClientKeyExchange which would not pass padding checks. 951 BadRSAClientKeyExchange RSABadValue 952 953 // RenewTicketOnResume causes the server to renew the session ticket and 954 // send a NewSessionTicket message during an abbreviated handshake. 955 RenewTicketOnResume bool 956 957 // SendClientVersion, if non-zero, causes the client to send the 958 // specified value in the ClientHello version field. 959 SendClientVersion uint16 960 961 // OmitSupportedVersions, if true, causes the client to omit the 962 // supported versions extension. 963 OmitSupportedVersions bool 964 965 // SendSupportedVersions, if non-empty, causes the client to send a 966 // supported versions extension with the values from array. 967 SendSupportedVersions []uint16 968 969 // NegotiateVersion, if non-zero, causes the server to negotiate the 970 // specifed wire version rather than the version supported by either 971 // peer. 972 NegotiateVersion uint16 973 974 // NegotiateVersionOnRenego, if non-zero, causes the server to negotiate 975 // the specified wire version on renegotiation rather than retaining it. 976 NegotiateVersionOnRenego uint16 977 978 // ExpectFalseStart causes the server to, on full handshakes, 979 // expect the peer to False Start; the server Finished message 980 // isn't sent until we receive an application data record 981 // from the peer. 982 ExpectFalseStart bool 983 984 // AlertBeforeFalseStartTest, if non-zero, causes the server to, on full 985 // handshakes, send an alert just before reading the application data 986 // record to test False Start. This can be used in a negative False 987 // Start test to determine whether the peer processed the alert (and 988 // closed the connection) before or after sending app data. 989 AlertBeforeFalseStartTest alert 990 991 // ExpectServerName, if not empty, is the hostname the client 992 // must specify in the selected ClientHello's server_name extension. 993 ExpectServerName string 994 995 // ExpectServerName, if not empty, is the hostname the client 996 // must specify in the ClientHelloOuter's server_name extension. 997 ExpectOuterServerName string 998 999 // ExpectClientECH causes the server to require that the client offer ECH. 1000 ExpectClientECH bool 1001 1002 // ExpectNoClientECH causes the server to require that the client not offer ECH. 1003 ExpectNoClientECH bool 1004 1005 // IgnoreECHConfigCipherPreferences, when true, causes the client to ignore 1006 // the cipher preferences in the ECHConfig and select the most preferred ECH 1007 // cipher suite unconditionally. 1008 IgnoreECHConfigCipherPreferences bool 1009 1010 // ExpectECHRetryConfigs, when non-nil, contains the expected bytes of the 1011 // server's retry configs. 1012 ExpectECHRetryConfigs []byte 1013 1014 // SendECHRetryConfigs, if not empty, contains the ECH server's serialized 1015 // retry configs. 1016 SendECHRetryConfigs []byte 1017 1018 // AlwaysSendECHRetryConfigs, if true, causes the ECH server to send retry 1019 // configs unconditionally, including in the TLS 1.2 ServerHello. 1020 AlwaysSendECHRetryConfigs bool 1021 1022 // AlwaysSendECHHelloRetryRequest, if true, causes the ECH server to send 1023 // the ECH HelloRetryRequest extension unconditionally. 1024 AlwaysSendECHHelloRetryRequest bool 1025 1026 // SendInvalidECHInner, if not empty, causes the client to send the 1027 // specified byte string after the type field in ClientHelloInner 1028 // encrypted_client_hello extension. 1029 SendInvalidECHInner []byte 1030 1031 // OmitECHInner, if true, causes the client to omit the encrypted_client_hello 1032 // extension on the ClientHelloInner message. 1033 OmitECHInner bool 1034 1035 // OmitSecondECHInner, if true, causes the client to omit the 1036 // encrypted_client_hello extension on the second ClientHelloInner message. 1037 OmitSecondECHInner bool 1038 1039 // OmitServerHelloECHConfirmation, if true, causes the server to omit the 1040 // ECH confirmation in the ServerHello. 1041 OmitServerHelloECHConfirmation bool 1042 1043 // AlwaysSendECHInner, if true, causes the client to send an inner 1044 // encrypted_client_hello extension on all ClientHello messages. The server 1045 // is then expected to unconditionally confirm the extension when 1046 // negotiating TLS 1.3 or later. 1047 AlwaysSendECHInner bool 1048 1049 // TruncateClientECHEnc, if true, causes the client to send a shortened 1050 // ClientECH.enc value in its encrypted_client_hello extension. 1051 TruncateClientECHEnc bool 1052 1053 // ClientECHPadding is the number of bytes of padding to add to the client 1054 // ECH payload. 1055 ClientECHPadding int 1056 1057 // BadClientECHPadding, if true, causes the client ECH padding to contain a 1058 // non-zero byte. 1059 BadClientECHPadding bool 1060 1061 // OfferSessionInClientHelloOuter, if true, causes the client to offer 1062 // sessions in ClientHelloOuter. 1063 OfferSessionInClientHelloOuter bool 1064 1065 // OnlyCompressSecondClientHelloInner, if true, causes the client to 1066 // only apply outer_extensions to the second ClientHello. 1067 OnlyCompressSecondClientHelloInner bool 1068 1069 // OmitSecondEncryptedClientHello, if true, causes the client to omit the 1070 // second encrypted_client_hello extension. 1071 OmitSecondEncryptedClientHello bool 1072 1073 // CorruptEncryptedClientHello, if true, causes the client to incorrectly 1074 // encrypt the encrypted_client_hello extension. 1075 CorruptEncryptedClientHello bool 1076 1077 // CorruptSecondEncryptedClientHello, if true, causes the client to 1078 // incorrectly encrypt the second encrypted_client_hello extension. 1079 CorruptSecondEncryptedClientHello bool 1080 1081 // CorruptSecondEncryptedClientHelloConfigID, if true, causes the client to 1082 // incorrectly set the second ClientHello's ECH config ID. 1083 CorruptSecondEncryptedClientHelloConfigID bool 1084 1085 // AllowTLS12InClientHelloInner, if true, causes the client to include 1086 // TLS 1.2 and earlier in ClientHelloInner. 1087 AllowTLS12InClientHelloInner bool 1088 1089 // MinimalClientHelloOuter, if true, causes the client to omit most fields 1090 // in ClientHelloOuter. Note this will make handshake attempts with the 1091 // ClientHelloOuter fail and should only be used in tests that expect 1092 // success. 1093 MinimalClientHelloOuter bool 1094 1095 // ExpectECHOuterExtensions is a list of extension IDs which the server 1096 // will require to be present in ech_outer_extensions. 1097 ExpectECHOuterExtensions []uint16 1098 1099 // ExpectECHOuterExtensions is a list of extension IDs which the server 1100 // will require to be omitted in ech_outer_extensions. 1101 ExpectECHUncompressedExtensions []uint16 1102 1103 // ECHOuterExtensionOrder, if not nil, is an extension order to apply to 1104 // ClientHelloOuter, instead of ordering the |ECHOuterExtensions| to match 1105 // in both ClientHellos. 1106 ECHOuterExtensionOrder []uint16 1107 1108 // UseInnerSessionWithClientHelloOuter, if true, causes the server to 1109 // handshake with ClientHelloOuter, but resume the session from 1110 // ClientHelloInner. 1111 UseInnerSessionWithClientHelloOuter bool 1112 1113 // RecordClientHelloInner, when non-nil, is called whenever the client 1114 // generates an encrypted ClientHello. The byte strings do not include the 1115 // ClientHello header. 1116 RecordClientHelloInner func(encodedInner, outer []byte) error 1117 1118 // SwapNPNAndALPN switches the relative order between NPN and ALPN in 1119 // both ClientHello and ServerHello. 1120 SwapNPNAndALPN bool 1121 1122 // ALPNProtocol, if not nil, sets the ALPN protocol that a server will 1123 // return. 1124 ALPNProtocol *string 1125 1126 // AlwaysNegotiateApplicationSettingsBoth, if true, causes the server to 1127 // negotiate ALPS using both codepoint for a protocol even if the client did 1128 // not support it or the version is wrong. 1129 AlwaysNegotiateApplicationSettingsBoth bool 1130 1131 // AlwaysNegotiateApplicationSettingsNew, if true, causes the server to 1132 // negotiate ALPS using new codepoint for a protocol even if the client did 1133 // not support it or the version is wrong. 1134 AlwaysNegotiateApplicationSettingsNew bool 1135 1136 // AlwaysNegotiateApplicationSettingsOld, if true, causes the server to 1137 // negotiate ALPS using old codepoint for a protocol even if the client did 1138 // not support it or the version is wrong. 1139 AlwaysNegotiateApplicationSettingsOld bool 1140 1141 // SendApplicationSettingsWithEarlyData, if true, causes the client and 1142 // server to send the application_settings extension with early data, 1143 // rather than letting them implicitly carry over. 1144 SendApplicationSettingsWithEarlyData bool 1145 1146 // AlwaysSendClientEncryptedExtension, if true, causes the client to always 1147 // send a, possibly empty, client EncryptedExtensions message. 1148 AlwaysSendClientEncryptedExtensions bool 1149 1150 // OmitClientEncryptedExtensions, if true, causes the client to omit the 1151 // client EncryptedExtensions message. 1152 OmitClientEncryptedExtensions bool 1153 1154 // OmitClientApplicationSettings, if true, causes the client to omit the 1155 // application_settings extension but still send EncryptedExtensions. 1156 OmitClientApplicationSettings bool 1157 1158 // SendExtraClientEncryptedExtension, if true, causes the client to 1159 // include an unsolicited extension in the client EncryptedExtensions 1160 // message. 1161 SendExtraClientEncryptedExtension bool 1162 1163 // AcceptAnySession causes the server to resume sessions regardless of 1164 // the version associated with the session or cipher suite. It also 1165 // causes the server to look in both TLS 1.2 and 1.3 extensions to 1166 // process a ticket. 1167 AcceptAnySession bool 1168 1169 // SendBothTickets, if true, causes the client to send tickets in both 1170 // TLS 1.2 and 1.3 extensions. 1171 SendBothTickets bool 1172 1173 // FilterTicket, if not nil, causes the client to modify a session 1174 // ticket before sending it in a resume handshake. 1175 FilterTicket func([]byte) ([]byte, error) 1176 1177 // TicketSessionIDLength, if non-zero, is the length of the session ID 1178 // to send with a ticket resumption offer. 1179 TicketSessionIDLength int 1180 1181 // EmptyTicketSessionID, if true, causes the client to send an empty 1182 // session ID with a ticket resumption offer. For simplicity, this will 1183 // also cause the client to interpret a ServerHello with empty session 1184 // ID as a resumption. (A client which sends empty session ID is 1185 // normally expected to look ahead for ChangeCipherSpec.) 1186 EmptyTicketSessionID bool 1187 1188 // NewSessionIDLength, if non-zero is the length of the session ID to use 1189 // when issung new sessions. 1190 NewSessionIDLength int 1191 1192 // SendClientHelloSessionID, if not nil, is the session ID sent in the 1193 // ClientHello. 1194 SendClientHelloSessionID []byte 1195 1196 // ExpectClientHelloSessionID, if true, causes the server to fail the 1197 // connection if there is not a session ID in the ClientHello. 1198 ExpectClientHelloSessionID bool 1199 1200 // EchoSessionIDInFullHandshake, if true, causes the server to echo the 1201 // ClientHello session ID, even in TLS 1.2 full handshakes. 1202 EchoSessionIDInFullHandshake bool 1203 1204 // ExpectNoSessionID, if true, causes the server to fail the connection if 1205 // the session ID field is present. 1206 ExpectNoSessionID bool 1207 1208 // ExpectNoTLS12Session, if true, causes the server to fail the 1209 // connection if the client offered a TLS 1.2 session. TLS 1.3 clients 1210 // always offer session IDs for compatibility, so the session ID check 1211 // checks for sessions the server issued. 1212 ExpectNoTLS12Session bool 1213 1214 // ExpectNoTLS12TicketSupport, if true, causes the server to fail the 1215 // connection if the client signaled TLS 1.2 session ticket support. 1216 // (This implicitly enforces that the client does not send a ticket.) 1217 ExpectNoTLS12TicketSupport bool 1218 1219 // ExpectNoTLS13PSK, if true, causes the server to fail the connection 1220 // if a TLS 1.3 PSK is offered. 1221 ExpectNoTLS13PSK bool 1222 1223 // ExpectNoTLS13PSKAfterHRR, if true, causes the server to fail the connection 1224 // if a TLS 1.3 PSK is offered after HRR. 1225 ExpectNoTLS13PSKAfterHRR bool 1226 1227 // RequireExtendedMasterSecret, if true, requires that the peer support 1228 // the extended master secret option. 1229 RequireExtendedMasterSecret bool 1230 1231 // NoExtendedMasterSecret causes the client and server to behave as if 1232 // they didn't support an extended master secret in the initial 1233 // handshake. 1234 NoExtendedMasterSecret bool 1235 1236 // NoExtendedMasterSecretOnRenegotiation causes the client and server to 1237 // behave as if they didn't support an extended master secret in 1238 // renegotiation handshakes. 1239 NoExtendedMasterSecretOnRenegotiation bool 1240 1241 // EmptyRenegotiationInfo causes the renegotiation extension to be 1242 // empty in a renegotiation handshake. 1243 EmptyRenegotiationInfo bool 1244 1245 // BadRenegotiationInfo causes the renegotiation extension value in a 1246 // renegotiation handshake to be incorrect at the start. 1247 BadRenegotiationInfo bool 1248 1249 // BadRenegotiationInfoEnd causes the renegotiation extension value in 1250 // a renegotiation handshake to be incorrect at the end. 1251 BadRenegotiationInfoEnd bool 1252 1253 // NoRenegotiationInfo disables renegotiation info support in all 1254 // handshakes. 1255 NoRenegotiationInfo bool 1256 1257 // NoRenegotiationInfoInInitial disables renegotiation info support in 1258 // the initial handshake. 1259 NoRenegotiationInfoInInitial bool 1260 1261 // NoRenegotiationInfoAfterInitial disables renegotiation info support 1262 // in renegotiation handshakes. 1263 NoRenegotiationInfoAfterInitial bool 1264 1265 // RequireRenegotiationInfo, if true, causes the client to return an 1266 // error if the server doesn't reply with the renegotiation extension. 1267 RequireRenegotiationInfo bool 1268 1269 // SequenceNumberMapping, if non-nil, is the mapping function to apply 1270 // to the sequence number of outgoing packets. For both TLS and DTLS, 1271 // the two most-significant bytes in the resulting sequence number are 1272 // ignored so that the DTLS epoch cannot be changed. 1273 SequenceNumberMapping func(uint64) uint64 1274 1275 // RSAEphemeralKey, if true, causes the server to send a 1276 // ServerKeyExchange message containing an ephemeral key (as in 1277 // RSA_EXPORT) in the plain RSA key exchange. 1278 RSAEphemeralKey bool 1279 1280 // SRTPMasterKeyIdentifier, if not empty, is the SRTP MKI value that the 1281 // client offers when negotiating SRTP. MKI support is still missing so 1282 // the peer must still send none. 1283 SRTPMasterKeyIdentifier string 1284 1285 // SendSRTPProtectionProfile, if non-zero, is the SRTP profile that the 1286 // server sends in the ServerHello instead of the negotiated one. 1287 SendSRTPProtectionProfile uint16 1288 1289 // NoSignatureAlgorithms, if true, causes the client to omit the 1290 // signature and hashes extension. 1291 // 1292 // For a server, it will cause an empty list to be sent in the 1293 // CertificateRequest message. None the less, the configured set will 1294 // still be enforced. 1295 NoSignatureAlgorithms bool 1296 1297 // NoSupportedCurves, if true, causes the client to omit the 1298 // supported_curves extension. 1299 NoSupportedCurves bool 1300 1301 // RequireSameRenegoClientVersion, if true, causes the server 1302 // to require that all ClientHellos match in offered version 1303 // across a renego. 1304 RequireSameRenegoClientVersion bool 1305 1306 // ExpectInitialRecordVersion, if non-zero, is the expected value of 1307 // record-layer version field before the protocol version is determined. 1308 ExpectInitialRecordVersion uint16 1309 1310 // SendRecordVersion, if non-zero, is the value to send as the 1311 // record-layer version. 1312 SendRecordVersion uint16 1313 1314 // SendInitialRecordVersion, if non-zero, is the value to send as the 1315 // record-layer version before the protocol version is determined. 1316 SendInitialRecordVersion uint16 1317 1318 // MaxPacketLength, if non-zero, is the maximum acceptable size for a 1319 // packet. The shim will also be expected to maximally fill packets in the 1320 // handshake up to this limit. 1321 MaxPacketLength int 1322 1323 // SendCipherSuite, if non-zero, is the cipher suite value that the 1324 // server will send in the ServerHello. This does not affect the cipher 1325 // the server believes it has actually negotiated. 1326 SendCipherSuite uint16 1327 1328 // SendCipherSuites, if not nil, is the cipher suite list that the 1329 // client will send in the ClientHello. This does not affect the cipher 1330 // the client believes it has actually offered. 1331 SendCipherSuites []uint16 1332 1333 // AppDataBeforeHandshake, if not nil, causes application data to be 1334 // sent immediately before the first handshake message. 1335 AppDataBeforeHandshake []byte 1336 1337 // AppDataAfterChangeCipherSpec, if not nil, causes application data to 1338 // be sent immediately after ChangeCipherSpec. 1339 AppDataAfterChangeCipherSpec []byte 1340 1341 // AlertAfterChangeCipherSpec, if non-zero, causes an alert to be sent 1342 // immediately after ChangeCipherSpec. 1343 AlertAfterChangeCipherSpec alert 1344 1345 // AppDataBeforeTLS13KeyChange, if not nil, causes application data to 1346 // be sent immediately before the final key change in (D)TLS 1.3. 1347 AppDataBeforeTLS13KeyChange []byte 1348 1349 // UnencryptedEncryptedExtensions, if true, causes the server to send 1350 // EncryptedExtensions unencrypted, delaying the first key change. 1351 UnencryptedEncryptedExtensions bool 1352 1353 // PacketAdaptor is the packetAdaptor to use to simulate timeouts. 1354 PacketAdaptor *packetAdaptor 1355 1356 // WriteFlightDTLS, if not nil, overrides the default behavior for writing 1357 // the flight in DTLS. See DTLSController for details. 1358 WriteFlightDTLS WriteFlightFunc 1359 1360 // ACKFlightDTLS, if not nil, overrides the default behavior for 1361 // acknowledging the final flight (of either the handshake or a 1362 // post-handshake transaction) in DTLS. See DTLSController for details. 1363 ACKFlightDTLS ACKFlightFunc 1364 1365 // SkipImplicitACKRead, if true, causes the DTLS 1.3 client to skip 1366 // implicitly reading the ACK at the end of the handshake. This may be used 1367 // when WriteFlightDTLS consumes the ACK itself. 1368 SkipImplicitACKRead bool 1369 1370 // MockQUICTransport is the mockQUICTransport used when testing 1371 // QUIC interfaces. 1372 MockQUICTransport *mockQUICTransport 1373 1374 // ReorderHandshakeFragments, if true, causes handshake fragments in 1375 // DTLS to overlap and be sent in the wrong order. It also causes 1376 // pre-CCS flights to be sent twice. (Post-CCS flights consist of 1377 // Finished and will trigger a spurious retransmit.) 1378 ReorderHandshakeFragments bool 1379 1380 // MixCompleteMessageWithFragments, if true, causes handshake 1381 // messages in DTLS to redundantly both fragment the message 1382 // and include a copy of the full one. 1383 MixCompleteMessageWithFragments bool 1384 1385 // SendInvalidRecordType, if true, causes a record with an invalid 1386 // content type to be sent immediately following the handshake. 1387 SendInvalidRecordType bool 1388 1389 // SendWrongMessageType, if non-zero, causes messages of the specified 1390 // type to be sent with the wrong value. 1391 SendWrongMessageType byte 1392 1393 // SendTrailingMessageData, if non-zero, causes messages of the 1394 // specified type to be sent with trailing data. 1395 SendTrailingMessageData byte 1396 1397 // SplitFragments, if non-zero, causes the handshake fragments in DTLS 1398 // to be split across two records. The value of |SplitFragments| is the 1399 // number of bytes in the first fragment. 1400 SplitFragments int 1401 1402 // SendEmptyFragments, if true, causes handshakes to include empty 1403 // fragments in DTLS. 1404 SendEmptyFragments bool 1405 1406 // SendSplitAlert, if true, causes an alert to be sent with the header 1407 // and record body split across multiple packets. The peer should 1408 // discard these packets rather than process it. 1409 SendSplitAlert bool 1410 1411 // FailIfResumeOnRenego, if true, causes renegotiations to fail if the 1412 // client offers a resumption or the server accepts one. 1413 FailIfResumeOnRenego bool 1414 1415 // IgnorePeerCipherPreferences, if true, causes the peer's cipher 1416 // preferences to be ignored. 1417 IgnorePeerCipherPreferences bool 1418 1419 // IgnorePeerSignatureAlgorithmPreferences, if true, causes the peer's 1420 // signature algorithm preferences to be ignored. 1421 IgnorePeerSignatureAlgorithmPreferences bool 1422 1423 // IgnorePeerCurvePreferences, if true, causes the peer's curve 1424 // preferences to be ignored. 1425 IgnorePeerCurvePreferences bool 1426 1427 // BadFinished, if true, causes the Finished hash to be broken. 1428 BadFinished bool 1429 1430 // PackHandshakeFragments, if true, causes handshake fragments in DTLS 1431 // to be packed into individual handshake records, up to the specified 1432 // record size. 1433 PackHandshakeFragments int 1434 1435 // PackHandshakeRecords, if non-zero, causes handshake and 1436 // ChangeCipherSpec records in DTLS to be packed into individual 1437 // packets, up to the specified packet size. 1438 PackHandshakeRecords int 1439 1440 // PackAppDataWithHandshake, if true, extends PackHandshakeRecords to 1441 // additionally include the first application data record sent after the 1442 // final Finished message in a handshake. (If the final Finished message 1443 // is sent by the peer, this option has no effect.) This requires that 1444 // the runner rather than shim speak first in a given test. 1445 PackAppDataWithHandshake bool 1446 1447 // SplitAndPackAppData, if true, causes application data in DTLS to be 1448 // split into two records each and packed into one packet. 1449 SplitAndPackAppData bool 1450 1451 // PackHandshakeFlight, if true, causes each handshake flight in TLS to 1452 // be packed into records, up to the largest size record available. 1453 PackHandshakeFlight bool 1454 1455 // AdvertiseAllConfiguredCiphers, if true, causes the client to 1456 // advertise all configured cipher suite values. 1457 AdvertiseAllConfiguredCiphers bool 1458 1459 // EmptyCertificateList, if true, causes the server to send an empty 1460 // certificate list in the Certificate message. 1461 EmptyCertificateList bool 1462 1463 // ExpectNewTicket, if true, causes the client to abort if it does not 1464 // receive a new ticket. 1465 ExpectNewTicket bool 1466 1467 // RequireClientHelloSize, if not zero, is the required length in bytes 1468 // of the ClientHello /record/. This is checked by the server. 1469 RequireClientHelloSize int 1470 1471 // CustomExtension, if not empty, contains the contents of an extension 1472 // that will be added to client/server hellos. 1473 CustomExtension string 1474 1475 // CustomUnencryptedExtension, if not empty, contains the contents of 1476 // an extension that will be added to ServerHello in TLS 1.3. 1477 CustomUnencryptedExtension string 1478 1479 // ExpectedCustomExtension, if not nil, contains the expected contents 1480 // of a custom extension. 1481 ExpectedCustomExtension *string 1482 1483 // CustomTicketExtension, if not empty, contains the contents of an 1484 // extension what will be added to NewSessionTicket in TLS 1.3. 1485 CustomTicketExtension string 1486 1487 // CustomTicketExtension, if not empty, contains the contents of an 1488 // extension what will be added to HelloRetryRequest in TLS 1.3. 1489 CustomHelloRetryRequestExtension string 1490 1491 // NoCloseNotify, if true, causes the close_notify alert to be skipped 1492 // on connection shutdown. 1493 NoCloseNotify bool 1494 1495 // SendAlertOnShutdown, if non-zero, is the alert to send instead of 1496 // close_notify on shutdown. 1497 SendAlertOnShutdown alert 1498 1499 // ExpectCloseNotify, if true, requires a close_notify from the peer on 1500 // shutdown. Records from the peer received after close_notify is sent 1501 // are not discard. 1502 ExpectCloseNotify bool 1503 1504 // SendLargeRecords, if true, allows outgoing records to be sent 1505 // arbitrarily large. 1506 SendLargeRecords bool 1507 1508 // NegotiateALPNAndNPN, if true, causes the server to negotiate both 1509 // ALPN and NPN in the same connetion. 1510 NegotiateALPNAndNPN bool 1511 1512 // SendALPN, if non-empty, causes the server to send the specified 1513 // string in the ALPN extension regardless of the content or presence of 1514 // the client offer. 1515 SendALPN string 1516 1517 // SendUnencryptedALPN, if non-empty, causes the server to send the 1518 // specified string in a ServerHello ALPN extension in TLS 1.3. 1519 SendUnencryptedALPN string 1520 1521 // SendEmptySessionTicket, if true, causes the server to send an empty 1522 // session ticket. 1523 SendEmptySessionTicket bool 1524 1525 // SendPSKKeyExchangeModes, if not nil, determines the PSK key exchange 1526 // modes to send. If a non-nil empty slice, no extension will be sent. 1527 SendPSKKeyExchangeModes []byte 1528 1529 // ExpectNoNewSessionTicket, if true, means that the client will fail upon 1530 // receipt of a NewSessionTicket message. 1531 ExpectNoNewSessionTicket bool 1532 1533 // ExpectNoNonEmptyNewSessionTicket, if true, means that the client will 1534 // fail upon receipt of a NewSessionTicket message that was non-empty. In 1535 // TLS 1.3, this is the same as ExpectNoNewSessionTicket. In TLS 1.2, this 1536 // allows the server to commit to sending NewSessionTicket, but then decline 1537 // to send one. 1538 ExpectNoNonEmptyNewSessionTicket bool 1539 1540 // DuplicateTicketEarlyData causes an extra empty extension of early_data to 1541 // be sent in NewSessionTicket. 1542 DuplicateTicketEarlyData bool 1543 1544 // ExpectTicketEarlyData, if true, means that the client will fail upon 1545 // absence of the early_data extension. 1546 ExpectTicketEarlyData bool 1547 1548 // ExpectTicketAge, if non-zero, is the expected age of the ticket that the 1549 // server receives from the client. 1550 ExpectTicketAge time.Duration 1551 1552 // SendTicketAge, if non-zero, is the ticket age to be sent by the 1553 // client. 1554 SendTicketAge time.Duration 1555 1556 // SendHelloRequestBeforeEveryAppDataRecord, if true, causes a 1557 // HelloRequest handshake message to be sent before each application 1558 // data record. This only makes sense for a server. 1559 SendHelloRequestBeforeEveryAppDataRecord bool 1560 1561 // SendHelloRequestBeforeEveryHandshakeMessage, if true, causes a 1562 // HelloRequest handshake message to be sent before each handshake 1563 // message. This only makes sense for a server. 1564 SendHelloRequestBeforeEveryHandshakeMessage bool 1565 1566 // BadChangeCipherSpec, if not nil, is the body to be sent in 1567 // ChangeCipherSpec records instead of {1}. 1568 BadChangeCipherSpec []byte 1569 1570 // BadHelloRequest, if not nil, is what to send instead of a 1571 // HelloRequest. 1572 BadHelloRequest []byte 1573 1574 // RequireSessionTickets, if true, causes the client to require new 1575 // sessions use session tickets instead of session IDs. 1576 RequireSessionTickets bool 1577 1578 // RequireSessionIDs, if true, causes the client to require new sessions use 1579 // session IDs instead of session tickets. 1580 RequireSessionIDs bool 1581 1582 // NullAllCiphers, if true, causes every cipher to behave like the null 1583 // cipher. 1584 NullAllCiphers bool 1585 1586 // SendSCTListOnResume, if not nil, causes the server to send the 1587 // supplied SCT list in resumption handshakes. 1588 SendSCTListOnResume []byte 1589 1590 // SendSCTListOnRenegotiation, if not nil, causes the server to send the 1591 // supplied SCT list on renegotiation. 1592 SendSCTListOnRenegotiation []byte 1593 1594 // SendOCSPResponseOnResume, if not nil, causes the server to advertise 1595 // OCSP stapling in resumption handshakes and, if applicable, send the 1596 // supplied stapled response. 1597 SendOCSPResponseOnResume []byte 1598 1599 // SendOCSPResponseOnResume, if not nil, causes the server to send the 1600 // supplied OCSP response on renegotiation. 1601 SendOCSPResponseOnRenegotiation []byte 1602 1603 // SendExtensionOnCertificate, if not nil, causes the runner to send the 1604 // supplied bytes in the extensions on the Certificate message. 1605 SendExtensionOnCertificate []byte 1606 1607 // SendOCSPOnIntermediates, if not nil, causes the server to send the 1608 // supplied OCSP on intermediate certificates in the Certificate message. 1609 SendOCSPOnIntermediates []byte 1610 1611 // SendSCTOnIntermediates, if not nil, causes the server to send the 1612 // supplied SCT on intermediate certificates in the Certificate message. 1613 SendSCTOnIntermediates []byte 1614 1615 // SendDuplicateCertExtensions, if true, causes the server to send an extra 1616 // copy of the OCSP/SCT extensions in the Certificate message. 1617 SendDuplicateCertExtensions bool 1618 1619 // ExpectNoExtensionsOnIntermediate, if true, causes the client to 1620 // reject extensions on intermediate certificates. 1621 ExpectNoExtensionsOnIntermediate bool 1622 1623 // RecordPadding is the number of bytes of padding to add to each 1624 // encrypted record in TLS 1.3. 1625 RecordPadding int 1626 1627 // OmitRecordContents, if true, causes encrypted records in TLS 1.3 to 1628 // be missing their body and content type. Padding, if configured, is 1629 // still added. 1630 OmitRecordContents bool 1631 1632 // OuterRecordType, if non-zero, is the outer record type to use instead 1633 // of application data. 1634 OuterRecordType recordType 1635 1636 // SendSignatureAlgorithm, if non-zero, causes all signatures to be sent 1637 // with the given signature algorithm rather than the one negotiated. 1638 SendSignatureAlgorithm signatureAlgorithm 1639 1640 // SkipECDSACurveCheck, if true, causes all ECDSA curve checks to be 1641 // skipped. 1642 SkipECDSACurveCheck bool 1643 1644 // IgnoreSignatureVersionChecks, if true, causes all signature 1645 // algorithms to be enabled at all TLS versions. 1646 IgnoreSignatureVersionChecks bool 1647 1648 // NegotiateRenegotiationInfoAtAllVersions, if true, causes 1649 // Renegotiation Info to be negotiated at all versions. 1650 NegotiateRenegotiationInfoAtAllVersions bool 1651 1652 // NegotiateNPNAtAllVersions, if true, causes NPN to be negotiated at 1653 // all versions. 1654 NegotiateNPNAtAllVersions bool 1655 1656 // NegotiateEMSAtAllVersions, if true, causes EMS to be negotiated at 1657 // all versions. 1658 NegotiateEMSAtAllVersions bool 1659 1660 // AdvertiseTicketExtension, if true, causes the ticket extension to be 1661 // advertised in server extensions 1662 AdvertiseTicketExtension bool 1663 1664 // NegotiatePSKResumption, if true, causes the server to attempt pure PSK 1665 // resumption. 1666 NegotiatePSKResumption bool 1667 1668 // AlwaysSelectPSKIdentity, if true, causes the server in TLS 1.3 to 1669 // always acknowledge a session, regardless of one was offered. 1670 AlwaysSelectPSKIdentity bool 1671 1672 // SelectPSKIdentityOnResume, if non-zero, causes the server to select 1673 // the specified PSK identity index rather than the actual value. 1674 SelectPSKIdentityOnResume uint16 1675 1676 // ExtraPSKIdentity, if true, causes the client to send an extra PSK 1677 // identity. 1678 ExtraPSKIdentity bool 1679 1680 // MissingKeyShare, if true, causes the TLS 1.3 implementation to skip 1681 // sending a key_share extension and use the zero ECDHE secret 1682 // instead. 1683 MissingKeyShare bool 1684 1685 // SecondClientHelloMissingKeyShare, if true, causes the second TLS 1.3 1686 // ClientHello to skip sending a key_share extension and use the zero 1687 // ECDHE secret instead. 1688 SecondClientHelloMissingKeyShare bool 1689 1690 // MisinterpretHelloRetryRequestCurve, if non-zero, causes the TLS 1.3 1691 // client to pretend the server requested a HelloRetryRequest with the 1692 // given curve rather than the actual one. 1693 MisinterpretHelloRetryRequestCurve CurveID 1694 1695 // DuplicateKeyShares, if true, causes the TLS 1.3 client to send two 1696 // copies of each KeyShareEntry. 1697 DuplicateKeyShares bool 1698 1699 // SendEarlyAlert, if true, sends a fatal alert after the ClientHello. 1700 SendEarlyAlert bool 1701 1702 // SendFakeEarlyDataLength, if non-zero, is the amount of early data to 1703 // send after the ClientHello. 1704 SendFakeEarlyDataLength int 1705 1706 // SendStrayEarlyHandshake, if non-zero, causes the client to send a stray 1707 // handshake record before sending end of early data. 1708 SendStrayEarlyHandshake bool 1709 1710 // OmitEarlyDataExtension, if true, causes the early data extension to 1711 // be omitted in the ClientHello. 1712 OmitEarlyDataExtension bool 1713 1714 // SendEarlyDataOnSecondClientHello, if true, causes the TLS 1.3 client to 1715 // send early data after the second ClientHello. 1716 SendEarlyDataOnSecondClientHello bool 1717 1718 // InterleaveEarlyData, if true, causes the TLS 1.3 client to send early 1719 // data interleaved with the second ClientHello and the client Finished. 1720 InterleaveEarlyData bool 1721 1722 // SendEarlyData causes a TLS 1.3 client to send the provided data 1723 // in application data records immediately after the ClientHello, 1724 // provided that the client offers a TLS 1.3 session. It will do this 1725 // whether or not the server advertised early data for the ticket. 1726 SendEarlyData [][]byte 1727 1728 // ExpectEarlyDataAccepted causes a TLS 1.3 client to check that early data 1729 // was accepted by the server. 1730 ExpectEarlyDataAccepted bool 1731 1732 // AlwaysAcceptEarlyData causes a TLS 1.3 server to always accept early data 1733 // regardless of ALPN mismatch. 1734 AlwaysAcceptEarlyData bool 1735 1736 // AlwaysRejectEarlyData causes a TLS 1.3 server to always reject early data. 1737 AlwaysRejectEarlyData bool 1738 1739 // SendEarlyDataExtension, if true, causes a TLS 1.3 server to send the 1740 // early_data extension in EncryptedExtensions, independent of whether 1741 // it was accepted. 1742 SendEarlyDataExtension bool 1743 1744 // ExpectEarlyData causes a TLS 1.3 server to read application 1745 // data after the ClientHello (assuming the server is able to 1746 // derive the key under which the data is encrypted) before it 1747 // sends a ServerHello. It checks that the application data it 1748 // reads matches what is provided in ExpectEarlyData and errors if 1749 // the number of records or their content do not match. 1750 ExpectEarlyData [][]byte 1751 1752 // ExpectLateEarlyData causes a TLS 1.3 server to read application 1753 // data after the ServerFinished (assuming the server is able to 1754 // derive the key under which the data is encrypted) before it 1755 // sends the ClientFinished. It checks that the application data it 1756 // reads matches what is provided in ExpectLateEarlyData and errors if 1757 // the number of records or their content do not match. 1758 ExpectLateEarlyData [][]byte 1759 1760 // ExpectHalfRTTData causes a TLS 1.3 client, if 0-RTT was accepted, to 1761 // read application data after reading the server's Finished message and 1762 // before sending any subsequent handshake messages. It checks that the 1763 // application data it reads matches what is provided in 1764 // ExpectHalfRTTData and errors if the number of records or their 1765 // content do not match. 1766 ExpectHalfRTTData [][]byte 1767 1768 // EmptyEncryptedExtensions, if true, causes the TLS 1.3 server to 1769 // emit an empty EncryptedExtensions block. 1770 EmptyEncryptedExtensions bool 1771 1772 // EncryptedExtensionsWithKeyShare, if true, causes the TLS 1.3 server to 1773 // include the KeyShare extension in the EncryptedExtensions block. 1774 EncryptedExtensionsWithKeyShare bool 1775 1776 // AlwaysSendHelloRetryRequest, if true, causes a HelloRetryRequest to 1777 // be sent by the server, even if empty. 1778 AlwaysSendHelloRetryRequest bool 1779 1780 // SecondHelloRetryRequest, if true, causes the TLS 1.3 server to send 1781 // two HelloRetryRequests instead of one. 1782 SecondHelloRetryRequest bool 1783 1784 // SendHelloRetryRequestCurve, if non-zero, causes the server to send 1785 // the specified curve in a HelloRetryRequest, even if the client did 1786 // not offer key shares at all. 1787 SendHelloRetryRequestCurve CurveID 1788 1789 // SendHelloRetryRequestCipherSuite, if non-zero, causes the server to send 1790 // the specified cipher suite in a HelloRetryRequest. 1791 SendHelloRetryRequestCipherSuite uint16 1792 1793 // SendHelloRetryRequestCookie, if not nil, contains a cookie to be 1794 // sent by the server in HelloRetryRequest. 1795 SendHelloRetryRequestCookie []byte 1796 1797 // DuplicateHelloRetryRequestExtensions, if true, causes all 1798 // HelloRetryRequest extensions to be sent twice. 1799 DuplicateHelloRetryRequestExtensions bool 1800 1801 // SendServerHelloVersion, if non-zero, causes the server to send the 1802 // specified value in ServerHello version field. 1803 SendServerHelloVersion uint16 1804 1805 // SendServerSupportedVersionExtension, if non-zero, causes the server to send 1806 // the specified value in supported_versions extension in the ServerHello (but 1807 // not the HelloRetryRequest). 1808 SendServerSupportedVersionExtension uint16 1809 1810 // OmitServerSupportedVersionExtension, if true, causes the server to 1811 // omit the supported_versions extension in the ServerHello (but not the 1812 // HelloRetryRequest) 1813 OmitServerSupportedVersionExtension bool 1814 1815 // SkipHelloRetryRequest, if true, causes the TLS 1.3 server to not send 1816 // HelloRetryRequest. 1817 SkipHelloRetryRequest bool 1818 1819 // PackHelloRequestWithFinished, if true, causes the TLS server to send 1820 // HelloRequest in the same record as Finished. 1821 PackHelloRequestWithFinished bool 1822 1823 // ExpectMissingKeyShare, if true, causes the TLS server to fail the 1824 // connection if the selected curve appears in the client's initial 1825 // ClientHello. That is, it requires that a HelloRetryRequest be sent. 1826 ExpectMissingKeyShare bool 1827 1828 // SendExtraFinished, if true, causes an extra Finished message to be 1829 // sent. 1830 SendExtraFinished bool 1831 1832 // SendRequestContext, if not empty, is the request context to send in 1833 // a TLS 1.3 CertificateRequest. 1834 SendRequestContext []byte 1835 1836 // OmitCertificateRequestAlgorithms, if true, omits the signature_algorithm 1837 // extension in a TLS 1.3 CertificateRequest. 1838 OmitCertificateRequestAlgorithms bool 1839 1840 // SendCustomCertificateRequest, if non-zero, send an additional custom 1841 // extension in a TLS 1.3 CertificateRequest. 1842 SendCustomCertificateRequest uint16 1843 1844 // AlwaysSendCertificateRequest, if true, causes the server to send 1845 // CertificateRequest in TLS 1.3, even in handshakes where it is not 1846 // allowed, such as resumption. 1847 AlwaysSendCertificateRequest bool 1848 1849 // AlwaysSendCertificate, if true, causes the server to send Certificate in 1850 // TLS 1.3, even in handshakes where it is not allowed, such as resumption. 1851 AlwaysSendCertificate bool 1852 1853 // UseCertificateCredential, if not nil, is the credential to use as a 1854 // server for TLS 1.3 Certificate and CertificateVerify messages. This may 1855 // be used with AlwaysSendCertificate to authenticate with a certificate 1856 // alongside some non-certificate credential. 1857 UseCertificateCredential *Credential 1858 1859 // SendSNIWarningAlert, if true, causes the server to send an 1860 // unrecognized_name alert before the ServerHello. 1861 SendSNIWarningAlert bool 1862 1863 // SendCompressionMethods, if not nil, is the compression method list to 1864 // send in the ClientHello. 1865 SendCompressionMethods []byte 1866 1867 // SendCompressionMethod is the compression method to send in the 1868 // ServerHello. 1869 SendCompressionMethod byte 1870 1871 // AlwaysSendPreSharedKeyIdentityHint, if true, causes the server to 1872 // always send a ServerKeyExchange for PSK ciphers, even if the identity 1873 // hint is empty. 1874 AlwaysSendPreSharedKeyIdentityHint bool 1875 1876 // TrailingKeyShareData, if true, causes the client key share list to 1877 // include a trailing byte. 1878 TrailingKeyShareData bool 1879 1880 // InvalidChannelIDSignature, if true, causes the client to generate an 1881 // invalid Channel ID signature. 1882 InvalidChannelIDSignature bool 1883 1884 // AlwaysNegotiateChannelID, if true, causes the server to negotiate Channel 1885 // ID, even whenn the client does not offer it. 1886 AlwaysNegotiateChannelID bool 1887 1888 // ExpectGREASE, if true, causes messages without GREASE values to be 1889 // rejected. See RFC 8701. 1890 ExpectGREASE bool 1891 1892 // OmitPSKsOnSecondClientHello, if true, causes the client to omit the 1893 // PSK extension on the second ClientHello. 1894 OmitPSKsOnSecondClientHello bool 1895 1896 // OnlyCorruptSecondPSKBinder, if true, causes the options below to 1897 // only apply to the second PSK binder. 1898 OnlyCorruptSecondPSKBinder bool 1899 1900 // SendShortPSKBinder, if true, causes the client to send a PSK binder 1901 // that is one byte shorter than it should be. 1902 SendShortPSKBinder bool 1903 1904 // SendInvalidPSKBinder, if true, causes the client to send an invalid 1905 // PSK binder. 1906 SendInvalidPSKBinder bool 1907 1908 // SendNoPSKBinder, if true, causes the client to send no PSK binders. 1909 SendNoPSKBinder bool 1910 1911 // SendExtraPSKBinder, if true, causes the client to send an extra PSK 1912 // binder. 1913 SendExtraPSKBinder bool 1914 1915 // PSKBinderFirst, if true, causes the client to send the PSK Binder 1916 // extension as the first extension instead of the last extension. 1917 PSKBinderFirst bool 1918 1919 // NoOCSPStapling, if true, causes the client to not request OCSP 1920 // stapling. 1921 NoOCSPStapling bool 1922 1923 // NoSignedCertificateTimestamps, if true, causes the client to not 1924 // request signed certificate timestamps. 1925 NoSignedCertificateTimestamps bool 1926 1927 // ExpectPeerRequestedTrustAnchors, if not nil, causes the server to 1928 // require the client to request the specified trust anchors in the 1929 // ClientHello. 1930 ExpectPeerRequestedTrustAnchors [][]byte 1931 1932 // ExpectPeerAvailableTrustAnchors, if not nil, causes the client to 1933 // require the server to list the specified trust anchors as available 1934 // in EncryptedExtensions. 1935 ExpectPeerAvailableTrustAnchors [][]byte 1936 1937 // ExpectPeerMatchTrustAnchor, if not nil, causes the client to require the 1938 // server to acknowledge, or not acknowledge the trust_anchors extension in 1939 // Certificate. 1940 ExpectPeerMatchTrustAnchor *bool 1941 1942 // AlwaysMatchTrustAnchorID, if true, causes the server to always indicate 1943 // a trust anchor ID match in the Certificate message. 1944 AlwaysMatchTrustAnchorID bool 1945 1946 // SendTrustAnchorWrongCertificate sends a trust anchor ID extension 1947 // on the second certificate in the Certificate message. 1948 SendTrustAnchorWrongCertificate bool 1949 1950 // SendNonEmptyTrustAnchorMatch sends a non-empty trust anchor ID 1951 // extension to indicate a match. 1952 SendNonEmptyTrustAnchorMatch bool 1953 1954 // AlwaysSendAvailableTrustAnchors, if true, causese the server to always 1955 // send available trust anchors in EncryptedExtensions, even if unsolicited. 1956 AlwaysSendAvailableTrustAnchors bool 1957 1958 // SendSupportedPointFormats, if not nil, is the list of supported point 1959 // formats to send in ClientHello or ServerHello. If set to a non-nil 1960 // empty slice, no extension will be sent. 1961 SendSupportedPointFormats []byte 1962 1963 // SendServerSupportedCurves, if true, causes the server to send its 1964 // supported curves list in the ServerHello (TLS 1.2) or 1965 // EncryptedExtensions (TLS 1.3) message. This is invalid in TLS 1.2 and 1966 // valid in TLS 1.3. 1967 SendServerSupportedCurves bool 1968 1969 // MaxReceivePlaintext, if non-zero, is the maximum plaintext record 1970 // length accepted from the peer. 1971 MaxReceivePlaintext int 1972 1973 // ExpectPackedEncryptedHandshake, if non-zero, requires that the peer maximally 1974 // pack their encrypted handshake messages, fitting at most the specified number 1975 // of bytes per record. In TLS, the limit counts plaintext bytes. In DTLS, it 1976 // counts packet size and checks both that fragments are packed into records and 1977 // records are packed into packets. 1978 ExpectPackedEncryptedHandshake int 1979 1980 // SendTicketLifetime, if non-zero, is the ticket lifetime to send in 1981 // NewSessionTicket messages. 1982 SendTicketLifetime time.Duration 1983 1984 // SendServerNameAck, if true, causes the server to acknowledge the SNI 1985 // extension. 1986 SendServerNameAck bool 1987 1988 // ExpectCertificateReqNames, if not nil, contains the list of X.509 1989 // names that must be sent in a CertificateRequest from the server. 1990 ExpectCertificateReqNames [][]byte 1991 1992 // RenegotiationCertificate, if not nil, is the certificate to use on 1993 // renegotiation handshakes. 1994 RenegotiationCertificate *Credential 1995 1996 // SigningAlgorithmForLegacyVersions, if non-zero, is the signature algorithm 1997 // to use when signing in TLS 1.1 and earlier where algorithms are not 1998 // negotiated. 1999 SigningAlgorithmForLegacyVersions signatureAlgorithm 2000 2001 // AlwaysSignAsLegacyVersion, if true, causes all TLS versions to sign as if 2002 // they were TLS 1.1 and earlier. This can be paired with 2003 // SendSignatureAlgorithm to send a given signature algorithm enum. 2004 AlwaysSignAsLegacyVersion bool 2005 2006 // RejectUnsolicitedKeyUpdate, if true, causes all unsolicited 2007 // KeyUpdates from the peer to be rejected. 2008 RejectUnsolicitedKeyUpdate bool 2009 2010 // OmitExtensions, if true, causes the extensions field in ClientHello 2011 // and ServerHello messages to be omitted. 2012 OmitExtensions bool 2013 2014 // EmptyExtensions, if true, causes the extensions field in ClientHello 2015 // and ServerHello messages to be present, but empty. 2016 EmptyExtensions bool 2017 2018 // ExpectOmitExtensions, if true, causes the client to reject 2019 // ServerHello messages that do not omit extensions. 2020 ExpectOmitExtensions bool 2021 2022 // ExpectRecordSplitting, if true, causes application records to only be 2023 // accepted if they follow a 1/n-1 record split. 2024 ExpectRecordSplitting bool 2025 2026 // PadClientHello, if non-zero, pads the ClientHello to a multiple of 2027 // that many bytes. 2028 PadClientHello int 2029 2030 // SendTLS13DowngradeRandom, if true, causes the server to send the 2031 // TLS 1.3 anti-downgrade signal. 2032 SendTLS13DowngradeRandom bool 2033 2034 // IgnoreTLS13DowngradeRandom, if true, causes the client to ignore the 2035 // TLS 1.3 anti-downgrade signal. 2036 IgnoreTLS13DowngradeRandom bool 2037 2038 // SendCompressedCoordinates, if true, causes ECDH key shares over NIST 2039 // curves to use compressed coordinates. 2040 SendCompressedCoordinates bool 2041 2042 // SetX25519HighBit, if true, causes X25519 key shares to set their 2043 // high-order bit. 2044 SetX25519HighBit bool 2045 2046 // LowOrderX25519Point, if true, causes X25519 key shares to be a low 2047 // order point. 2048 LowOrderX25519Point bool 2049 2050 // MLKEMEncapKeyNotReduced, if true, causes the ML-KEM encapsulation key 2051 // to not be fully reduced. 2052 MLKEMEncapKeyNotReduced bool 2053 2054 // DuplicateCompressedCertAlgs, if true, causes two, equal, certificate 2055 // compression algorithm IDs to be sent. 2056 DuplicateCompressedCertAlgs bool 2057 2058 // ExpectedCompressedCert specifies the compression algorithm ID that must be 2059 // used on this connection, or zero if there are no special requirements. 2060 ExpectedCompressedCert uint16 2061 2062 // ExpectUncompressedCert, if true, specifies that certificate compression 2063 // should not be used on this connection. 2064 ExpectUncompressedCert bool 2065 2066 // SendCertCompressionAlgID, if not zero, sets the algorithm ID that will be 2067 // sent in the compressed certificate message. 2068 SendCertCompressionAlgID uint16 2069 2070 // SendCertUncompressedLength, if not zero, sets the uncompressed length that 2071 // will be sent in the compressed certificate message. 2072 SendCertUncompressedLength uint32 2073 2074 // SendClientHelloWithFixes, if not nil, sends the specified byte string 2075 // instead of the ClientHello. This string is incorporated into the 2076 // transcript as if it were the real ClientHello, but the handshake will 2077 // otherwise behave as if this was not sent in terms of what ciphers it 2078 // will accept, etc. 2079 // 2080 // The input is modified to match key share entries. DefaultCurves must 2081 // be configured to match. The random and session ID fields are 2082 // extracted from the ClientHello. 2083 SendClientHelloWithFixes []byte 2084 2085 // SendJDK11DowngradeRandom, if true, causes the server to send the JDK 2086 // 11 downgrade signal. 2087 SendJDK11DowngradeRandom bool 2088 2089 // ExpectJDK11DowngradeRandom is whether the client should expect the 2090 // server to send the JDK 11 downgrade signal. 2091 ExpectJDK11DowngradeRandom bool 2092 2093 // FailIfHelloRetryRequested causes a handshake failure if a server requests a 2094 // hello retry. 2095 FailIfHelloRetryRequested bool 2096 2097 // FailIfPostQuantumOffered will cause a server to reject a ClientHello if 2098 // post-quantum curves are supported. 2099 FailIfPostQuantumOffered bool 2100 2101 // ExpectKeyShares, if not nil, lists (in order) the curves that a ClientHello 2102 // should have key shares for. 2103 ExpectedKeyShares []CurveID 2104 2105 // CompatModeWithQUIC, if true, enables TLS 1.3 compatibility mode 2106 // when running over QUIC. 2107 CompatModeWithQUIC bool 2108 2109 // DTLS13EchoSessionID, if true, has DTLS 1.3 servers echo the client's 2110 // session ID in the ServerHello. 2111 DTLS13EchoSessionID bool 2112 2113 // DTLSUsePlaintextRecord header, if true, has DTLS 1.3 connections to use 2114 // the DTLS 1.2 record header once the handshake completes. The bug is not 2115 // activated during the handshake so that the handshake can complete first. 2116 DTLSUsePlaintextRecordHeader bool 2117 2118 // DTLS13RecordHeaderSetCIDBit, if true, sets the Connection ID bit in 2119 // the DTLS 1.3 record header. 2120 DTLS13RecordHeaderSetCIDBit bool 2121 2122 // EncryptSessionTicketKey, if non-nil, is the ticket key to use when 2123 // encrypting tickets. 2124 EncryptSessionTicketKey *[32]byte 2125 2126 // OmitPublicName omits the server name extension from ClientHelloOuter. 2127 OmitPublicName bool 2128 2129 // AllowEpochOverflow allows DTLS epoch numbers to wrap around. 2130 AllowEpochOverflow bool 2131 2132 // SendPAKEInHelloRetryRequest causes the server to send a HelloRetryRequest 2133 // message containing a PAKE extension. 2134 SendPAKEInHelloRetryRequest bool 2135 2136 // UnsolicitedPAKE, if non-zero, causes a ServerHello to contain a PAKE 2137 // response of the specified algorithm, even if the client didn't request it. 2138 UnsolicitedPAKE uint16 2139 2140 // OfferExtraPAKEs, if not empty, is a list of additional PAKE algorithms to 2141 // offer as a client. They cannot be negotiated and should be used in tests 2142 // where the server is expected to ignore them. 2143 OfferExtraPAKEs []uint16 2144 2145 // OfferExtraPAKEClientID and OfferExtraPAKEServerID are the PAKE client and 2146 // server IDs to send with OfferExtraPAKEs. These may be left unset if 2147 // configured with a real PAKE credential. 2148 OfferExtraPAKEClientID []byte 2149 OfferExtraPAKEServerID []byte 2150 2151 // TruncatePAKEMessage, if true, causes PAKE messages to be truncated. 2152 TruncatePAKEMessage bool 2153 2154 // CheckClientHello is called on the initial ClientHello received from the 2155 // peer, to implement extra checks. 2156 CheckClientHello func(*clientHelloMsg) error 2157 2158 // SendTicketFlags contains a list of flags, represented by bit index, that 2159 // the server will send in TLS 1.3 NewSessionTicket. 2160 SendTicketFlags []uint 2161 2162 // AlwaysSendTicketFlags causes the server to send the flags extension in 2163 // TLS 1.3 NewSessionTicket even if empty. 2164 AlwaysSendTicketFlags bool 2165 2166 // TicketFlagPadding is the number of extra bytes of padding (giving a 2167 // non-minimal encoding) to include in the flags extension in TLS 1.3 2168 // NewSessionTicket. 2169 TicketFlagPadding int 2170 2171 // ExpectResumptionAcrossNames, if not nil, causes the client to require all 2172 // NewSessionTicket messages to have or not have the resumption_across_names 2173 // flag set. 2174 ExpectResumptionAcrossNames *bool 2175} 2176 2177func (c *Config) serverInit() { 2178 if c.SessionTicketsDisabled { 2179 return 2180 } 2181 2182 // If the key has already been set then we have nothing to do. 2183 for _, b := range c.SessionTicketKey { 2184 if b != 0 { 2185 return 2186 } 2187 } 2188 2189 if _, err := io.ReadFull(c.rand(), c.SessionTicketKey[:]); err != nil { 2190 c.SessionTicketsDisabled = true 2191 } 2192} 2193 2194func (c *Config) rand() io.Reader { 2195 r := c.Rand 2196 if r == nil { 2197 return rand.Reader 2198 } 2199 return r 2200} 2201 2202func (c *Config) time() time.Time { 2203 t := c.Time 2204 if t == nil { 2205 t = time.Now 2206 } 2207 return t() 2208} 2209 2210func (c *Config) cipherSuites() []uint16 { 2211 s := c.CipherSuites 2212 if s == nil { 2213 s = defaultCipherSuites() 2214 } 2215 return s 2216} 2217 2218func (c *Config) minVersion(isDTLS bool) uint16 { 2219 ret := uint16(minVersion) 2220 if c != nil && c.MinVersion != 0 { 2221 ret = c.MinVersion 2222 } 2223 if isDTLS { 2224 // The lowest version of DTLS is 1.0. There is no DSSL 3.0. 2225 if ret < VersionTLS10 { 2226 return VersionTLS10 2227 } 2228 // There is no such thing as DTLS 1.1. 2229 if ret == VersionTLS11 { 2230 return VersionTLS12 2231 } 2232 } 2233 return ret 2234} 2235 2236func (c *Config) maxVersion(isDTLS bool) uint16 { 2237 ret := uint16(maxVersion) 2238 if c != nil && c.MaxVersion != 0 { 2239 ret = c.MaxVersion 2240 } 2241 if isDTLS { 2242 // There is no such thing as DTLS 1.1. 2243 if ret == VersionTLS11 { 2244 return VersionTLS10 2245 } 2246 } 2247 return ret 2248} 2249 2250var defaultCurvePreferences = []CurveID{CurveX25519MLKEM768, CurveX25519Kyber768, CurveMLKEM1024, CurveX25519, CurveP256, CurveP384, CurveP521} 2251 2252func (c *Config) curvePreferences() []CurveID { 2253 if c == nil || len(c.CurvePreferences) == 0 { 2254 return defaultCurvePreferences 2255 } 2256 return c.CurvePreferences 2257} 2258 2259func (c *Config) defaultCurves() map[CurveID]bool { 2260 defaultCurves := make(map[CurveID]bool) 2261 curves := c.DefaultCurves 2262 if c == nil || c.DefaultCurves == nil { 2263 curves = c.curvePreferences() 2264 } 2265 for _, curveID := range curves { 2266 defaultCurves[curveID] = true 2267 } 2268 return defaultCurves 2269} 2270 2271var defaultECHCipherSuitePreferences = []HPKECipherSuite{ 2272 {KDF: hpke.HKDFSHA256, AEAD: hpke.AES128GCM}, 2273 {KDF: hpke.HKDFSHA256, AEAD: hpke.AES256GCM}, 2274 {KDF: hpke.HKDFSHA256, AEAD: hpke.ChaCha20Poly1305}, 2275} 2276 2277func (c *Config) echCipherSuitePreferences() []HPKECipherSuite { 2278 if c == nil || len(c.ECHCipherSuites) == 0 { 2279 return defaultECHCipherSuitePreferences 2280 } 2281 return c.ECHCipherSuites 2282} 2283 2284func wireToVersion(vers uint16, isDTLS bool) (uint16, bool) { 2285 if isDTLS { 2286 switch vers { 2287 case VersionDTLS13: 2288 return VersionTLS13, true 2289 case VersionDTLS12: 2290 return VersionTLS12, true 2291 case VersionDTLS10: 2292 return VersionTLS10, true 2293 } 2294 } else { 2295 switch vers { 2296 case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12, VersionTLS13: 2297 return vers, true 2298 } 2299 } 2300 2301 return 0, false 2302} 2303 2304// isSupportedVersion checks if the specified wire version is acceptable. If so, 2305// it returns true and the corresponding protocol version. Otherwise, it returns 2306// false. 2307func (c *Config) isSupportedVersion(wireVers uint16, isDTLS bool) (uint16, bool) { 2308 vers, ok := wireToVersion(wireVers, isDTLS) 2309 if !ok || c.minVersion(isDTLS) > vers || vers > c.maxVersion(isDTLS) { 2310 return 0, false 2311 } 2312 return vers, true 2313} 2314 2315func (c *Config) supportedVersions(isDTLS, requireTLS13 bool) []uint16 { 2316 versions := allTLSWireVersions 2317 if isDTLS { 2318 versions = allDTLSWireVersions 2319 } 2320 var ret []uint16 2321 for _, wireVers := range versions { 2322 vers, ok := c.isSupportedVersion(wireVers, isDTLS) 2323 if !ok { 2324 continue 2325 } 2326 if requireTLS13 && vers < VersionTLS13 { 2327 continue 2328 } 2329 ret = append(ret, wireVers) 2330 } 2331 return ret 2332} 2333 2334func (c *Config) verifySignatureAlgorithms() []signatureAlgorithm { 2335 if c != nil && c.VerifySignatureAlgorithms != nil { 2336 return c.VerifySignatureAlgorithms 2337 } 2338 return supportedSignatureAlgorithms 2339} 2340 2341type CredentialType int 2342 2343const ( 2344 CredentialTypeX509 CredentialType = iota 2345 CredentialTypeDelegated 2346 CredentialTypeSPAKE2PlusV1 2347) 2348 2349// A Credential is a certificate chain and private key that a TLS endpoint may 2350// use to authenticate. 2351type Credential struct { 2352 Type CredentialType 2353 // Certificate is a chain of one or more certificates, leaf first. 2354 Certificate [][]byte 2355 // RootCertificate is the certificate that issued this chain. 2356 RootCertificate []byte 2357 PrivateKey crypto.PrivateKey // supported types: *rsa.PrivateKey, *ecdsa.PrivateKey 2358 // OCSPStaple contains an optional OCSP response which will be served 2359 // to clients that request it. 2360 OCSPStaple []byte 2361 // SignedCertificateTimestampList contains an optional encoded 2362 // SignedCertificateTimestampList structure which will be 2363 // served to clients that request it. 2364 SignedCertificateTimestampList []byte 2365 // SignatureAlgorithms, if not nil, overrides the default set of 2366 // supported signature algorithms to sign with. 2367 SignatureAlgorithms []signatureAlgorithm 2368 // DelegatedCredential is the delegated credential to use 2369 // with the certificate. 2370 DelegatedCredential []byte 2371 // ChainPath is the path to the temporary on disk copy of the certificate 2372 // chain. 2373 ChainPath string 2374 // KeyPath is the path to the temporary on disk copy of the key. 2375 KeyPath string 2376 // RootPath is the path to the temporary on disk copy of the root of the 2377 // certificate chain. If the chain only contains one certificate ChainPath 2378 // and RootPath will be the same. 2379 RootPath string 2380 // SignSignatureAlgorithms, if not nil, overrides the default set of 2381 // supported signature algorithms to sign with. 2382 SignSignatureAlgorithms []signatureAlgorithm 2383 // MustMatchIssuer, if set, causes the shim to only consider this 2384 // credential when the issuer matches a peer-requested CA. 2385 MustMatchIssuer bool 2386 // The following fields are used for PAKE credentials. For simplicity, 2387 // we specify the password directly and expect the shim and runner to 2388 // compute the client- and server-specific halves as needed. 2389 PAKEContext []byte 2390 PAKEClientID []byte 2391 PAKEServerID []byte 2392 PAKEPassword []byte 2393 // WrongPAKERole, if set, causes the shim to be configured with a 2394 // credential of the wrong role. 2395 WrongPAKERole bool 2396 // OverridePAKECodepoint, if non-zero, causes the runner to send the 2397 // specified value instead of the actual PAKE codepoint. 2398 OverridePAKECodepoint uint16 2399 // TrustAnchorID, if not empty, is the trust anchor ID for the issuer 2400 // of the certificate chain. 2401 TrustAnchorID []byte 2402} 2403 2404func (c *Credential) WithSignatureAlgorithms(sigAlgs ...signatureAlgorithm) *Credential { 2405 ret := *c 2406 ret.SignatureAlgorithms = sigAlgs 2407 return &ret 2408} 2409 2410func (c *Credential) WithOCSP(ocsp []byte) *Credential { 2411 ret := *c 2412 ret.OCSPStaple = ocsp 2413 return &ret 2414} 2415 2416func (c *Credential) WithSCTList(sctList []byte) *Credential { 2417 ret := *c 2418 ret.SignedCertificateTimestampList = sctList 2419 return &ret 2420} 2421 2422func (c *Credential) WithMustMatchIssuer(mustMatch bool) *Credential { 2423 ret := *c 2424 ret.MustMatchIssuer = mustMatch 2425 return &ret 2426} 2427 2428func (c *Credential) signatureAlgorithms() []signatureAlgorithm { 2429 if c != nil && c.SignatureAlgorithms != nil { 2430 return c.SignatureAlgorithms 2431 } 2432 return supportedSignatureAlgorithms 2433} 2434 2435func (c *Credential) WithTrustAnchorID(id []byte) *Credential { 2436 ret := *c 2437 ret.TrustAnchorID = id 2438 ret.MustMatchIssuer = true 2439 return &ret 2440} 2441 2442type handshakeMessage interface { 2443 marshal() []byte 2444 unmarshal([]byte) bool 2445} 2446 2447// lruSessionCache is a client or server session cache implementation 2448// that uses an LRU caching strategy. 2449type lruSessionCache struct { 2450 sync.Mutex 2451 2452 m map[string]*list.Element 2453 q *list.List 2454 capacity int 2455} 2456 2457type lruSessionCacheEntry struct { 2458 sessionKey string 2459 state any 2460} 2461 2462// Put adds the provided (sessionKey, cs) pair to the cache. 2463func (c *lruSessionCache) Put(sessionKey string, cs any) { 2464 c.Lock() 2465 defer c.Unlock() 2466 2467 if elem, ok := c.m[sessionKey]; ok { 2468 entry := elem.Value.(*lruSessionCacheEntry) 2469 entry.state = cs 2470 c.q.MoveToFront(elem) 2471 return 2472 } 2473 2474 if c.q.Len() < c.capacity { 2475 entry := &lruSessionCacheEntry{sessionKey, cs} 2476 c.m[sessionKey] = c.q.PushFront(entry) 2477 return 2478 } 2479 2480 elem := c.q.Back() 2481 entry := elem.Value.(*lruSessionCacheEntry) 2482 delete(c.m, entry.sessionKey) 2483 entry.sessionKey = sessionKey 2484 entry.state = cs 2485 c.q.MoveToFront(elem) 2486 c.m[sessionKey] = elem 2487} 2488 2489// Get returns the value associated with a given key. It returns (nil, 2490// false) if no value is found. 2491func (c *lruSessionCache) Get(sessionKey string) (any, bool) { 2492 c.Lock() 2493 defer c.Unlock() 2494 2495 if elem, ok := c.m[sessionKey]; ok { 2496 c.q.MoveToFront(elem) 2497 return elem.Value.(*lruSessionCacheEntry).state, true 2498 } 2499 return nil, false 2500} 2501 2502// lruClientSessionCache is a ClientSessionCache implementation that 2503// uses an LRU caching strategy. 2504type lruClientSessionCache struct { 2505 lruSessionCache 2506} 2507 2508func (c *lruClientSessionCache) Put(sessionKey string, cs *ClientSessionState) { 2509 c.lruSessionCache.Put(sessionKey, cs) 2510} 2511 2512func (c *lruClientSessionCache) Get(sessionKey string) (*ClientSessionState, bool) { 2513 cs, ok := c.lruSessionCache.Get(sessionKey) 2514 if !ok { 2515 return nil, false 2516 } 2517 return cs.(*ClientSessionState), true 2518} 2519 2520// lruServerSessionCache is a ServerSessionCache implementation that 2521// uses an LRU caching strategy. 2522type lruServerSessionCache struct { 2523 lruSessionCache 2524} 2525 2526func (c *lruServerSessionCache) Put(sessionID string, session *sessionState) { 2527 c.lruSessionCache.Put(sessionID, session) 2528} 2529 2530func (c *lruServerSessionCache) Get(sessionID string) (*sessionState, bool) { 2531 cs, ok := c.lruSessionCache.Get(sessionID) 2532 if !ok { 2533 return nil, false 2534 } 2535 return cs.(*sessionState), true 2536} 2537 2538// NewLRUClientSessionCache returns a ClientSessionCache with the given 2539// capacity that uses an LRU strategy. If capacity is < 1, a default capacity 2540// is used instead. 2541func NewLRUClientSessionCache(capacity int) ClientSessionCache { 2542 const defaultSessionCacheCapacity = 64 2543 2544 if capacity < 1 { 2545 capacity = defaultSessionCacheCapacity 2546 } 2547 return &lruClientSessionCache{ 2548 lruSessionCache{ 2549 m: make(map[string]*list.Element), 2550 q: list.New(), 2551 capacity: capacity, 2552 }, 2553 } 2554} 2555 2556// NewLRUServerSessionCache returns a ServerSessionCache with the given 2557// capacity that uses an LRU strategy. If capacity is < 1, a default capacity 2558// is used instead. 2559func NewLRUServerSessionCache(capacity int) ServerSessionCache { 2560 const defaultSessionCacheCapacity = 64 2561 2562 if capacity < 1 { 2563 capacity = defaultSessionCacheCapacity 2564 } 2565 return &lruServerSessionCache{ 2566 lruSessionCache{ 2567 m: make(map[string]*list.Element), 2568 q: list.New(), 2569 capacity: capacity, 2570 }, 2571 } 2572} 2573 2574// TODO(jsing): Make these available to both crypto/x509 and crypto/tls. 2575type dsaSignature struct { 2576 R, S *big.Int 2577} 2578 2579type ecdsaSignature dsaSignature 2580 2581var emptyConfig Config 2582 2583func defaultConfig() *Config { 2584 return &emptyConfig 2585} 2586 2587var ( 2588 once sync.Once 2589 varDefaultCipherSuites []uint16 2590) 2591 2592func defaultCipherSuites() []uint16 { 2593 once.Do(initDefaultCipherSuites) 2594 return varDefaultCipherSuites 2595} 2596 2597func initDefaultCipherSuites() { 2598 for _, suite := range cipherSuites { 2599 if suite.flags&suitePSK == 0 { 2600 varDefaultCipherSuites = append(varDefaultCipherSuites, suite.id) 2601 } 2602 } 2603} 2604 2605func unexpectedMessageError(wanted, got any) error { 2606 return fmt.Errorf("tls: received unexpected handshake message of type %T when waiting for %T", got, wanted) 2607} 2608 2609var ( 2610 // See RFC 8446, section 4.1.3. 2611 downgradeTLS13 = []byte{0x44, 0x4f, 0x57, 0x4e, 0x47, 0x52, 0x44, 0x01} 2612 downgradeTLS12 = []byte{0x44, 0x4f, 0x57, 0x4e, 0x47, 0x52, 0x44, 0x00} 2613 2614 // This is a non-standard randomly-generated value. 2615 downgradeJDK11 = []byte{0xed, 0xbf, 0xb4, 0xa8, 0xc2, 0x47, 0x10, 0xff} 2616) 2617 2618func containsGREASE(values []uint16) bool { 2619 for _, v := range values { 2620 if isGREASEValue(v) { 2621 return true 2622 } 2623 } 2624 return false 2625} 2626 2627func isAllZero(v []byte) bool { 2628 for _, b := range v { 2629 if b != 0 { 2630 return false 2631 } 2632 } 2633 return true 2634} 2635 2636// https://github.com/golang/go/issues/45624 2637func ptrTo[T any](t T) *T { return &t } 2638