| 6 |
| 7 | import ( |
| 8 | "container/list" |
| 9 | "crypto" |
| 10 | "crypto/ecdsa" |
| 11 | "crypto/rand" |
| 12 | "crypto/x509" |
| 13 | "errors" |
| 14 | "fmt" |
| 15 | "io" |
| 16 | "math/big" |
| 17 | "strings" |
| 18 | "sync" |
| 19 | "time" |
| 20 | ) |
| 21 |
| 22 | const ( |
| 23 | VersionSSL30 = 0x0300 |
| 24 | VersionTLS10 = 0x0301 |
| 25 | VersionTLS11 = 0x0302 |
| 26 | VersionTLS12 = 0x0303 |
| 27 | VersionTLS13 = 0x0304 |
| 28 | ) |
| 29 |
| 30 | const ( |
| 31 | VersionDTLS10 = 0xfeff |
| 32 | VersionDTLS12 = 0xfefd |
| 33 | ) |
| 34 |
| 35 | var allTLSWireVersions = []uint16{ |
| 36 | VersionTLS13, |
| 37 | VersionTLS12, |
| 38 | VersionTLS11, |
| 39 | VersionTLS10, |
| 40 | VersionSSL30, |
| 41 | } |
| 42 |
| 43 | var allDTLSWireVersions = []uint16{ |
| 44 | VersionDTLS12, |
| 45 | VersionDTLS10, |
| 46 | } |
| 47 |
| 48 | const ( |
| 49 | maxPlaintext = 16384 // maximum plaintext payload length |
| 50 | maxCiphertext = 16384 + 2048 // maximum ciphertext payload length |
| 51 | tlsRecordHeaderLen = 5 // record header length |
| 52 | dtlsRecordHeaderLen = 13 |
| 53 | maxHandshake = 65536 // maximum handshake we support (protocol max is 16 MB) |
| 54 |
| 55 | minVersion = VersionSSL30 |
| 56 | maxVersion = VersionTLS13 |
| 57 | ) |
| 58 |
| 59 | // TLS record types. |
| 60 | type recordType uint8 |
| 61 |
| 62 | const ( |
| 63 | recordTypeChangeCipherSpec recordType = 20 |
| 64 | recordTypeAlert recordType = 21 |
| 65 | recordTypeHandshake recordType = 22 |
| 66 | recordTypeApplicationData recordType = 23 |
| 67 | recordTypePlaintextHandshake recordType = 24 |
| 68 | ) |
| 69 |
| 70 | // TLS handshake message types. |
| 71 | const ( |
| 72 | typeHelloRequest uint8 = 0 |
| 73 | typeClientHello uint8 = 1 |
| 74 | typeServerHello uint8 = 2 |
| 75 | typeHelloVerifyRequest uint8 = 3 |
| 76 | typeNewSessionTicket uint8 = 4 |
| 77 | typeEndOfEarlyData uint8 = 5 |
| 78 | typeHelloRetryRequest uint8 = 6 |
| 79 | typeEncryptedExtensions uint8 = 8 |
| 80 | typeCertificate uint8 = 11 |
| 81 | typeServerKeyExchange uint8 = 12 |
| 82 | typeCertificateRequest uint8 = 13 |
| 83 | typeServerHelloDone uint8 = 14 |
| 84 | typeCertificateVerify uint8 = 15 |
| 85 | typeClientKeyExchange uint8 = 16 |
| 86 | typeFinished uint8 = 20 |
| 87 | typeCertificateStatus uint8 = 22 |
| 88 | typeKeyUpdate uint8 = 24 |
| 89 | typeCompressedCertificate uint8 = 25 // Not IANA assigned |
| 90 | typeNextProtocol uint8 = 67 // Not IANA assigned |
| 91 | typeChannelID uint8 = 203 // Not IANA assigned |
| 92 | typeMessageHash uint8 = 254 |
| 93 | ) |
| 94 |
| 95 | // TLS compression types. |
| 96 | const ( |
| 97 | compressionNone uint8 = 0 |
| 98 | ) |
| 99 |
| 100 | // TLS extension numbers |
| 101 | const ( |
| 102 | extensionServerName uint16 = 0 |
| 103 | extensionStatusRequest uint16 = 5 |
| 104 | extensionSupportedCurves uint16 = 10 |
| 105 | extensionSupportedPoints uint16 = 11 |
| 106 | extensionSignatureAlgorithms uint16 = 13 |
| 107 | extensionUseSRTP uint16 = 14 |
| 108 | extensionALPN uint16 = 16 |
| 109 | extensionSignedCertificateTimestamp uint16 = 18 |
| 110 | extensionPadding uint16 = 21 |
| 111 | extensionExtendedMasterSecret uint16 = 23 |
| 112 | extensionTokenBinding uint16 = 24 |
| 113 | extensionCompressedCertAlgs uint16 = 27 |
| 114 | extensionSessionTicket uint16 = 35 |
| 115 | extensionPreSharedKey uint16 = 41 |
| 116 | extensionEarlyData uint16 = 42 |
| 117 | extensionSupportedVersions uint16 = 43 |
| 118 | extensionCookie uint16 = 44 |
| 119 | extensionPSKKeyExchangeModes uint16 = 45 |
| 120 | extensionCertificateAuthorities uint16 = 47 |
| 121 | extensionSignatureAlgorithmsCert uint16 = 50 |
| 122 | extensionKeyShare uint16 = 51 |
| 123 | extensionCustom uint16 = 1234 // not IANA assigned |
| 124 | extensionNextProtoNeg uint16 = 13172 // not IANA assigned |
| 125 | extensionRenegotiationInfo uint16 = 0xff01 |
| 126 | extensionQUICTransportParams uint16 = 0xffa5 // draft-ietf-quic-tls-13 |
| 127 | extensionChannelID uint16 = 30032 // not IANA assigned |
| 128 | extensionDelegatedCredentials uint16 = 0xff02 // not IANA assigned |
| 129 | extensionPQExperimentSignal uint16 = 54538 |
| 130 | ) |
| 131 |
| 132 | // TLS signaling cipher suite values |
| 133 | const ( |
| 134 | scsvRenegotiation uint16 = 0x00ff |
| 135 | ) |
| 136 |
| 137 | var tls13HelloRetryRequest = []uint8{ |
| 138 | 0xcf, 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, |
| 139 | 0x02, 0x1e, 0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, |
| 140 | 0x8c, 0x5e, 0x07, 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, |
| 141 | } |
| 142 |
| 143 | // CurveID is the type of a TLS identifier for an elliptic curve. See |
| 144 | // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-8 |
| 145 | type CurveID uint16 |
| 146 |
| 147 | const ( |
| 148 | CurveP224 CurveID = 21 |
| 149 | CurveP256 CurveID = 23 |
| 150 | CurveP384 CurveID = 24 |
| 151 | CurveP521 CurveID = 25 |
| 152 | CurveX25519 CurveID = 29 |
| 153 | CurveCECPQ2 CurveID = 16696 |
| 154 | CurveCECPQ2b CurveID = 65074 |
| 155 | ) |
| 156 |
| 157 | // TLS Elliptic Curve Point Formats |
| 158 | // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-9 |
| 159 | const ( |
| 160 | pointFormatUncompressed uint8 = 0 |
| 161 | pointFormatCompressedPrime uint8 = 1 |
| 162 | ) |
| 163 |
| 164 | // TLS CertificateStatusType (RFC 3546) |
| 165 | const ( |
| 166 | statusTypeOCSP uint8 = 1 |
| 167 | ) |
| 168 |
| 169 | // Certificate types (for certificateRequestMsg) |
| 170 | const ( |
| 171 | CertTypeRSASign = 1 // A certificate containing an RSA key |
| 172 | CertTypeDSSSign = 2 // A certificate containing a DSA key |
| 173 | CertTypeRSAFixedDH = 3 // A certificate containing a static DH key |
| 174 | CertTypeDSSFixedDH = 4 // A certificate containing a static DH key |
| 175 |
| 176 | // See RFC4492 sections 3 and 5.5. |
| 177 | CertTypeECDSASign = 64 // A certificate containing an ECDSA-capable public key, signed with ECDSA. |
| 178 | CertTypeRSAFixedECDH = 65 // A certificate containing an ECDH-capable public key, signed with RSA. |
| 179 | CertTypeECDSAFixedECDH = 66 // A certificate containing an ECDH-capable public key, signed with ECDSA. |
| 180 |
| 181 | // Rest of these are reserved by the TLS spec |
| 182 | ) |
| 183 |
| 184 | // signatureAlgorithm corresponds to a SignatureScheme value from TLS 1.3. Note |
| 185 | // that TLS 1.3 names the production 'SignatureScheme' to avoid colliding with |
| 186 | // TLS 1.2's SignatureAlgorithm but otherwise refers to them as 'signature |
| 187 | // algorithms' throughout. We match the latter. |
| 188 | type signatureAlgorithm uint16 |
| 189 |
| 190 | const ( |
| 191 | // RSASSA-PKCS1-v1_5 algorithms |
| 192 | signatureRSAPKCS1WithMD5 signatureAlgorithm = 0x0101 |
| 193 | signatureRSAPKCS1WithSHA1 signatureAlgorithm = 0x0201 |
| 194 | signatureRSAPKCS1WithSHA256 signatureAlgorithm = 0x0401 |
| 195 | signatureRSAPKCS1WithSHA384 signatureAlgorithm = 0x0501 |
| 196 | signatureRSAPKCS1WithSHA512 signatureAlgorithm = 0x0601 |
| 197 |
| 198 | // ECDSA algorithms |
| 199 | signatureECDSAWithSHA1 signatureAlgorithm = 0x0203 |
| 200 | signatureECDSAWithP256AndSHA256 signatureAlgorithm = 0x0403 |
| 201 | signatureECDSAWithP384AndSHA384 signatureAlgorithm = 0x0503 |
| 202 | signatureECDSAWithP521AndSHA512 signatureAlgorithm = 0x0603 |
| 203 |
| 204 | // RSASSA-PSS algorithms |
| 205 | signatureRSAPSSWithSHA256 signatureAlgorithm = 0x0804 |
| 206 | signatureRSAPSSWithSHA384 signatureAlgorithm = 0x0805 |
| 207 | signatureRSAPSSWithSHA512 signatureAlgorithm = 0x0806 |
| 208 |
| 209 | // EdDSA algorithms |
| 210 | signatureEd25519 signatureAlgorithm = 0x0807 |
| 211 | signatureEd448 signatureAlgorithm = 0x0808 |
| 212 | ) |
| 213 |
| 214 | // supportedSignatureAlgorithms contains the default supported signature |
| 215 | // algorithms. |
| 216 | var supportedSignatureAlgorithms = []signatureAlgorithm{ |
| 217 | signatureRSAPSSWithSHA256, |
| 218 | signatureRSAPKCS1WithSHA256, |
| 219 | signatureECDSAWithP256AndSHA256, |
| 220 | signatureRSAPKCS1WithSHA1, |
| 221 | signatureECDSAWithSHA1, |
| 222 | signatureEd25519, |
| 223 | } |
| 224 |
| 225 | // SRTP protection profiles (See RFC 5764, section 4.1.2) |
| 226 | const ( |
| 227 | SRTP_AES128_CM_HMAC_SHA1_80 uint16 = 0x0001 |
| 228 | SRTP_AES128_CM_HMAC_SHA1_32 = 0x0002 |
| 229 | ) |
| 230 |
| 231 | // PskKeyExchangeMode values (see RFC 8446, section 4.2.9) |
| 232 | const ( |
| 233 | pskKEMode = 0 |
| 234 | pskDHEKEMode = 1 |
| 235 | ) |
| 236 |
| 237 | // KeyUpdateRequest values (see RFC 8446, section 4.6.3) |
| 238 | const ( |
| 239 | keyUpdateNotRequested = 0 |
| 240 | keyUpdateRequested = 1 |
| 241 | ) |
| 242 |
| 243 | // ConnectionState records basic TLS details about the connection. |
| 244 | type ConnectionState struct { |
| 245 | Version uint16 // TLS version used by the connection (e.g. VersionTLS12) |
| 246 | HandshakeComplete bool // TLS handshake is complete |
| 247 | DidResume bool // connection resumes a previous TLS connection |
| 248 | CipherSuite uint16 // cipher suite in use (TLS_RSA_WITH_RC4_128_SHA, ...) |
| 249 | NegotiatedProtocol string // negotiated next protocol (from Config.NextProtos) |
| 250 | NegotiatedProtocolIsMutual bool // negotiated protocol was advertised by server |
| 251 | NegotiatedProtocolFromALPN bool // protocol negotiated with ALPN |
| 252 | ServerName string // server name requested by client, if any (server side only) |
| 253 | PeerCertificates []*x509.Certificate // certificate chain presented by remote peer |
| 254 | VerifiedChains [][]*x509.Certificate // verified chains built from PeerCertificates |
| 255 | ChannelID *ecdsa.PublicKey // the channel ID for this connection |
| 256 | TokenBindingNegotiated bool // whether Token Binding was negotiated |
| 257 | TokenBindingParam uint8 // the negotiated Token Binding key parameter |
| 258 | SRTPProtectionProfile uint16 // the negotiated DTLS-SRTP protection profile |
| 259 | TLSUnique []byte // the tls-unique channel binding |
| 260 | SCTList []byte // signed certificate timestamp list |
| 261 | PeerSignatureAlgorithm signatureAlgorithm // algorithm used by the peer in the handshake |
| 262 | CurveID CurveID // the curve used in ECDHE |
| 263 | QUICTransportParams []byte // the QUIC transport params received from the peer |
| 264 | } |
| 265 |
| 266 | // ClientAuthType declares the policy the server will follow for |
| 267 | // TLS Client Authentication. |
| 268 | type ClientAuthType int |
| 269 |
| 270 | const ( |
| 271 | NoClientCert ClientAuthType = iota |
| 272 | RequestClientCert |
| 273 | RequireAnyClientCert |
| 274 | VerifyClientCertIfGiven |
| 275 | RequireAndVerifyClientCert |
| 276 | ) |
| 277 |
| 278 | // ClientSessionState contains the state needed by clients to resume TLS |
| 279 | // sessions. |
| 280 | type ClientSessionState struct { |
| 281 | sessionId []uint8 // Session ID supplied by the server. nil if the session has a ticket. |
| 282 | sessionTicket []uint8 // Encrypted ticket used for session resumption with server |
| 283 | vers uint16 // SSL/TLS version negotiated for the session |
| 284 | wireVersion uint16 // Wire SSL/TLS version negotiated for the session |
| 285 | cipherSuite uint16 // Ciphersuite negotiated for the session |
| 286 | masterSecret []byte // MasterSecret generated by client on a full handshake |
| 287 | handshakeHash []byte // Handshake hash for Channel ID purposes. |
| 288 | serverCertificates []*x509.Certificate // Certificate chain presented by the server |
| 289 | extendedMasterSecret bool // Whether an extended master secret was used to generate the session |
| 290 | sctList []byte |
| 291 | ocspResponse []byte |
| 292 | earlyALPN string |
| 293 | ticketCreationTime time.Time |
| 294 | ticketExpiration time.Time |
| 295 | ticketAgeAdd uint32 |
| 296 | maxEarlyDataSize uint32 |
| 297 | } |
| 298 |
| 299 | // ClientSessionCache is a cache of ClientSessionState objects that can be used |
| 300 | // by a client to resume a TLS session with a given server. ClientSessionCache |
| 301 | // implementations should expect to be called concurrently from different |
| 302 | // goroutines. |
| 303 | type ClientSessionCache interface { |
| 304 | // Get searches for a ClientSessionState associated with the given key. |
| 305 | // On return, ok is true if one was found. |
| 306 | Get(sessionKey string) (session *ClientSessionState, ok bool) |
| 307 |
| 308 | // Put adds the ClientSessionState to the cache with the given key. |
| 309 | Put(sessionKey string, cs *ClientSessionState) |
| 310 | } |
| 311 |
| 312 | // ServerSessionCache is a cache of sessionState objects that can be used by a |
| 313 | // client to resume a TLS session with a given server. ServerSessionCache |
| 314 | // implementations should expect to be called concurrently from different |
| 315 | // goroutines. |
| 316 | type ServerSessionCache interface { |
| 317 | // Get searches for a sessionState associated with the given session |
| 318 | // ID. On return, ok is true if one was found. |
| 319 | Get(sessionId string) (session *sessionState, ok bool) |
| 320 |
| 321 | // Put adds the sessionState to the cache with the given session ID. |
| 322 | Put(sessionId string, session *sessionState) |
| 323 | } |
| 324 |
| 325 | // CertCompressionAlg is a certificate compression algorithm, specified as a |
| 326 | // pair of functions for compressing and decompressing certificates. |
| 327 | type CertCompressionAlg struct { |
| 328 | // Compress returns a compressed representation of the input. |
| 329 | Compress func([]byte) []byte |
| 330 | // Decompress depresses the contents of in and writes the result to out, which |
| 331 | // will be the correct size. It returns true on success and false otherwise. |
| 332 | Decompress func(out, in []byte) bool |
| 333 | } |
| 334 |
| 335 | // A Config structure is used to configure a TLS client or server. |
| 336 | // After one has been passed to a TLS function it must not be |
| 337 | // modified. A Config may be reused; the tls package will also not |
| 338 | // modify it. |
| 339 | type Config struct { |
| 340 | // Rand provides the source of entropy for nonces and RSA blinding. |
| 341 | // If Rand is nil, TLS uses the cryptographic random reader in package |
| 342 | // crypto/rand. |
| 343 | // The Reader must be safe for use by multiple goroutines. |
| 344 | Rand io.Reader |
| 345 |
| 346 | // Time returns the current time as the number of seconds since the epoch. |
| 347 | // If Time is nil, TLS uses time.Now. |
| 348 | Time func() time.Time |
| 349 |
| 350 | // Certificates contains one or more certificate chains |
| 351 | // to present to the other side of the connection. |
| 352 | // Server configurations must include at least one certificate. |
| 353 | Certificates []Certificate |
| 354 |
| 355 | // NameToCertificate maps from a certificate name to an element of |
| 356 | // Certificates. Note that a certificate name can be of the form |
| 357 | // '*.example.com' and so doesn't have to be a domain name as such. |
| 358 | // See Config.BuildNameToCertificate |
| 359 | // The nil value causes the first element of Certificates to be used |
| 360 | // for all connections. |
| 361 | NameToCertificate map[string]*Certificate |
| 362 |
| 363 | // RootCAs defines the set of root certificate authorities |
| 364 | // that clients use when verifying server certificates. |
| 365 | // If RootCAs is nil, TLS uses the host's root CA set. |
| 366 | RootCAs *x509.CertPool |
| 367 |
| 368 | // NextProtos is a list of supported, application level protocols. |
| 369 | NextProtos []string |
| 370 |
| 371 | // ServerName is used to verify the hostname on the returned |
| 372 | // certificates unless InsecureSkipVerify is given. It is also included |
| 373 | // in the client's handshake to support virtual hosting. |
| 374 | ServerName string |
| 375 |
| 376 | // ClientAuth determines the server's policy for |
| 377 | // TLS Client Authentication. The default is NoClientCert. |
| 378 | ClientAuth ClientAuthType |
| 379 |
| 380 | // ClientCAs defines the set of root certificate authorities |
| 381 | // that servers use if required to verify a client certificate |
| 382 | // by the policy in ClientAuth. |
| 383 | ClientCAs *x509.CertPool |
| 384 |
| 385 | // ClientCertificateTypes defines the set of allowed client certificate |
| 386 | // types. The default is CertTypeRSASign and CertTypeECDSASign. |
| 387 | ClientCertificateTypes []byte |
| 388 |
| 389 | // InsecureSkipVerify controls whether a client verifies the |
| 390 | // server's certificate chain and host name. |
| 391 | // If InsecureSkipVerify is true, TLS accepts any certificate |
| 392 | // presented by the server and any host name in that certificate. |
| 393 | // In this mode, TLS is susceptible to man-in-the-middle attacks. |
| 394 | // This should be used only for testing. |
| 395 | InsecureSkipVerify bool |
| 396 |
| 397 | // CipherSuites is a list of supported cipher suites. If CipherSuites |
| 398 | // is nil, TLS uses a list of suites supported by the implementation. |
| 399 | CipherSuites []uint16 |
| 400 |
| 401 | // PreferServerCipherSuites controls whether the server selects the |
| 402 | // client's most preferred ciphersuite, or the server's most preferred |
| 403 | // ciphersuite. If true then the server's preference, as expressed in |
| 404 | // the order of elements in CipherSuites, is used. |
| 405 | PreferServerCipherSuites bool |
| 406 |
| 407 | // SessionTicketsDisabled may be set to true to disable session ticket |
| 408 | // (resumption) support. |
| 409 | SessionTicketsDisabled bool |
| 410 |
| 411 | // SessionTicketKey is used by TLS servers to provide session |
| 412 | // resumption. See RFC 5077. If zero, it will be filled with |
| 413 | // random data before the first server handshake. |
| 414 | // |
| 415 | // If multiple servers are terminating connections for the same host |
| 416 | // they should all have the same SessionTicketKey. If the |
| 417 | // SessionTicketKey leaks, previously recorded and future TLS |
| 418 | // connections using that key are compromised. |
| 419 | SessionTicketKey [32]byte |
| 420 |
| 421 | // ClientSessionCache is a cache of ClientSessionState entries |
| 422 | // for TLS session resumption. |
| 423 | ClientSessionCache ClientSessionCache |
| 424 |
| 425 | // ServerSessionCache is a cache of sessionState entries for TLS session |
| 426 | // resumption. |
| 427 | ServerSessionCache ServerSessionCache |
| 428 |
| 429 | // MinVersion contains the minimum SSL/TLS version that is acceptable. |
| 430 | // If zero, then SSLv3 is taken as the minimum. |
| 431 | MinVersion uint16 |
| 432 |
| 433 | // MaxVersion contains the maximum SSL/TLS version that is acceptable. |
| 434 | // If zero, then the maximum version supported by this package is used, |
| 435 | // which is currently TLS 1.2. |
| 436 | MaxVersion uint16 |
| 437 |
| 438 | // CurvePreferences contains the elliptic curves that will be used in |
| 439 | // an ECDHE handshake, in preference order. If empty, the default will |
| 440 | // be used. |
| 441 | CurvePreferences []CurveID |
| 442 |
| 443 | // DefaultCurves contains the elliptic curves for which public values will |
| 444 | // be sent in the ClientHello's KeyShare extension. If this value is nil, |
| 445 | // all supported curves will have public values sent. This field is ignored |
| 446 | // on servers. |
| 447 | DefaultCurves []CurveID |
| 448 |
| 449 | // ChannelID contains the ECDSA key for the client to use as |
| 450 | // its TLS Channel ID. |
| 451 | ChannelID *ecdsa.PrivateKey |
| 452 |
| 453 | // RequestChannelID controls whether the server requests a TLS |
| 454 | // Channel ID. If negotiated, the client's public key is |
| 455 | // returned in the ConnectionState. |
| 456 | RequestChannelID bool |
| 457 |
| 458 | // TokenBindingParams contains a list of TokenBindingKeyParameters |
| 459 | // (draft-ietf-tokbind-protocol-16) to attempt to negotiate. If |
| 460 | // nil, Token Binding will not be negotiated. |
| 461 | TokenBindingParams []byte |
| 462 |
| 463 | // TokenBindingVersion contains the serialized ProtocolVersion to |
| 464 | // use when negotiating Token Binding. |
| 465 | TokenBindingVersion uint16 |
| 466 |
| 467 | // ExpectTokenBindingParams is checked by a server that the client |
| 468 | // sent ExpectTokenBindingParams as its list of Token Binding |
| 469 | // paramters. |
| 470 | ExpectTokenBindingParams []byte |
| 471 |
| 472 | // PreSharedKey, if not nil, is the pre-shared key to use with |
| 473 | // the PSK cipher suites. |
| 474 | PreSharedKey []byte |
| 475 |
| 476 | // PreSharedKeyIdentity, if not empty, is the identity to use |
| 477 | // with the PSK cipher suites. |
| 478 | PreSharedKeyIdentity string |
| 479 |
| 480 | // MaxEarlyDataSize controls the maximum number of bytes that the |
| 481 | // server will accept in early data and advertise in a |
| 482 | // NewSessionTicketMsg. If 0, no early data will be accepted and |
| 483 | // the early_data extension in the NewSessionTicketMsg will be omitted. |
| 484 | MaxEarlyDataSize uint32 |
| 485 |
| 486 | // SRTPProtectionProfiles, if not nil, is the list of SRTP |
| 487 | // protection profiles to offer in DTLS-SRTP. |
| 488 | SRTPProtectionProfiles []uint16 |
| 489 |
| 490 | // SignSignatureAlgorithms, if not nil, overrides the default set of |
| 491 | // supported signature algorithms to sign with. |
| 492 | SignSignatureAlgorithms []signatureAlgorithm |
| 493 |
| 494 | // VerifySignatureAlgorithms, if not nil, overrides the default set of |
| 495 | // supported signature algorithms that are accepted. |
| 496 | VerifySignatureAlgorithms []signatureAlgorithm |
| 497 |
| 498 | // QUICTransportParams, if not empty, will be sent in the QUIC |
| 499 | // transport parameters extension. |
| 500 | QUICTransportParams []byte |
| 501 |
| 502 | CertCompressionAlgs map[uint16]CertCompressionAlg |
| 503 |
| 504 | // PQExperimentSignal instructs a client to send a non-IANA defined extension |
| 505 | // that signals participation in an experiment of post-quantum key exchange |
| 506 | // methods. |
| 507 | PQExperimentSignal bool |
| 508 |
| 509 | // Bugs specifies optional misbehaviour to be used for testing other |
| 510 | // implementations. |
| 511 | Bugs ProtocolBugs |
| 512 |
| 513 | serverInitOnce sync.Once // guards calling (*Config).serverInit |
| 514 | } |
| 515 |
| 516 | type BadValue int |
| 517 |
| 518 | const ( |
| 519 | BadValueNone BadValue = iota |
| 520 | BadValueNegative |
| 521 | BadValueZero |
| 522 | BadValueLimit |
| 523 | BadValueLarge |
| 524 | NumBadValues |
| 525 | ) |
| 526 |
| 527 | type RSABadValue int |
| 528 |
| 529 | const ( |
| 530 | RSABadValueNone RSABadValue = iota |
| 531 | RSABadValueCorrupt |
| 532 | RSABadValueTooLong |
| 533 | RSABadValueTooShort |
| 534 | RSABadValueWrongVersion1 |
| 535 | RSABadValueWrongVersion2 |
| 536 | RSABadValueWrongBlockType |
| 537 | RSABadValueWrongLeadingByte |
| 538 | RSABadValueNoZero |
| 539 | NumRSABadValues |
| 540 | ) |
| 541 |
| 542 | type RSAPSSSupport int |
| 543 |
| 544 | const ( |
| 545 | RSAPSSSupportAny RSAPSSSupport = iota |
| 546 | RSAPSSSupportNone |
| 547 | RSAPSSSupportOnlineSignatureOnly |
| 548 | RSAPSSSupportBoth |
| 549 | ) |
| 550 |
| 551 | type ProtocolBugs struct { |
| 552 | // InvalidSignature specifies that the signature in a ServerKeyExchange |
| 553 | // or CertificateVerify message should be invalid. |
| 554 | InvalidSignature bool |
| 555 |
| 556 | // SendCurve, if non-zero, causes the server to send the specified curve |
| 557 | // ID in ServerKeyExchange (TLS 1.2) or ServerHello (TLS 1.3) rather |
| 558 | // than the negotiated one. |
| 559 | SendCurve CurveID |
| 560 |
| 561 | // InvalidECDHPoint, if true, causes the ECC points in |
| 562 | // ServerKeyExchange or ClientKeyExchange messages to be invalid. |
| 563 | InvalidECDHPoint bool |
| 564 |
| 565 | // BadECDSAR controls ways in which the 'r' value of an ECDSA signature |
| 566 | // can be invalid. |
| 567 | BadECDSAR BadValue |
| 568 | BadECDSAS BadValue |
| 569 |
| 570 | // MaxPadding causes CBC records to have the maximum possible padding. |
| 571 | MaxPadding bool |
| 572 | // PaddingFirstByteBad causes the first byte of the padding to be |
| 573 | // incorrect. |
| 574 | PaddingFirstByteBad bool |
| 575 | // PaddingFirstByteBadIf255 causes the first byte of padding to be |
| 576 | // incorrect if there's a maximum amount of padding (i.e. 255 bytes). |
| 577 | PaddingFirstByteBadIf255 bool |
| 578 |
| 579 | // FailIfNotFallbackSCSV causes a server handshake to fail if the |
| 580 | // client doesn't send the fallback SCSV value. |
| 581 | FailIfNotFallbackSCSV bool |
| 582 |
| 583 | // DuplicateExtension causes an extra empty extension of bogus type to |
| 584 | // be emitted in either the ClientHello or the ServerHello. |
| 585 | DuplicateExtension bool |
| 586 |
| 587 | // UnauthenticatedECDH causes the server to pretend ECDHE_RSA |
| 588 | // and ECDHE_ECDSA cipher suites are actually ECDH_anon. No |
| 589 | // Certificate message is sent and no signature is added to |
| 590 | // ServerKeyExchange. |
| 591 | UnauthenticatedECDH bool |
| 592 |
| 593 | // SkipHelloVerifyRequest causes a DTLS server to skip the |
| 594 | // HelloVerifyRequest message. |
| 595 | SkipHelloVerifyRequest bool |
| 596 |
| 597 | // SkipCertificateStatus, if true, causes the server to skip the |
| 598 | // CertificateStatus message. This is legal because CertificateStatus is |
| 599 | // optional, even with a status_request in ServerHello. |
| 600 | SkipCertificateStatus bool |
| 601 |
| 602 | // SkipServerKeyExchange causes the server to skip sending |
| 603 | // ServerKeyExchange messages. |
| 604 | SkipServerKeyExchange bool |
| 605 |
| 606 | // SkipNewSessionTicket causes the server to skip sending the |
| 607 | // NewSessionTicket message despite promising to in ServerHello. |
| 608 | SkipNewSessionTicket bool |
| 609 |
| 610 | // UseFirstSessionTicket causes the client to cache only the first session |
| 611 | // ticket received. |
| 612 | UseFirstSessionTicket bool |
| 613 |
| 614 | // SkipClientCertificate causes the client to skip the Certificate |
| 615 | // message. |
| 616 | SkipClientCertificate bool |
| 617 |
| 618 | // SkipChangeCipherSpec causes the implementation to skip |
| 619 | // sending the ChangeCipherSpec message (and adjusting cipher |
| 620 | // state accordingly for the Finished message). |
| 621 | SkipChangeCipherSpec bool |
| 622 |
| 623 | // SkipFinished causes the implementation to skip sending the Finished |
| 624 | // message. |
| 625 | SkipFinished bool |
| 626 |
| 627 | // SkipEndOfEarlyData causes the implementation to skip |
| 628 | // end_of_early_data. |
| 629 | SkipEndOfEarlyData bool |
| 630 |
| 631 | // NonEmptyEndOfEarlyData causes the implementation to end an extra byte in the |
| 632 | // EndOfEarlyData. |
| 633 | NonEmptyEndOfEarlyData bool |
| 634 |
| 635 | // SkipCertificateVerify, if true causes peer to skip sending a |
| 636 | // CertificateVerify message after the Certificate message. |
| 637 | SkipCertificateVerify bool |
| 638 |
| 639 | // EarlyChangeCipherSpec causes the client to send an early |
| 640 | // ChangeCipherSpec message before the ClientKeyExchange. A value of |
| 641 | // zero disables this behavior. One and two configure variants for |
| 642 | // 1.0.1 and 0.9.8 modes, respectively. |
| 643 | EarlyChangeCipherSpec int |
| 644 |
| 645 | // StrayChangeCipherSpec causes every pre-ChangeCipherSpec handshake |
| 646 | // message in DTLS to be prefaced by stray ChangeCipherSpec record. This |
| 647 | // may be used to test DTLS's handling of reordered ChangeCipherSpec. |
| 648 | StrayChangeCipherSpec bool |
| 649 |
| 650 | // ReorderChangeCipherSpec causes the ChangeCipherSpec message to be |
| 651 | // sent at start of each flight in DTLS. Unlike EarlyChangeCipherSpec, |
| 652 | // the cipher change happens at the usual time. |
| 653 | ReorderChangeCipherSpec bool |
| 654 |
| 655 | // FragmentAcrossChangeCipherSpec causes the implementation to fragment |
| 656 | // the Finished (or NextProto) message around the ChangeCipherSpec |
| 657 | // messages. |
| 658 | FragmentAcrossChangeCipherSpec bool |
| 659 |
| 660 | // SendExtraChangeCipherSpec causes the implementation to send extra |
| 661 | // ChangeCipherSpec messages. |
| 662 | SendExtraChangeCipherSpec int |
| 663 |
| 664 | // SendPostHandshakeChangeCipherSpec causes the implementation to send |
| 665 | // a ChangeCipherSpec record before every application data record. |
| 666 | SendPostHandshakeChangeCipherSpec bool |
| 667 |
| 668 | // SendUnencryptedFinished, if true, causes the Finished message to be |
| 669 | // send unencrypted before ChangeCipherSpec rather than after it. |
| 670 | SendUnencryptedFinished bool |
| 671 |
| 672 | // PartialEncryptedExtensionsWithServerHello, if true, causes the TLS |
| 673 | // 1.3 server to send part of EncryptedExtensions unencrypted |
| 674 | // in the same record as ServerHello. |
| 675 | PartialEncryptedExtensionsWithServerHello bool |
| 676 |
| 677 | // PartialClientFinishedWithClientHello, if true, causes the TLS 1.3 |
| 678 | // client to send part of Finished unencrypted in the same record as |
| 679 | // ClientHello. |
| 680 | PartialClientFinishedWithClientHello bool |
| 681 |
| 682 | // SendV2ClientHello causes the client to send a V2ClientHello |
| 683 | // instead of a normal ClientHello. |
| 684 | SendV2ClientHello bool |
| 685 |
| 686 | // SendFallbackSCSV causes the client to include |
| 687 | // TLS_FALLBACK_SCSV in the ClientHello. |
| 688 | SendFallbackSCSV bool |
| 689 |
| 690 | // SendRenegotiationSCSV causes the client to include the renegotiation |
| 691 | // SCSV in the ClientHello. |
| 692 | SendRenegotiationSCSV bool |
| 693 |
| 694 | // MaxHandshakeRecordLength, if non-zero, is the maximum size of a |
| 695 | // handshake record. Handshake messages will be split into multiple |
| 696 | // records at the specified size, except that the client_version will |
| 697 | // never be fragmented. For DTLS, it is the maximum handshake fragment |
| 698 | // size, not record size; DTLS allows multiple handshake fragments in a |
| 699 | // single handshake record. See |PackHandshakeFragments|. |
| 700 | MaxHandshakeRecordLength int |
| 701 |
| 702 | // FragmentClientVersion will allow MaxHandshakeRecordLength to apply to |
| 703 | // the first 6 bytes of the ClientHello. |
| 704 | FragmentClientVersion bool |
| 705 |
| 706 | // FragmentAlert will cause all alerts to be fragmented across |
| 707 | // two records. |
| 708 | FragmentAlert bool |
| 709 |
| 710 | // DoubleAlert will cause all alerts to be sent as two copies packed |
| 711 | // within one record. |
| 712 | DoubleAlert bool |
| 713 |
| 714 | // SendSpuriousAlert, if non-zero, will cause an spurious, unwanted |
| 715 | // alert to be sent. |
| 716 | SendSpuriousAlert alert |
| 717 |
| 718 | // BadRSAClientKeyExchange causes the client to send a corrupted RSA |
| 719 | // ClientKeyExchange which would not pass padding checks. |
| 720 | BadRSAClientKeyExchange RSABadValue |
| 721 |
| 722 | // RenewTicketOnResume causes the server to renew the session ticket and |
| 723 | // send a NewSessionTicket message during an abbreviated handshake. |
| 724 | RenewTicketOnResume bool |
| 725 |
| 726 | // SendClientVersion, if non-zero, causes the client to send the |
| 727 | // specified value in the ClientHello version field. |
| 728 | SendClientVersion uint16 |
| 729 |
| 730 | // OmitSupportedVersions, if true, causes the client to omit the |
| 731 | // supported versions extension. |
| 732 | OmitSupportedVersions bool |
| 733 |
| 734 | // SendSupportedVersions, if non-empty, causes the client to send a |
| 735 | // supported versions extension with the values from array. |
| 736 | SendSupportedVersions []uint16 |
| 737 |
| 738 | // NegotiateVersion, if non-zero, causes the server to negotiate the |
| 739 | // specifed wire version rather than the version supported by either |
| 740 | // peer. |
| 741 | NegotiateVersion uint16 |
| 742 |
| 743 | // NegotiateVersionOnRenego, if non-zero, causes the server to negotiate |
| 744 | // the specified wire version on renegotiation rather than retaining it. |
| 745 | NegotiateVersionOnRenego uint16 |
| 746 |
| 747 | // ExpectFalseStart causes the server to, on full handshakes, |
| 748 | // expect the peer to False Start; the server Finished message |
| 749 | // isn't sent until we receive an application data record |
| 750 | // from the peer. |
| 751 | ExpectFalseStart bool |
| 752 |
| 753 | // AlertBeforeFalseStartTest, if non-zero, causes the server to, on full |
| 754 | // handshakes, send an alert just before reading the application data |
| 755 | // record to test False Start. This can be used in a negative False |
| 756 | // Start test to determine whether the peer processed the alert (and |
| 757 | // closed the connection) before or after sending app data. |
| 758 | AlertBeforeFalseStartTest alert |
| 759 |
| 760 | // ExpectServerName, if not empty, is the hostname the client |
| 761 | // must specify in the server_name extension. |
| 762 | ExpectServerName string |
| 763 |
| 764 | // SwapNPNAndALPN switches the relative order between NPN and ALPN in |
| 765 | // both ClientHello and ServerHello. |
| 766 | SwapNPNAndALPN bool |
| 767 |
| 768 | // ALPNProtocol, if not nil, sets the ALPN protocol that a server will |
| 769 | // return. |
| 770 | ALPNProtocol *string |
| 771 |
| 772 | // AcceptAnySession causes the server to resume sessions regardless of |
| 773 | // the version associated with the session or cipher suite. It also |
| 774 | // causes the server to look in both TLS 1.2 and 1.3 extensions to |
| 775 | // process a ticket. |
| 776 | AcceptAnySession bool |
| 777 |
| 778 | // SendBothTickets, if true, causes the client to send tickets in both |
| 779 | // TLS 1.2 and 1.3 extensions. |
| 780 | SendBothTickets bool |
| 781 |
| 782 | // FilterTicket, if not nil, causes the client to modify a session |
| 783 | // ticket before sending it in a resume handshake. |
| 784 | FilterTicket func([]byte) ([]byte, error) |
| 785 |
| 786 | // TicketSessionIDLength, if non-zero, is the length of the session ID |
| 787 | // to send with a ticket resumption offer. |
| 788 | TicketSessionIDLength int |
| 789 |
| 790 | // EmptyTicketSessionID, if true, causes the client to send an empty |
| 791 | // session ID with a ticket resumption offer. For simplicity, this will |
| 792 | // also cause the client to interpret a ServerHello with empty session |
| 793 | // ID as a resumption. (A client which sends empty session ID is |
| 794 | // normally expected to look ahead for ChangeCipherSpec.) |
| 795 | EmptyTicketSessionID bool |
| 796 |
| 797 | // SendClientHelloSessionID, if not nil, is the session ID sent in the |
| 798 | // ClientHello. |
| 799 | SendClientHelloSessionID []byte |
| 800 |
| 801 | // ExpectClientHelloSessionID, if true, causes the server to fail the |
| 802 | // connection if there is not a session ID in the ClientHello. |
| 803 | ExpectClientHelloSessionID bool |
| 804 |
| 805 | // EchoSessionIDInFullHandshake, if true, causes the server to echo the |
| 806 | // ClientHello session ID, even in TLS 1.2 full handshakes. |
| 807 | EchoSessionIDInFullHandshake bool |
| 808 |
| 809 | // ExpectNoTLS12Session, if true, causes the server to fail the |
| 810 | // connection if either a session ID or TLS 1.2 ticket is offered. |
| 811 | ExpectNoTLS12Session bool |
| 812 |
| 813 | // ExpectNoTLS13PSK, if true, causes the server to fail the connection |
| 814 | // if a TLS 1.3 PSK is offered. |
| 815 | ExpectNoTLS13PSK bool |
| 816 |
| 817 | // ExpectNoTLS13PSKAfterHRR, if true, causes the server to fail the connection |
| 818 | // if a TLS 1.3 PSK is offered after HRR. |
| 819 | ExpectNoTLS13PSKAfterHRR bool |
| 820 |
| 821 | // RequireExtendedMasterSecret, if true, requires that the peer support |
| 822 | // the extended master secret option. |
| 823 | RequireExtendedMasterSecret bool |
| 824 |
| 825 | // NoExtendedMasterSecret causes the client and server to behave as if |
| 826 | // they didn't support an extended master secret in the initial |
| 827 | // handshake. |
| 828 | NoExtendedMasterSecret bool |
| 829 |
| 830 | // NoExtendedMasterSecretOnRenegotiation causes the client and server to |
| 831 | // behave as if they didn't support an extended master secret in |
| 832 | // renegotiation handshakes. |
| 833 | NoExtendedMasterSecretOnRenegotiation bool |
| 834 |
| 835 | // EmptyRenegotiationInfo causes the renegotiation extension to be |
| 836 | // empty in a renegotiation handshake. |
| 837 | EmptyRenegotiationInfo bool |
| 838 |
| 839 | // BadRenegotiationInfo causes the renegotiation extension value in a |
| 840 | // renegotiation handshake to be incorrect at the start. |
| 841 | BadRenegotiationInfo bool |
| 842 |
| 843 | // BadRenegotiationInfoEnd causes the renegotiation extension value in |
| 844 | // a renegotiation handshake to be incorrect at the end. |
| 845 | BadRenegotiationInfoEnd bool |
| 846 |
| 847 | // NoRenegotiationInfo disables renegotiation info support in all |
| 848 | // handshakes. |
| 849 | NoRenegotiationInfo bool |
| 850 |
| 851 | // NoRenegotiationInfoInInitial disables renegotiation info support in |
| 852 | // the initial handshake. |
| 853 | NoRenegotiationInfoInInitial bool |
| 854 |
| 855 | // NoRenegotiationInfoAfterInitial disables renegotiation info support |
| 856 | // in renegotiation handshakes. |
| 857 | NoRenegotiationInfoAfterInitial bool |
| 858 |
| 859 | // RequireRenegotiationInfo, if true, causes the client to return an |
| 860 | // error if the server doesn't reply with the renegotiation extension. |
| 861 | RequireRenegotiationInfo bool |
| 862 |
| 863 | // SequenceNumberMapping, if non-nil, is the mapping function to apply |
| 864 | // to the sequence number of outgoing packets. For both TLS and DTLS, |
| 865 | // the two most-significant bytes in the resulting sequence number are |
| 866 | // ignored so that the DTLS epoch cannot be changed. |
| 867 | SequenceNumberMapping func(uint64) uint64 |
| 868 |
| 869 | // RSAEphemeralKey, if true, causes the server to send a |
| 870 | // ServerKeyExchange message containing an ephemeral key (as in |
| 871 | // RSA_EXPORT) in the plain RSA key exchange. |
| 872 | RSAEphemeralKey bool |
| 873 |
| 874 | // SRTPMasterKeyIdentifer, if not empty, is the SRTP MKI value that the |
| 875 | // client offers when negotiating SRTP. MKI support is still missing so |
| 876 | // the peer must still send none. |
| 877 | SRTPMasterKeyIdentifer string |
| 878 |
| 879 | // SendSRTPProtectionProfile, if non-zero, is the SRTP profile that the |
| 880 | // server sends in the ServerHello instead of the negotiated one. |
| 881 | SendSRTPProtectionProfile uint16 |
| 882 |
| 883 | // NoSignatureAlgorithms, if true, causes the client to omit the |
| 884 | // signature and hashes extension. |
| 885 | // |
| 886 | // For a server, it will cause an empty list to be sent in the |
| 887 | // CertificateRequest message. None the less, the configured set will |
| 888 | // still be enforced. |
| 889 | NoSignatureAlgorithms bool |
| 890 |
| 891 | // NoSupportedCurves, if true, causes the client to omit the |
| 892 | // supported_curves extension. |
| 893 | NoSupportedCurves bool |
| 894 |
| 895 | // RequireSameRenegoClientVersion, if true, causes the server |
| 896 | // to require that all ClientHellos match in offered version |
| 897 | // across a renego. |
| 898 | RequireSameRenegoClientVersion bool |
| 899 |
| 900 | // ExpectInitialRecordVersion, if non-zero, is the expected value of |
| 901 | // record-layer version field before the protocol version is determined. |
| 902 | ExpectInitialRecordVersion uint16 |
| 903 |
| 904 | // SendRecordVersion, if non-zero, is the value to send as the |
| 905 | // record-layer version. |
| 906 | SendRecordVersion uint16 |
| 907 |
| 908 | // SendInitialRecordVersion, if non-zero, is the value to send as the |
| 909 | // record-layer version before the protocol version is determined. |
| 910 | SendInitialRecordVersion uint16 |
| 911 |
| 912 | // MaxPacketLength, if non-zero, is the maximum acceptable size for a |
| 913 | // packet. |
| 914 | MaxPacketLength int |
| 915 |
| 916 | // SendCipherSuite, if non-zero, is the cipher suite value that the |
| 917 | // server will send in the ServerHello. This does not affect the cipher |
| 918 | // the server believes it has actually negotiated. |
| 919 | SendCipherSuite uint16 |
| 920 |
| 921 | // SendCipherSuites, if not nil, is the cipher suite list that the |
| 922 | // client will send in the ClientHello. This does not affect the cipher |
| 923 | // the client believes it has actually offered. |
| 924 | SendCipherSuites []uint16 |
| 925 |
| 926 | // AppDataBeforeHandshake, if not nil, causes application data to be |
| 927 | // sent immediately before the first handshake message. |
| 928 | AppDataBeforeHandshake []byte |
| 929 |
| 930 | // AppDataAfterChangeCipherSpec, if not nil, causes application data to |
| 931 | // be sent immediately after ChangeCipherSpec. |
| 932 | AppDataAfterChangeCipherSpec []byte |
| 933 |
| 934 | // AlertAfterChangeCipherSpec, if non-zero, causes an alert to be sent |
| 935 | // immediately after ChangeCipherSpec. |
| 936 | AlertAfterChangeCipherSpec alert |
| 937 |
| 938 | // TimeoutSchedule is the schedule of packet drops and simulated |
| 939 | // timeouts for before each handshake leg from the peer. |
| 940 | TimeoutSchedule []time.Duration |
| 941 |
| 942 | // PacketAdaptor is the packetAdaptor to use to simulate timeouts. |
| 943 | PacketAdaptor *packetAdaptor |
| 944 |
| 945 | // ReorderHandshakeFragments, if true, causes handshake fragments in |
| 946 | // DTLS to overlap and be sent in the wrong order. It also causes |
| 947 | // pre-CCS flights to be sent twice. (Post-CCS flights consist of |
| 948 | // Finished and will trigger a spurious retransmit.) |
| 949 | ReorderHandshakeFragments bool |
| 950 |
| 951 | // ReverseHandshakeFragments, if true, causes handshake fragments in |
| 952 | // DTLS to be reversed within a flight. |
| 953 | ReverseHandshakeFragments bool |
| 954 |
| 955 | // MixCompleteMessageWithFragments, if true, causes handshake |
| 956 | // messages in DTLS to redundantly both fragment the message |
| 957 | // and include a copy of the full one. |
| 958 | MixCompleteMessageWithFragments bool |
| 959 |
| 960 | // RetransmitFinished, if true, causes the DTLS Finished message to be |
| 961 | // sent twice. |
| 962 | RetransmitFinished bool |
| 963 |
| 964 | // SendInvalidRecordType, if true, causes a record with an invalid |
| 965 | // content type to be sent immediately following the handshake. |
| 966 | SendInvalidRecordType bool |
| 967 |
| 968 | // SendWrongMessageType, if non-zero, causes messages of the specified |
| 969 | // type to be sent with the wrong value. |
| 970 | SendWrongMessageType byte |
| 971 |
| 972 | // SendTrailingMessageData, if non-zero, causes messages of the |
| 973 | // specified type to be sent with trailing data. |
| 974 | SendTrailingMessageData byte |
| 975 |
| 976 | // FragmentMessageTypeMismatch, if true, causes all non-initial |
| 977 | // handshake fragments in DTLS to have the wrong message type. |
| 978 | FragmentMessageTypeMismatch bool |
| 979 |
| 980 | // FragmentMessageLengthMismatch, if true, causes all non-initial |
| 981 | // handshake fragments in DTLS to have the wrong message length. |
| 982 | FragmentMessageLengthMismatch bool |
| 983 |
| 984 | // SplitFragments, if non-zero, causes the handshake fragments in DTLS |
| 985 | // to be split across two records. The value of |SplitFragments| is the |
| 986 | // number of bytes in the first fragment. |
| 987 | SplitFragments int |
| 988 |
| 989 | // SendEmptyFragments, if true, causes handshakes to include empty |
| 990 | // fragments in DTLS. |
| 991 | SendEmptyFragments bool |
| 992 |
| 993 | // SendSplitAlert, if true, causes an alert to be sent with the header |
| 994 | // and record body split across multiple packets. The peer should |
| 995 | // discard these packets rather than process it. |
| 996 | SendSplitAlert bool |
| 997 |
| 998 | // FailIfResumeOnRenego, if true, causes renegotiations to fail if the |
| 999 | // client offers a resumption or the server accepts one. |
| 1000 | FailIfResumeOnRenego bool |
| 1001 |
| 1002 | // IgnorePeerCipherPreferences, if true, causes the peer's cipher |
| 1003 | // preferences to be ignored. |
| 1004 | IgnorePeerCipherPreferences bool |
| 1005 |
| 1006 | // IgnorePeerSignatureAlgorithmPreferences, if true, causes the peer's |
| 1007 | // signature algorithm preferences to be ignored. |
| 1008 | IgnorePeerSignatureAlgorithmPreferences bool |
| 1009 |
| 1010 | // IgnorePeerCurvePreferences, if true, causes the peer's curve |
| 1011 | // preferences to be ignored. |
| 1012 | IgnorePeerCurvePreferences bool |
| 1013 |
| 1014 | // BadFinished, if true, causes the Finished hash to be broken. |
| 1015 | BadFinished bool |
| 1016 |
| 1017 | // PackHandshakeFragments, if true, causes handshake fragments in DTLS |
| 1018 | // to be packed into individual handshake records, up to the specified |
| 1019 | // record size. |
| 1020 | PackHandshakeFragments int |
| 1021 |
| 1022 | // PackHandshakeRecords, if non-zero, causes handshake and |
| 1023 | // ChangeCipherSpec records in DTLS to be packed into individual |
| 1024 | // packets, up to the specified packet size. |
| 1025 | PackHandshakeRecords int |
| 1026 |
| 1027 | // PackAppDataWithHandshake, if true, extends PackHandshakeRecords to |
| 1028 | // additionally include the first application data record sent after the |
| 1029 | // final Finished message in a handshake. (If the final Finished message |
| 1030 | // is sent by the peer, this option has no effect.) This requires that |
| 1031 | // the runner rather than shim speak first in a given test. |
| 1032 | PackAppDataWithHandshake bool |
| 1033 |
| 1034 | // SplitAndPackAppData, if true, causes application data in DTLS to be |
| 1035 | // split into two records each and packed into one packet. |
| 1036 | SplitAndPackAppData bool |
| 1037 |
| 1038 | // PackHandshakeFlight, if true, causes each handshake flight in TLS to |
| 1039 | // be packed into records, up to the largest size record available. |
| 1040 | PackHandshakeFlight bool |
| 1041 |
| 1042 | // AdvertiseAllConfiguredCiphers, if true, causes the client to |
| 1043 | // advertise all configured cipher suite values. |
| 1044 | AdvertiseAllConfiguredCiphers bool |
| 1045 |
| 1046 | // EmptyCertificateList, if true, causes the server to send an empty |
| 1047 | // certificate list in the Certificate message. |
| 1048 | EmptyCertificateList bool |
| 1049 |
| 1050 | // ExpectNewTicket, if true, causes the client to abort if it does not |
| 1051 | // receive a new ticket. |
| 1052 | ExpectNewTicket bool |
| 1053 |
| 1054 | // RequireClientHelloSize, if not zero, is the required length in bytes |
| 1055 | // of the ClientHello /record/. This is checked by the server. |
| 1056 | RequireClientHelloSize int |
| 1057 |
| 1058 | // CustomExtension, if not empty, contains the contents of an extension |
| 1059 | // that will be added to client/server hellos. |
| 1060 | CustomExtension string |
| 1061 |
| 1062 | // CustomUnencryptedExtension, if not empty, contains the contents of |
| 1063 | // an extension that will be added to ServerHello in TLS 1.3. |
| 1064 | CustomUnencryptedExtension string |
| 1065 |
| 1066 | // ExpectedCustomExtension, if not nil, contains the expected contents |
| 1067 | // of a custom extension. |
| 1068 | ExpectedCustomExtension *string |
| 1069 |
| 1070 | // CustomTicketExtension, if not empty, contains the contents of an |
| 1071 | // extension what will be added to NewSessionTicket in TLS 1.3. |
| 1072 | CustomTicketExtension string |
| 1073 |
| 1074 | // CustomTicketExtension, if not empty, contains the contents of an |
| 1075 | // extension what will be added to HelloRetryRequest in TLS 1.3. |
| 1076 | CustomHelloRetryRequestExtension string |
| 1077 |
| 1078 | // NoCloseNotify, if true, causes the close_notify alert to be skipped |
| 1079 | // on connection shutdown. |
| 1080 | NoCloseNotify bool |
| 1081 |
| 1082 | // SendAlertOnShutdown, if non-zero, is the alert to send instead of |
| 1083 | // close_notify on shutdown. |
| 1084 | SendAlertOnShutdown alert |
| 1085 |
| 1086 | // ExpectCloseNotify, if true, requires a close_notify from the peer on |
| 1087 | // shutdown. Records from the peer received after close_notify is sent |
| 1088 | // are not discard. |
| 1089 | ExpectCloseNotify bool |
| 1090 |
| 1091 | // SendLargeRecords, if true, allows outgoing records to be sent |
| 1092 | // arbitrarily large. |
| 1093 | SendLargeRecords bool |
| 1094 |
| 1095 | // NegotiateALPNAndNPN, if true, causes the server to negotiate both |
| 1096 | // ALPN and NPN in the same connetion. |
| 1097 | NegotiateALPNAndNPN bool |
| 1098 |
| 1099 | // SendALPN, if non-empty, causes the server to send the specified |
| 1100 | // string in the ALPN extension regardless of the content or presence of |
| 1101 | // the client offer. |
| 1102 | SendALPN string |
| 1103 |
| 1104 | // SendUnencryptedALPN, if non-empty, causes the server to send the |
| 1105 | // specified string in a ServerHello ALPN extension in TLS 1.3. |
| 1106 | SendUnencryptedALPN string |
| 1107 |
| 1108 | // SendEmptySessionTicket, if true, causes the server to send an empty |
| 1109 | // session ticket. |
| 1110 | SendEmptySessionTicket bool |
| 1111 |
| 1112 | // SendPSKKeyExchangeModes, if present, determines the PSK key exchange modes |
| 1113 | // to send. |
| 1114 | SendPSKKeyExchangeModes []byte |
| 1115 |
| 1116 | // ExpectNoNewSessionTicket, if present, means that the client will fail upon |
| 1117 | // receipt of a NewSessionTicket message. |
| 1118 | ExpectNoNewSessionTicket bool |
| 1119 |
| 1120 | // DuplicateTicketEarlyData causes an extra empty extension of early_data to |
| 1121 | // be sent in NewSessionTicket. |
| 1122 | DuplicateTicketEarlyData bool |
| 1123 |
| 1124 | // ExpectTicketEarlyData, if true, means that the client will fail upon |
| 1125 | // absence of the early_data extension. |
| 1126 | ExpectTicketEarlyData bool |
| 1127 |
| 1128 | // ExpectTicketAge, if non-zero, is the expected age of the ticket that the |
| 1129 | // server receives from the client. |
| 1130 | ExpectTicketAge time.Duration |
| 1131 |
| 1132 | // SendTicketAge, if non-zero, is the ticket age to be sent by the |
| 1133 | // client. |
| 1134 | SendTicketAge time.Duration |
| 1135 |
| 1136 | // FailIfSessionOffered, if true, causes the server to fail any |
| 1137 | // connections where the client offers a non-empty session ID or session |
| 1138 | // ticket. |
| 1139 | FailIfSessionOffered bool |
| 1140 |
| 1141 | // SendHelloRequestBeforeEveryAppDataRecord, if true, causes a |
| 1142 | // HelloRequest handshake message to be sent before each application |
| 1143 | // data record. This only makes sense for a server. |
| 1144 | SendHelloRequestBeforeEveryAppDataRecord bool |
| 1145 |
| 1146 | // SendHelloRequestBeforeEveryHandshakeMessage, if true, causes a |
| 1147 | // HelloRequest handshake message to be sent before each handshake |
| 1148 | // message. This only makes sense for a server. |
| 1149 | SendHelloRequestBeforeEveryHandshakeMessage bool |
| 1150 |
| 1151 | // BadChangeCipherSpec, if not nil, is the body to be sent in |
| 1152 | // ChangeCipherSpec records instead of {1}. |
| 1153 | BadChangeCipherSpec []byte |
| 1154 |
| 1155 | // BadHelloRequest, if not nil, is what to send instead of a |
| 1156 | // HelloRequest. |
| 1157 | BadHelloRequest []byte |
| 1158 |
| 1159 | // RequireSessionTickets, if true, causes the client to require new |
| 1160 | // sessions use session tickets instead of session IDs. |
| 1161 | RequireSessionTickets bool |
| 1162 |
| 1163 | // RequireSessionIDs, if true, causes the client to require new sessions use |
| 1164 | // session IDs instead of session tickets. |
| 1165 | RequireSessionIDs bool |
| 1166 |
| 1167 | // NullAllCiphers, if true, causes every cipher to behave like the null |
| 1168 | // cipher. |
| 1169 | NullAllCiphers bool |
| 1170 |
| 1171 | // SendSCTListOnResume, if not nil, causes the server to send the |
| 1172 | // supplied SCT list in resumption handshakes. |
| 1173 | SendSCTListOnResume []byte |
| 1174 |
| 1175 | // SendSCTListOnRenegotiation, if not nil, causes the server to send the |
| 1176 | // supplied SCT list on renegotiation. |
| 1177 | SendSCTListOnRenegotiation []byte |
| 1178 |
| 1179 | // SendOCSPResponseOnResume, if not nil, causes the server to advertise |
| 1180 | // OCSP stapling in resumption handshakes and, if applicable, send the |
| 1181 | // supplied stapled response. |
| 1182 | SendOCSPResponseOnResume []byte |
| 1183 |
| 1184 | // SendOCSPResponseOnResume, if not nil, causes the server to send the |
| 1185 | // supplied OCSP response on renegotiation. |
| 1186 | SendOCSPResponseOnRenegotiation []byte |
| 1187 |
| 1188 | // SendExtensionOnCertificate, if not nil, causes the runner to send the |
| 1189 | // supplied bytes in the extensions on the Certificate message. |
| 1190 | SendExtensionOnCertificate []byte |
| 1191 |
| 1192 | // SendOCSPOnIntermediates, if not nil, causes the server to send the |
| 1193 | // supplied OCSP on intermediate certificates in the Certificate message. |
| 1194 | SendOCSPOnIntermediates []byte |
| 1195 |
| 1196 | // SendSCTOnIntermediates, if not nil, causes the server to send the |
| 1197 | // supplied SCT on intermediate certificates in the Certificate message. |
| 1198 | SendSCTOnIntermediates []byte |
| 1199 |
| 1200 | // SendDuplicateCertExtensions, if true, causes the server to send an extra |
| 1201 | // copy of the OCSP/SCT extensions in the Certificate message. |
| 1202 | SendDuplicateCertExtensions bool |
| 1203 |
| 1204 | // ExpectNoExtensionsOnIntermediate, if true, causes the client to |
| 1205 | // reject extensions on intermediate certificates. |
| 1206 | ExpectNoExtensionsOnIntermediate bool |
| 1207 |
| 1208 | // RecordPadding is the number of bytes of padding to add to each |
| 1209 | // encrypted record in TLS 1.3. |
| 1210 | RecordPadding int |
| 1211 |
| 1212 | // OmitRecordContents, if true, causes encrypted records in TLS 1.3 to |
| 1213 | // be missing their body and content type. Padding, if configured, is |
| 1214 | // still added. |
| 1215 | OmitRecordContents bool |
| 1216 |
| 1217 | // OuterRecordType, if non-zero, is the outer record type to use instead |
| 1218 | // of application data. |
| 1219 | OuterRecordType recordType |
| 1220 |
| 1221 | // SendSignatureAlgorithm, if non-zero, causes all signatures to be sent |
| 1222 | // with the given signature algorithm rather than the one negotiated. |
| 1223 | SendSignatureAlgorithm signatureAlgorithm |
| 1224 |
| 1225 | // SkipECDSACurveCheck, if true, causes all ECDSA curve checks to be |
| 1226 | // skipped. |
| 1227 | SkipECDSACurveCheck bool |
| 1228 |
| 1229 | // IgnoreSignatureVersionChecks, if true, causes all signature |
| 1230 | // algorithms to be enabled at all TLS versions. |
| 1231 | IgnoreSignatureVersionChecks bool |
| 1232 |
| 1233 | // NegotiateRenegotiationInfoAtAllVersions, if true, causes |
| 1234 | // Renegotiation Info to be negotiated at all versions. |
| 1235 | NegotiateRenegotiationInfoAtAllVersions bool |
| 1236 |
| 1237 | // NegotiateNPNAtAllVersions, if true, causes NPN to be negotiated at |
| 1238 | // all versions. |
| 1239 | NegotiateNPNAtAllVersions bool |
| 1240 |
| 1241 | // NegotiateEMSAtAllVersions, if true, causes EMS to be negotiated at |
| 1242 | // all versions. |
| 1243 | NegotiateEMSAtAllVersions bool |
| 1244 |
| 1245 | // AdvertiseTicketExtension, if true, causes the ticket extension to be |
| 1246 | // advertised in server extensions |
| 1247 | AdvertiseTicketExtension bool |
| 1248 |
| 1249 | // NegotiatePSKResumption, if true, causes the server to attempt pure PSK |
| 1250 | // resumption. |
| 1251 | NegotiatePSKResumption bool |
| 1252 |
| 1253 | // AlwaysSelectPSKIdentity, if true, causes the server in TLS 1.3 to |
| 1254 | // always acknowledge a session, regardless of one was offered. |
| 1255 | AlwaysSelectPSKIdentity bool |
| 1256 |
| 1257 | // SelectPSKIdentityOnResume, if non-zero, causes the server to select |
| 1258 | // the specified PSK identity index rather than the actual value. |
| 1259 | SelectPSKIdentityOnResume uint16 |
| 1260 |
| 1261 | // ExtraPSKIdentity, if true, causes the client to send an extra PSK |
| 1262 | // identity. |
| 1263 | ExtraPSKIdentity bool |
| 1264 |
| 1265 | // MissingKeyShare, if true, causes the TLS 1.3 implementation to skip |
| 1266 | // sending a key_share extension and use the zero ECDHE secret |
| 1267 | // instead. |
| 1268 | MissingKeyShare bool |
| 1269 |
| 1270 | // SecondClientHelloMissingKeyShare, if true, causes the second TLS 1.3 |
| 1271 | // ClientHello to skip sending a key_share extension and use the zero |
| 1272 | // ECDHE secret instead. |
| 1273 | SecondClientHelloMissingKeyShare bool |
| 1274 |
| 1275 | // MisinterpretHelloRetryRequestCurve, if non-zero, causes the TLS 1.3 |
| 1276 | // client to pretend the server requested a HelloRetryRequest with the |
| 1277 | // given curve rather than the actual one. |
| 1278 | MisinterpretHelloRetryRequestCurve CurveID |
| 1279 |
| 1280 | // DuplicateKeyShares, if true, causes the TLS 1.3 client to send two |
| 1281 | // copies of each KeyShareEntry. |
| 1282 | DuplicateKeyShares bool |
| 1283 |
| 1284 | // SendEarlyAlert, if true, sends a fatal alert after the ClientHello. |
| 1285 | SendEarlyAlert bool |
| 1286 |
| 1287 | // SendFakeEarlyDataLength, if non-zero, is the amount of early data to |
| 1288 | // send after the ClientHello. |
| 1289 | SendFakeEarlyDataLength int |
| 1290 |
| 1291 | // SendStrayEarlyHandshake, if non-zero, causes the client to send a stray |
| 1292 | // handshake record before sending end of early data. |
| 1293 | SendStrayEarlyHandshake bool |
| 1294 |
| 1295 | // OmitEarlyDataExtension, if true, causes the early data extension to |
| 1296 | // be omitted in the ClientHello. |
| 1297 | OmitEarlyDataExtension bool |
| 1298 |
| 1299 | // SendEarlyDataOnSecondClientHello, if true, causes the TLS 1.3 client to |
| 1300 | // send early data after the second ClientHello. |
| 1301 | SendEarlyDataOnSecondClientHello bool |
| 1302 |
| 1303 | // InterleaveEarlyData, if true, causes the TLS 1.3 client to send early |
| 1304 | // data interleaved with the second ClientHello and the client Finished. |
| 1305 | InterleaveEarlyData bool |
| 1306 |
| 1307 | // SendEarlyData causes a TLS 1.3 client to send the provided data |
| 1308 | // in application data records immediately after the ClientHello, |
| 1309 | // provided that the client offers a TLS 1.3 session. It will do this |
| 1310 | // whether or not the server advertised early data for the ticket. |
| 1311 | SendEarlyData [][]byte |
| 1312 |
| 1313 | // ExpectEarlyDataAccepted causes a TLS 1.3 client to check that early data |
| 1314 | // was accepted by the server. |
| 1315 | ExpectEarlyDataAccepted bool |
| 1316 |
| 1317 | // AlwaysAcceptEarlyData causes a TLS 1.3 server to always accept early data |
| 1318 | // regardless of ALPN mismatch. |
| 1319 | AlwaysAcceptEarlyData bool |
| 1320 |
| 1321 | // AlwaysRejectEarlyData causes a TLS 1.3 server to always reject early data. |
| 1322 | AlwaysRejectEarlyData bool |
| 1323 |
| 1324 | // SendEarlyDataExtension, if true, causes a TLS 1.3 server to send the |
| 1325 | // early_data extension in EncryptedExtensions, independent of whether |
| 1326 | // it was accepted. |
| 1327 | SendEarlyDataExtension bool |
| 1328 |
| 1329 | // ExpectEarlyData causes a TLS 1.3 server to read application |
| 1330 | // data after the ClientHello (assuming the server is able to |
| 1331 | // derive the key under which the data is encrypted) before it |
| 1332 | // sends a ServerHello. It checks that the application data it |
| 1333 | // reads matches what is provided in ExpectEarlyData and errors if |
| 1334 | // the number of records or their content do not match. |
| 1335 | ExpectEarlyData [][]byte |
| 1336 |
| 1337 | // ExpectLateEarlyData causes a TLS 1.3 server to read application |
| 1338 | // data after the ServerFinished (assuming the server is able to |
| 1339 | // derive the key under which the data is encrypted) before it |
| 1340 | // sends the ClientFinished. It checks that the application data it |
| 1341 | // reads matches what is provided in ExpectLateEarlyData and errors if |
| 1342 | // the number of records or their content do not match. |
| 1343 | ExpectLateEarlyData [][]byte |
| 1344 |
| 1345 | // SendHalfRTTData causes a TLS 1.3 server to send the provided |
| 1346 | // data in application data records before reading the client's |
| 1347 | // Finished message. |
| 1348 | SendHalfRTTData [][]byte |
| 1349 |
| 1350 | // ExpectHalfRTTData causes a TLS 1.3 client, if 0-RTT was accepted, to |
| 1351 | // read application data after reading the server's Finished message and |
| 1352 | // before sending any subsequent handshake messages. It checks that the |
| 1353 | // application data it reads matches what is provided in |
| 1354 | // ExpectHalfRTTData and errors if the number of records or their |
| 1355 | // content do not match. |
| 1356 | ExpectHalfRTTData [][]byte |
| 1357 |
| 1358 | // EmptyEncryptedExtensions, if true, causes the TLS 1.3 server to |
| 1359 | // emit an empty EncryptedExtensions block. |
| 1360 | EmptyEncryptedExtensions bool |
| 1361 |
| 1362 | // EncryptedExtensionsWithKeyShare, if true, causes the TLS 1.3 server to |
| 1363 | // include the KeyShare extension in the EncryptedExtensions block. |
| 1364 | EncryptedExtensionsWithKeyShare bool |
| 1365 |
| 1366 | // AlwaysSendHelloRetryRequest, if true, causes a HelloRetryRequest to |
| 1367 | // be sent by the server, even if empty. |
| 1368 | AlwaysSendHelloRetryRequest bool |
| 1369 |
| 1370 | // SecondHelloRetryRequest, if true, causes the TLS 1.3 server to send |
| 1371 | // two HelloRetryRequests instead of one. |
| 1372 | SecondHelloRetryRequest bool |
| 1373 |
| 1374 | // SendHelloRetryRequestCurve, if non-zero, causes the server to send |
| 1375 | // the specified curve in a HelloRetryRequest. |
| 1376 | SendHelloRetryRequestCurve CurveID |
| 1377 |
| 1378 | // SendHelloRetryRequestCipherSuite, if non-zero, causes the server to send |
| 1379 | // the specified cipher suite in a HelloRetryRequest. |
| 1380 | SendHelloRetryRequestCipherSuite uint16 |
| 1381 |
| 1382 | // SendHelloRetryRequestCookie, if not nil, contains a cookie to be |
| 1383 | // sent by the server in HelloRetryRequest. |
| 1384 | SendHelloRetryRequestCookie []byte |
| 1385 |
| 1386 | // DuplicateHelloRetryRequestExtensions, if true, causes all |
| 1387 | // HelloRetryRequest extensions to be sent twice. |
| 1388 | DuplicateHelloRetryRequestExtensions bool |
| 1389 |
| 1390 | // SendServerHelloVersion, if non-zero, causes the server to send the |
| 1391 | // specified value in ServerHello version field. |
| 1392 | SendServerHelloVersion uint16 |
| 1393 |
| 1394 | // SendServerSupportedVersionExtension, if non-zero, causes the server to send |
| 1395 | // the specified value in supported_versions extension in the ServerHello (but |
| 1396 | // not the HelloRetryRequest). |
| 1397 | SendServerSupportedVersionExtension uint16 |
| 1398 |
| 1399 | // OmitServerSupportedVersionExtension, if true, causes the server to |
| 1400 | // omit the supported_versions extension in the ServerHello (but not the |
| 1401 | // HelloRetryRequest) |
| 1402 | OmitServerSupportedVersionExtension bool |
| 1403 |
| 1404 | // SkipHelloRetryRequest, if true, causes the TLS 1.3 server to not send |
| 1405 | // HelloRetryRequest. |
| 1406 | SkipHelloRetryRequest bool |
| 1407 |
| 1408 | // PackHelloRequestWithFinished, if true, causes the TLS server to send |
| 1409 | // HelloRequest in the same record as Finished. |
| 1410 | PackHelloRequestWithFinished bool |
| 1411 |
| 1412 | // ExpectMissingKeyShare, if true, causes the TLS server to fail the |
| 1413 | // connection if the selected curve appears in the client's initial |
| 1414 | // ClientHello. That is, it requires that a HelloRetryRequest be sent. |
| 1415 | ExpectMissingKeyShare bool |
| 1416 |
| 1417 | // SendExtraFinished, if true, causes an extra Finished message to be |
| 1418 | // sent. |
| 1419 | SendExtraFinished bool |
| 1420 |
| 1421 | // SendRequestContext, if not empty, is the request context to send in |
| 1422 | // a TLS 1.3 CertificateRequest. |
| 1423 | SendRequestContext []byte |
| 1424 |
| 1425 | // OmitCertificateRequestAlgorithms, if true, omits the signature_algorithm |
| 1426 | // extension in a TLS 1.3 CertificateRequest. |
| 1427 | OmitCertificateRequestAlgorithms bool |
| 1428 |
| 1429 | // SendCustomCertificateRequest, if non-zero, send an additional custom |
| 1430 | // extension in a TLS 1.3 CertificateRequest. |
| 1431 | SendCustomCertificateRequest uint16 |
| 1432 |
| 1433 | // SendSNIWarningAlert, if true, causes the server to send an |
| 1434 | // unrecognized_name alert before the ServerHello. |
| 1435 | SendSNIWarningAlert bool |
| 1436 |
| 1437 | // SendCompressionMethods, if not nil, is the compression method list to |
| 1438 | // send in the ClientHello. |
| 1439 | SendCompressionMethods []byte |
| 1440 |
| 1441 | // SendCompressionMethod is the compression method to send in the |
| 1442 | // ServerHello. |
| 1443 | SendCompressionMethod byte |
| 1444 |
| 1445 | // AlwaysSendPreSharedKeyIdentityHint, if true, causes the server to |
| 1446 | // always send a ServerKeyExchange for PSK ciphers, even if the identity |
| 1447 | // hint is empty. |
| 1448 | AlwaysSendPreSharedKeyIdentityHint bool |
| 1449 |
| 1450 | // TrailingKeyShareData, if true, causes the client key share list to |
| 1451 | // include a trailing byte. |
| 1452 | TrailingKeyShareData bool |
| 1453 |
| 1454 | // InvalidChannelIDSignature, if true, causes the client to generate an |
| 1455 | // invalid Channel ID signature. |
| 1456 | InvalidChannelIDSignature bool |
| 1457 |
| 1458 | // ExpectGREASE, if true, causes messages without GREASE values to be |
| 1459 | // rejected. See draft-davidben-tls-grease-01. |
| 1460 | ExpectGREASE bool |
| 1461 |
| 1462 | // OmitPSKsOnSecondClientHello, if true, causes the client to omit the |
| 1463 | // PSK extension on the second ClientHello. |
| 1464 | OmitPSKsOnSecondClientHello bool |
| 1465 |
| 1466 | // OnlyCorruptSecondPSKBinder, if true, causes the options below to |
| 1467 | // only apply to the second PSK binder. |
| 1468 | OnlyCorruptSecondPSKBinder bool |
| 1469 |
| 1470 | // SendShortPSKBinder, if true, causes the client to send a PSK binder |
| 1471 | // that is one byte shorter than it should be. |
| 1472 | SendShortPSKBinder bool |
| 1473 |
| 1474 | // SendInvalidPSKBinder, if true, causes the client to send an invalid |
| 1475 | // PSK binder. |
| 1476 | SendInvalidPSKBinder bool |
| 1477 |
| 1478 | // SendNoPSKBinder, if true, causes the client to send no PSK binders. |
| 1479 | SendNoPSKBinder bool |
| 1480 |
| 1481 | // SendExtraPSKBinder, if true, causes the client to send an extra PSK |
| 1482 | // binder. |
| 1483 | SendExtraPSKBinder bool |
| 1484 |
| 1485 | // PSKBinderFirst, if true, causes the client to send the PSK Binder |
| 1486 | // extension as the first extension instead of the last extension. |
| 1487 | PSKBinderFirst bool |
| 1488 |
| 1489 | // NoOCSPStapling, if true, causes the client to not request OCSP |
| 1490 | // stapling. |
| 1491 | NoOCSPStapling bool |
| 1492 |
| 1493 | // NoSignedCertificateTimestamps, if true, causes the client to not |
| 1494 | // request signed certificate timestamps. |
| 1495 | NoSignedCertificateTimestamps bool |
| 1496 |
| 1497 | // SendSupportedPointFormats, if not nil, is the list of supported point |
| 1498 | // formats to send in ClientHello or ServerHello. If set to a non-nil |
| 1499 | // empty slice, no extension will be sent. |
| 1500 | SendSupportedPointFormats []byte |
| 1501 |
| 1502 | // SendServerSupportedCurves, if true, causes the server to send its |
| 1503 | // supported curves list in the ServerHello (TLS 1.2) or |
| 1504 | // EncryptedExtensions (TLS 1.3) message. This is invalid in TLS 1.2 and |
| 1505 | // valid in TLS 1.3. |
| 1506 | SendServerSupportedCurves bool |
| 1507 |
| 1508 | // MaxReceivePlaintext, if non-zero, is the maximum plaintext record |
| 1509 | // length accepted from the peer. |
| 1510 | MaxReceivePlaintext int |
| 1511 |
| 1512 | // ExpectPackedEncryptedHandshake, if non-zero, requires that the peer maximally |
| 1513 | // pack their encrypted handshake messages, fitting at most the |
| 1514 | // specified number of plaintext bytes per record. |
| 1515 | ExpectPackedEncryptedHandshake int |
| 1516 |
| 1517 | // SendTicketLifetime, if non-zero, is the ticket lifetime to send in |
| 1518 | // NewSessionTicket messages. |
| 1519 | SendTicketLifetime time.Duration |
| 1520 |
| 1521 | // SendServerNameAck, if true, causes the server to acknowledge the SNI |
| 1522 | // extension. |
| 1523 | SendServerNameAck bool |
| 1524 |
| 1525 | // ExpectCertificateReqNames, if not nil, contains the list of X.509 |
| 1526 | // names that must be sent in a CertificateRequest from the server. |
| 1527 | ExpectCertificateReqNames [][]byte |
| 1528 |
| 1529 | // RenegotiationCertificate, if not nil, is the certificate to use on |
| 1530 | // renegotiation handshakes. |
| 1531 | RenegotiationCertificate *Certificate |
| 1532 |
| 1533 | // ExpectNoCertificateAuthoritiesExtension, if true, causes the client to |
| 1534 | // reject CertificateRequest with the CertificateAuthorities extension. |
| 1535 | ExpectNoCertificateAuthoritiesExtension bool |
| 1536 |
| 1537 | // UseLegacySigningAlgorithm, if non-zero, is the signature algorithm |
| 1538 | // to use when signing in TLS 1.1 and earlier where algorithms are not |
| 1539 | // negotiated. |
| 1540 | UseLegacySigningAlgorithm signatureAlgorithm |
| 1541 |
| 1542 | // SendServerHelloAsHelloRetryRequest, if true, causes the server to |
| 1543 | // send ServerHello messages with a HelloRetryRequest type field. |
| 1544 | SendServerHelloAsHelloRetryRequest bool |
| 1545 |
| 1546 | // RejectUnsolicitedKeyUpdate, if true, causes all unsolicited |
| 1547 | // KeyUpdates from the peer to be rejected. |
| 1548 | RejectUnsolicitedKeyUpdate bool |
| 1549 |
| 1550 | // OmitExtensions, if true, causes the extensions field in ClientHello |
| 1551 | // and ServerHello messages to be omitted. |
| 1552 | OmitExtensions bool |
| 1553 |
| 1554 | // EmptyExtensions, if true, causes the extensions field in ClientHello |
| 1555 | // and ServerHello messages to be present, but empty. |
| 1556 | EmptyExtensions bool |
| 1557 |
| 1558 | // ExpectOmitExtensions, if true, causes the client to reject |
| 1559 | // ServerHello messages that do not omit extensions. |
| 1560 | ExpectOmitExtensions bool |
| 1561 |
| 1562 | // ExpectRecordSplitting, if true, causes application records to only be |
| 1563 | // accepted if they follow a 1/n-1 record split. |
| 1564 | ExpectRecordSplitting bool |
| 1565 |
| 1566 | // PadClientHello, if non-zero, pads the ClientHello to a multiple of |
| 1567 | // that many bytes. |
| 1568 | PadClientHello int |
| 1569 |
| 1570 | // SendTLS13DowngradeRandom, if true, causes the server to send the |
| 1571 | // TLS 1.3 anti-downgrade signal. |
| 1572 | SendTLS13DowngradeRandom bool |
| 1573 |
| 1574 | // CheckTLS13DowngradeRandom, if true, causes the client to check the |
| 1575 | // TLS 1.3 anti-downgrade signal regardless of its variant. |
| 1576 | CheckTLS13DowngradeRandom bool |
| 1577 |
| 1578 | // IgnoreTLS13DowngradeRandom, if true, causes the client to ignore the |
| 1579 | // TLS 1.3 anti-downgrade signal. |
| 1580 | IgnoreTLS13DowngradeRandom bool |
| 1581 |
| 1582 | // SendCompressedCoordinates, if true, causes ECDH key shares over NIST |
| 1583 | // curves to use compressed coordinates. |
| 1584 | SendCompressedCoordinates bool |
| 1585 |
| 1586 | // ExpectRSAPSSSupport specifies the level of RSA-PSS support expected |
| 1587 | // from the peer. |
| 1588 | ExpectRSAPSSSupport RSAPSSSupport |
| 1589 |
| 1590 | // SetX25519HighBit, if true, causes X25519 key shares to set their |
| 1591 | // high-order bit. |
| 1592 | SetX25519HighBit bool |
| 1593 |
| 1594 | // DuplicateCompressedCertAlgs, if true, causes two, equal, certificate |
| 1595 | // compression algorithm IDs to be sent. |
| 1596 | DuplicateCompressedCertAlgs bool |
| 1597 |
| 1598 | // ExpectedCompressedCert specifies the compression algorithm ID that must be |
| 1599 | // used on this connection, or zero if there are no special requirements. |
| 1600 | ExpectedCompressedCert uint16 |
| 1601 |
| 1602 | // SendCertCompressionAlgId, if not zero, sets the algorithm ID that will be |
| 1603 | // sent in the compressed certificate message. |
| 1604 | SendCertCompressionAlgId uint16 |
| 1605 |
| 1606 | // SendCertUncompressedLength, if not zero, sets the uncompressed length that |
| 1607 | // will be sent in the compressed certificate message. |
| 1608 | SendCertUncompressedLength uint32 |
| 1609 |
| 1610 | // SendClientHelloWithFixes, if not nil, sends the specified byte string |
| 1611 | // instead of the ClientHello. This string is incorporated into the |
| 1612 | // transcript as if it were the real ClientHello, but the handshake will |
| 1613 | // otherwise behave as if this was not sent in terms of what ciphers it |
| 1614 | // will accept, etc. |
| 1615 | // |
| 1616 | // The input is modified to match key share entries. DefaultCurves must |
| 1617 | // be configured to match. The random and session ID fields are |
| 1618 | // extracted from the ClientHello. |
| 1619 | SendClientHelloWithFixes []byte |
| 1620 |
| 1621 | // SendJDK11DowngradeRandom, if true, causes the server to send the JDK |
| 1622 | // 11 downgrade signal. |
| 1623 | SendJDK11DowngradeRandom bool |
| 1624 |
| 1625 | // ExpectJDK11DowngradeRandom is whether the client should expect the |
| 1626 | // server to send the JDK 11 downgrade signal. |
| 1627 | ExpectJDK11DowngradeRandom bool |
| 1628 |
| 1629 | // FailIfHelloRetryRequested causes a handshake failure if a server requests a |
| 1630 | // hello retry. |
| 1631 | FailIfHelloRetryRequested bool |
| 1632 |
| 1633 | // FailedIfCECPQ2Offered will cause a server to reject a ClientHello if CECPQ2 |
| 1634 | // is supported. |
| 1635 | FailIfCECPQ2Offered bool |
| 1636 |
| 1637 | // ExpectKeyShares, if not nil, lists (in order) the curves that a ClientHello |
| 1638 | // should have key shares for. |
| 1639 | ExpectedKeyShares []CurveID |
| 1640 |
| 1641 | // ExpectDelegatedCredentials, if true, requires that the handshake present |
| 1642 | // delegated credentials. |
| 1643 | ExpectDelegatedCredentials bool |
| 1644 |
| 1645 | // FailIfDelegatedCredentials, if true, causes a handshake failure if the |
| 1646 | // server returns delegated credentials. |
| 1647 | FailIfDelegatedCredentials bool |
| 1648 |
| 1649 | // DisableDelegatedCredentials, if true, disables client support for delegated |
| 1650 | // credentials. |
| 1651 | DisableDelegatedCredentials bool |
| 1652 |
| 1653 | // ExpectPQExperimentSignal specifies whether or not the post-quantum |
| 1654 | // experiment signal should be received by a client or server. |
| 1655 | ExpectPQExperimentSignal bool |
| 1656 | } |
| 1657 |
| 1658 | func (c *Config) serverInit() { |
| 1659 | if c.SessionTicketsDisabled { |
| 1660 | return |
| 1661 | } |
| 1662 |
| 1663 | // If the key has already been set then we have nothing to do. |
| 1664 | for _, b := range c.SessionTicketKey { |
| 1665 | if b != 0 { |
| 1666 | return |
| 1667 | } |
| 1668 | } |
| 1669 |
| 1670 | if _, err := io.ReadFull(c.rand(), c.SessionTicketKey[:]); err != nil { |
| 1671 | c.SessionTicketsDisabled = true |
| 1672 | } |
| 1673 | } |
| 1674 |
| 1675 | func (c *Config) rand() io.Reader { |
| 1676 | r := c.Rand |
| 1677 | if r == nil { |
| 1678 | return rand.Reader |
| 1679 | } |
| 1680 | return r |
| 1681 | } |
| 1682 |
| 1683 | func (c *Config) time() time.Time { |
| 1684 | t := c.Time |
| 1685 | if t == nil { |
| 1686 | t = time.Now |
| 1687 | } |
| 1688 | return t() |
| 1689 | } |
| 1690 |
| 1691 | func (c *Config) cipherSuites() []uint16 { |
| 1692 | s := c.CipherSuites |
| 1693 | if s == nil { |
| 1694 | s = defaultCipherSuites() |
| 1695 | } |
| 1696 | return s |
| 1697 | } |
| 1698 |
| 1699 | func (c *Config) minVersion(isDTLS bool) uint16 { |
| 1700 | ret := uint16(minVersion) |
| 1701 | if c != nil && c.MinVersion != 0 { |
| 1702 | ret = c.MinVersion |
| 1703 | } |
| 1704 | if isDTLS { |
| 1705 | // The lowest version of DTLS is 1.0. There is no DSSL 3.0. |
| 1706 | if ret < VersionTLS10 { |
| 1707 | return VersionTLS10 |
| 1708 | } |
| 1709 | // There is no such thing as DTLS 1.1. |
| 1710 | if ret == VersionTLS11 { |
| 1711 | return VersionTLS12 |
| 1712 | } |
| 1713 | } |
| 1714 | return ret |
| 1715 | } |
| 1716 |
| 1717 | func (c *Config) maxVersion(isDTLS bool) uint16 { |
| 1718 | ret := uint16(maxVersion) |
| 1719 | if c != nil && c.MaxVersion != 0 { |
| 1720 | ret = c.MaxVersion |
| 1721 | } |
| 1722 | if isDTLS { |
| 1723 | // We only implement up to DTLS 1.2. |
| 1724 | if ret > VersionTLS12 { |
| 1725 | return VersionTLS12 |
| 1726 | } |
| 1727 | // There is no such thing as DTLS 1.1. |
| 1728 | if ret == VersionTLS11 { |
| 1729 | return VersionTLS10 |
| 1730 | } |
| 1731 | } |
| 1732 | return ret |
| 1733 | } |
| 1734 |
| 1735 | var defaultCurvePreferences = []CurveID{CurveCECPQ2b, CurveCECPQ2, CurveX25519, CurveP256, CurveP384, CurveP521} |
| 1736 |
| 1737 | func (c *Config) curvePreferences() []CurveID { |
| 1738 | if c == nil || len(c.CurvePreferences) == 0 { |
| 1739 | return defaultCurvePreferences |
| 1740 | } |
| 1741 | return c.CurvePreferences |
| 1742 | } |
| 1743 |
| 1744 | func (c *Config) defaultCurves() map[CurveID]bool { |
| 1745 | defaultCurves := make(map[CurveID]bool) |
| 1746 | curves := c.DefaultCurves |
| 1747 | if c == nil || c.DefaultCurves == nil { |
| 1748 | curves = c.curvePreferences() |
| 1749 | } |
| 1750 | for _, curveID := range curves { |
| 1751 | defaultCurves[curveID] = true |
| 1752 | } |
| 1753 | return defaultCurves |
| 1754 | } |
| 1755 |
| 1756 | func wireToVersion(vers uint16, isDTLS bool) (uint16, bool) { |
| 1757 | if isDTLS { |
| 1758 | switch vers { |
| 1759 | case VersionDTLS12: |
| 1760 | return VersionTLS12, true |
| 1761 | case VersionDTLS10: |
| 1762 | return VersionTLS10, true |
| 1763 | } |
| 1764 | } else { |
| 1765 | switch vers { |
| 1766 | case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12, VersionTLS13: |
| 1767 | return vers, true |
| 1768 | } |
| 1769 | } |
| 1770 |
| 1771 | return 0, false |
| 1772 | } |
| 1773 |
| 1774 | // isSupportedVersion checks if the specified wire version is acceptable. If so, |
| 1775 | // it returns true and the corresponding protocol version. Otherwise, it returns |
| 1776 | // false. |
| 1777 | func (c *Config) isSupportedVersion(wireVers uint16, isDTLS bool) (uint16, bool) { |
| 1778 | vers, ok := wireToVersion(wireVers, isDTLS) |
| 1779 | if !ok || c.minVersion(isDTLS) > vers || vers > c.maxVersion(isDTLS) { |
| 1780 | return 0, false |
| 1781 | } |
| 1782 | return vers, true |
| 1783 | } |
| 1784 |
| 1785 | func (c *Config) supportedVersions(isDTLS bool) []uint16 { |
| 1786 | versions := allTLSWireVersions |
| 1787 | if isDTLS { |
| 1788 | versions = allDTLSWireVersions |
| 1789 | } |
| 1790 | var ret []uint16 |
| 1791 | for _, vers := range versions { |
| 1792 | if _, ok := c.isSupportedVersion(vers, isDTLS); ok { |
| 1793 | ret = append(ret, vers) |
| 1794 | } |
| 1795 | } |
| 1796 | return ret |
| 1797 | } |
| 1798 |
| 1799 | // getCertificateForName returns the best certificate for the given name, |
| 1800 | // defaulting to the first element of c.Certificates if there are no good |
| 1801 | // options. |
| 1802 | func (c *Config) getCertificateForName(name string) *Certificate { |
| 1803 | if len(c.Certificates) == 1 || c.NameToCertificate == nil { |
| 1804 | // There's only one choice, so no point doing any work. |
| 1805 | return &c.Certificates[0] |
| 1806 | } |
| 1807 |
| 1808 | name = strings.ToLower(name) |
| 1809 | for len(name) > 0 && name[len(name)-1] == '.' { |
| 1810 | name = name[:len(name)-1] |
| 1811 | } |
| 1812 |
| 1813 | if cert, ok := c.NameToCertificate[name]; ok { |
| 1814 | return cert |
| 1815 | } |
| 1816 |
| 1817 | // try replacing labels in the name with wildcards until we get a |
| 1818 | // match. |
| 1819 | labels := strings.Split(name, ".") |
| 1820 | for i := range labels { |
| 1821 | labels[i] = "*" |
| 1822 | candidate := strings.Join(labels, ".") |
| 1823 | if cert, ok := c.NameToCertificate[candidate]; ok { |
| 1824 | return cert |
| 1825 | } |
| 1826 | } |
| 1827 |
| 1828 | // If nothing matches, return the first certificate. |
| 1829 | return &c.Certificates[0] |
| 1830 | } |
| 1831 |
| 1832 | func (c *Config) signSignatureAlgorithms() []signatureAlgorithm { |
| 1833 | if c != nil && c.SignSignatureAlgorithms != nil { |
| 1834 | return c.SignSignatureAlgorithms |
| 1835 | } |
| 1836 | return supportedSignatureAlgorithms |
| 1837 | } |
| 1838 |
| 1839 | func (c *Config) verifySignatureAlgorithms() []signatureAlgorithm { |
| 1840 | if c != nil && c.VerifySignatureAlgorithms != nil { |
| 1841 | return c.VerifySignatureAlgorithms |
| 1842 | } |
| 1843 | return supportedSignatureAlgorithms |
| 1844 | } |
| 1845 |
| 1846 | // BuildNameToCertificate parses c.Certificates and builds c.NameToCertificate |
| 1847 | // from the CommonName and SubjectAlternateName fields of each of the leaf |
| 1848 | // certificates. |
| 1849 | func (c *Config) BuildNameToCertificate() { |
| 1850 | c.NameToCertificate = make(map[string]*Certificate) |
| 1851 | for i := range c.Certificates { |
| 1852 | cert := &c.Certificates[i] |
| 1853 | x509Cert, err := x509.ParseCertificate(cert.Certificate[0]) |
| 1854 | if err != nil { |
| 1855 | continue |
| 1856 | } |
| 1857 | if len(x509Cert.Subject.CommonName) > 0 { |
| 1858 | c.NameToCertificate[x509Cert.Subject.CommonName] = cert |
| 1859 | } |
| 1860 | for _, san := range x509Cert.DNSNames { |
| 1861 | c.NameToCertificate[san] = cert |
| 1862 | } |
| 1863 | } |
| 1864 | } |
| 1865 |
| 1866 | // A Certificate is a chain of one or more certificates, leaf first. |
| 1867 | type Certificate struct { |
| 1868 | Certificate [][]byte |
| 1869 | PrivateKey crypto.PrivateKey // supported types: *rsa.PrivateKey, *ecdsa.PrivateKey |
| 1870 | // OCSPStaple contains an optional OCSP response which will be served |
| 1871 | // to clients that request it. |
| 1872 | OCSPStaple []byte |
| 1873 | // SignedCertificateTimestampList contains an optional encoded |
| 1874 | // SignedCertificateTimestampList structure which will be |
| 1875 | // served to clients that request it. |
| 1876 | SignedCertificateTimestampList []byte |
| 1877 | // Leaf is the parsed form of the leaf certificate, which may be |
| 1878 | // initialized using x509.ParseCertificate to reduce per-handshake |
| 1879 | // processing for TLS clients doing client authentication. If nil, the |
| 1880 | // leaf certificate will be parsed as needed. |
| 1881 | Leaf *x509.Certificate |
| 1882 | } |
| 1883 |
| 1884 | // A TLS record. |
| 1885 | type record struct { |
| 1886 | contentType recordType |
| 1887 | major, minor uint8 |
| 1888 | payload []byte |
| 1889 | } |
| 1890 |
| 1891 | type handshakeMessage interface { |
| 1892 | marshal() []byte |
| 1893 | unmarshal([]byte) bool |
| 1894 | } |
| 1895 |
| 1896 | // lruSessionCache is a client or server session cache implementation |
| 1897 | // that uses an LRU caching strategy. |
| 1898 | type lruSessionCache struct { |
| 1899 | sync.Mutex |
| 1900 |
| 1901 | m map[string]*list.Element |
| 1902 | q *list.List |
| 1903 | capacity int |
| 1904 | } |
| 1905 |
| 1906 | type lruSessionCacheEntry struct { |
| 1907 | sessionKey string |
| 1908 | state interface{} |
| 1909 | } |
| 1910 |
| 1911 | // Put adds the provided (sessionKey, cs) pair to the cache. |
| 1912 | func (c *lruSessionCache) Put(sessionKey string, cs interface{}) { |
| 1913 | c.Lock() |
| 1914 | defer c.Unlock() |
| 1915 |
| 1916 | if elem, ok := c.m[sessionKey]; ok { |
| 1917 | entry := elem.Value.(*lruSessionCacheEntry) |
| 1918 | entry.state = cs |
| 1919 | c.q.MoveToFront(elem) |
| 1920 | return |
| 1921 | } |
| 1922 |
| 1923 | if c.q.Len() < c.capacity { |
| 1924 | entry := &lruSessionCacheEntry{sessionKey, cs} |
| 1925 | c.m[sessionKey] = c.q.PushFront(entry) |
| 1926 | return |
| 1927 | } |
| 1928 |
| 1929 | elem := c.q.Back() |
| 1930 | entry := elem.Value.(*lruSessionCacheEntry) |
| 1931 | delete(c.m, entry.sessionKey) |
| 1932 | entry.sessionKey = sessionKey |
| 1933 | entry.state = cs |
| 1934 | c.q.MoveToFront(elem) |
| 1935 | c.m[sessionKey] = elem |
| 1936 | } |
| 1937 |
| 1938 | // Get returns the value associated with a given key. It returns (nil, |
| 1939 | // false) if no value is found. |
| 1940 | func (c *lruSessionCache) Get(sessionKey string) (interface{}, bool) { |
| 1941 | c.Lock() |
| 1942 | defer c.Unlock() |
| 1943 |
| 1944 | if elem, ok := c.m[sessionKey]; ok { |
| 1945 | c.q.MoveToFront(elem) |
| 1946 | return elem.Value.(*lruSessionCacheEntry).state, true |
| 1947 | } |
| 1948 | return nil, false |
| 1949 | } |
| 1950 |
| 1951 | // lruClientSessionCache is a ClientSessionCache implementation that |
| 1952 | // uses an LRU caching strategy. |
| 1953 | type lruClientSessionCache struct { |
| 1954 | lruSessionCache |
| 1955 | } |
| 1956 |
| 1957 | func (c *lruClientSessionCache) Put(sessionKey string, cs *ClientSessionState) { |
| 1958 | c.lruSessionCache.Put(sessionKey, cs) |
| 1959 | } |
| 1960 |
| 1961 | func (c *lruClientSessionCache) Get(sessionKey string) (*ClientSessionState, bool) { |
| 1962 | cs, ok := c.lruSessionCache.Get(sessionKey) |
| 1963 | if !ok { |
| 1964 | return nil, false |
| 1965 | } |
| 1966 | return cs.(*ClientSessionState), true |
| 1967 | } |
| 1968 |
| 1969 | // lruServerSessionCache is a ServerSessionCache implementation that |
| 1970 | // uses an LRU caching strategy. |
| 1971 | type lruServerSessionCache struct { |
| 1972 | lruSessionCache |
| 1973 | } |
| 1974 |
| 1975 | func (c *lruServerSessionCache) Put(sessionId string, session *sessionState) { |
| 1976 | c.lruSessionCache.Put(sessionId, session) |
| 1977 | } |
| 1978 |
| 1979 | func (c *lruServerSessionCache) Get(sessionId string) (*sessionState, bool) { |
| 1980 | cs, ok := c.lruSessionCache.Get(sessionId) |
| 1981 | if !ok { |
| 1982 | return nil, false |
| 1983 | } |
| 1984 | return cs.(*sessionState), true |
| 1985 | } |
| 1986 |
| 1987 | // NewLRUClientSessionCache returns a ClientSessionCache with the given |
| 1988 | // capacity that uses an LRU strategy. If capacity is < 1, a default capacity |
| 1989 | // is used instead. |
| 1990 | func NewLRUClientSessionCache(capacity int) ClientSessionCache { |
| 1991 | const defaultSessionCacheCapacity = 64 |
| 1992 |
| 1993 | if capacity < 1 { |
| 1994 | capacity = defaultSessionCacheCapacity |
| 1995 | } |
| 1996 | return &lruClientSessionCache{ |
| 1997 | lruSessionCache{ |
| 1998 | m: make(map[string]*list.Element), |
| 1999 | q: list.New(), |
| 2000 | capacity: capacity, |
| 2001 | }, |
| 2002 | } |
| 2003 | } |
| 2004 |
| 2005 | // NewLRUServerSessionCache returns a ServerSessionCache with the given |
| 2006 | // capacity that uses an LRU strategy. If capacity is < 1, a default capacity |
| 2007 | // is used instead. |
| 2008 | func NewLRUServerSessionCache(capacity int) ServerSessionCache { |
| 2009 | const defaultSessionCacheCapacity = 64 |
| 2010 |
| 2011 | if capacity < 1 { |
| 2012 | capacity = defaultSessionCacheCapacity |
| 2013 | } |
| 2014 | return &lruServerSessionCache{ |
| 2015 | lruSessionCache{ |
| 2016 | m: make(map[string]*list.Element), |
| 2017 | q: list.New(), |
| 2018 | capacity: capacity, |
| 2019 | }, |
| 2020 | } |
| 2021 | } |
| 2022 |
| 2023 | // TODO(jsing): Make these available to both crypto/x509 and crypto/tls. |
| 2024 | type dsaSignature struct { |
| 2025 | R, S *big.Int |
| 2026 | } |
| 2027 |
| 2028 | type ecdsaSignature dsaSignature |
| 2029 |
| 2030 | var emptyConfig Config |
| 2031 |
| 2032 | func defaultConfig() *Config { |
| 2033 | return &emptyConfig |
| 2034 | } |
| 2035 |
| 2036 | var ( |
| 2037 | once sync.Once |
| 2038 | varDefaultCipherSuites []uint16 |
| 2039 | ) |
| 2040 |
| 2041 | func defaultCipherSuites() []uint16 { |
| 2042 | once.Do(initDefaultCipherSuites) |
| 2043 | return varDefaultCipherSuites |
| 2044 | } |
| 2045 |
| 2046 | func initDefaultCipherSuites() { |
| 2047 | for _, suite := range cipherSuites { |
| 2048 | if suite.flags&suitePSK == 0 { |
| 2049 | varDefaultCipherSuites = append(varDefaultCipherSuites, suite.id) |
| 2050 | } |
| 2051 | } |
| 2052 | } |
| 2053 |
| 2054 | func unexpectedMessageError(wanted, got interface{}) error { |
| 2055 | return fmt.Errorf("tls: received unexpected handshake message of type %T when waiting for %T", got, wanted) |
| 2056 | } |
| 2057 |
| 2058 | func isSupportedSignatureAlgorithm(sigAlg signatureAlgorithm, sigAlgs []signatureAlgorithm) bool { |
| 2059 | for _, s := range sigAlgs { |
| 2060 | if s == sigAlg { |
| 2061 | return true |
| 2062 | } |
| 2063 | } |
| 2064 | return false |
| 2065 | } |
| 2066 |
| 2067 | var ( |
| 2068 | // See RFC 8446, section 4.1.3. |
| 2069 | downgradeTLS13 = []byte{0x44, 0x4f, 0x57, 0x4e, 0x47, 0x52, 0x44, 0x01} |
| 2070 | downgradeTLS12 = []byte{0x44, 0x4f, 0x57, 0x4e, 0x47, 0x52, 0x44, 0x00} |
| 2071 |
| 2072 | // This is a non-standard randomly-generated value. |
| 2073 | downgradeJDK11 = []byte{0xed, 0xbf, 0xb4, 0xa8, 0xc2, 0x47, 0x10, 0xff} |
| 2074 | ) |
| 2075 |
| 2076 | func containsGREASE(values []uint16) bool { |
| 2077 | for _, v := range values { |
| 2078 | if isGREASEValue(v) { |
| 2079 | return true |
| 2080 | } |
| 2081 | } |
| 2082 | return false |
| 2083 | } |
| 2084 |
| 2085 | func checkRSAPSSSupport(support RSAPSSSupport, sigAlgs, sigAlgsCert []signatureAlgorithm) error { |
| 2086 | if sigAlgsCert == nil { |
| 2087 | sigAlgsCert = sigAlgs |
| 2088 | } else if eqSignatureAlgorithms(sigAlgs, sigAlgsCert) { |
| 2089 | // The peer should have only sent the list once. |
| 2090 | return errors.New("tls: signature_algorithms and signature_algorithms_cert extensions were identical") |
| 2091 | } |
| 2092 |
| 2093 | if support == RSAPSSSupportAny { |
| 2094 | return nil |
| 2095 | } |
| 2096 |
| 2097 | var foundPSS, foundPSSCert bool |
| 2098 | for _, sigAlg := range sigAlgs { |
| 2099 | if sigAlg == signatureRSAPSSWithSHA256 || sigAlg == signatureRSAPSSWithSHA384 || sigAlg == signatureRSAPSSWithSHA512 { |
| 2100 | foundPSS = true |
| 2101 | break |
| 2102 | } |
| 2103 | } |
| 2104 | for _, sigAlg := range sigAlgsCert { |
| 2105 | if sigAlg == signatureRSAPSSWithSHA256 || sigAlg == signatureRSAPSSWithSHA384 || sigAlg == signatureRSAPSSWithSHA512 { |
| 2106 | foundPSSCert = true |
| 2107 | break |
| 2108 | } |
| 2109 | } |
| 2110 |
| 2111 | expectPSS := support != RSAPSSSupportNone |
| 2112 | if foundPSS != expectPSS { |
| 2113 | if expectPSS { |
| 2114 | return errors.New("tls: peer did not support PSS") |
| 2115 | } else { |
| 2116 | return errors.New("tls: peer unexpectedly supported PSS") |
| 2117 | } |
| 2118 | } |
| 2119 |
| 2120 | expectPSSCert := support == RSAPSSSupportBoth |
| 2121 | if foundPSSCert != expectPSSCert { |
| 2122 | if expectPSSCert { |
| 2123 | return errors.New("tls: peer did not support PSS in certificates") |
| 2124 | } else { |
| 2125 | return errors.New("tls: peer unexpectedly supported PSS in certificates") |
| 2126 | } |
| 2127 | } |
| 2128 |
| 2129 | return nil |
| 2130 | } |
| 2131 |