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