Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 1 | // Copyright 2009 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Kenny Root | e99801b | 2015-11-06 15:31:15 -0800 | [diff] [blame] | 5 | package runner |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 6 | |
| 7 | import ( |
| 8 | "container/list" |
| 9 | "crypto" |
| 10 | "crypto/ecdsa" |
| 11 | "crypto/rand" |
| 12 | "crypto/x509" |
Robert Sloan | 5cbb5c8 | 2018-04-24 11:35:46 -0700 | [diff] [blame] | 13 | "errors" |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 27 | VersionTLS13 = 0x0304 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 28 | ) |
| 29 | |
Robert Sloan | f6200e7 | 2017-07-10 08:09:18 -0700 | [diff] [blame] | 30 | const ( |
| 31 | VersionDTLS10 = 0xfeff |
| 32 | VersionDTLS12 = 0xfefd |
| 33 | ) |
| 34 | |
Robert Sloan | f6200e7 | 2017-07-10 08:09:18 -0700 | [diff] [blame] | 35 | var allTLSWireVersions = []uint16{ |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 36 | VersionTLS13, |
Robert Sloan | f6200e7 | 2017-07-10 08:09:18 -0700 | [diff] [blame] | 37 | VersionTLS12, |
| 38 | VersionTLS11, |
| 39 | VersionTLS10, |
| 40 | VersionSSL30, |
| 41 | } |
| 42 | |
| 43 | var allDTLSWireVersions = []uint16{ |
| 44 | VersionDTLS12, |
| 45 | VersionDTLS10, |
| 46 | } |
| 47 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 56 | maxVersion = VersionTLS13 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 57 | ) |
| 58 | |
| 59 | // TLS record types. |
| 60 | type recordType uint8 |
| 61 | |
| 62 | const ( |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 63 | recordTypeChangeCipherSpec recordType = 20 |
| 64 | recordTypeAlert recordType = 21 |
| 65 | recordTypeHandshake recordType = 22 |
| 66 | recordTypeApplicationData recordType = 23 |
| 67 | recordTypePlaintextHandshake recordType = 24 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 68 | ) |
| 69 | |
| 70 | // TLS handshake message types. |
| 71 | const ( |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 72 | typeHelloRequest uint8 = 0 |
| 73 | typeClientHello uint8 = 1 |
| 74 | typeServerHello uint8 = 2 |
| 75 | typeHelloVerifyRequest uint8 = 3 |
| 76 | typeNewSessionTicket uint8 = 4 |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 77 | typeEndOfEarlyData uint8 = 5 |
| 78 | typeHelloRetryRequest uint8 = 6 |
| 79 | typeEncryptedExtensions uint8 = 8 |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 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 |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 88 | typeKeyUpdate uint8 = 24 |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 89 | typeCompressedCertificate uint8 = 25 // Not IANA assigned |
| 90 | typeNextProtocol uint8 = 67 // Not IANA assigned |
| 91 | typeChannelID uint8 = 203 // Not IANA assigned |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 92 | typeMessageHash uint8 = 254 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 |
Robert Sloan | d1d118f | 2017-09-11 09:00:48 -0700 | [diff] [blame] | 110 | extensionPadding uint16 = 21 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 111 | extensionExtendedMasterSecret uint16 = 23 |
Robert Sloan | 978112c | 2018-01-22 12:53:01 -0800 | [diff] [blame] | 112 | extensionTokenBinding uint16 = 24 |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 113 | extensionCompressedCertAlgs uint16 = 27 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 114 | extensionSessionTicket uint16 = 35 |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 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 |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 123 | extensionCustom uint16 = 1234 // not IANA assigned |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 124 | extensionNextProtoNeg uint16 = 13172 // not IANA assigned |
| 125 | extensionRenegotiationInfo uint16 = 0xff01 |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 126 | extensionQUICTransportParams uint16 = 0xffa5 // draft-ietf-quic-tls-13 |
| 127 | extensionChannelID uint16 = 30032 // not IANA assigned |
Robert Sloan | 4c22c5f | 2019-03-01 15:53:37 -0800 | [diff] [blame] | 128 | extensionDelegatedCredentials uint16 = 0xff02 // not IANA assigned |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame^] | 129 | extensionPQExperimentSignal uint16 = 54538 |
David Benjamin | 95add82 | 2016-10-19 01:09:12 -0400 | [diff] [blame] | 130 | ) |
| 131 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 132 | // TLS signaling cipher suite values |
| 133 | const ( |
| 134 | scsvRenegotiation uint16 = 0x00ff |
| 135 | ) |
| 136 | |
Robert Sloan | d5c2215 | 2017-11-13 09:22:12 -0800 | [diff] [blame] | 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 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 ( |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame^] | 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 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 155 | ) |
| 156 | |
| 157 | // TLS Elliptic Curve Point Formats |
| 158 | // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-9 |
| 159 | const ( |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 160 | pointFormatUncompressed uint8 = 0 |
| 161 | pointFormatCompressedPrime uint8 = 1 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 190 | const ( |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 |
David Benjamin | 7c0d06c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 205 | signatureRSAPSSWithSHA256 signatureAlgorithm = 0x0804 |
| 206 | signatureRSAPSSWithSHA384 signatureAlgorithm = 0x0805 |
| 207 | signatureRSAPSSWithSHA512 signatureAlgorithm = 0x0806 |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 208 | |
| 209 | // EdDSA algorithms |
David Benjamin | 7c0d06c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 210 | signatureEd25519 signatureAlgorithm = 0x0807 |
| 211 | signatureEd448 signatureAlgorithm = 0x0808 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 212 | ) |
| 213 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 214 | // supportedSignatureAlgorithms contains the default supported signature |
| 215 | // algorithms. |
| 216 | var supportedSignatureAlgorithms = []signatureAlgorithm{ |
| 217 | signatureRSAPSSWithSHA256, |
| 218 | signatureRSAPKCS1WithSHA256, |
| 219 | signatureECDSAWithP256AndSHA256, |
| 220 | signatureRSAPKCS1WithSHA1, |
| 221 | signatureECDSAWithSHA1, |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 222 | signatureEd25519, |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 231 | // PskKeyExchangeMode values (see RFC 8446, section 4.2.9) |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 232 | const ( |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 233 | pskKEMode = 0 |
| 234 | pskDHEKEMode = 1 |
| 235 | ) |
| 236 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 237 | // KeyUpdateRequest values (see RFC 8446, section 4.6.3) |
David Benjamin | 95add82 | 2016-10-19 01:09:12 -0400 | [diff] [blame] | 238 | const ( |
| 239 | keyUpdateNotRequested = 0 |
| 240 | keyUpdateRequested = 1 |
| 241 | ) |
| 242 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 |
Robert Sloan | 978112c | 2018-01-22 12:53:01 -0800 | [diff] [blame] | 256 | TokenBindingNegotiated bool // whether Token Binding was negotiated |
| 257 | TokenBindingParam uint8 // the negotiated Token Binding key parameter |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 258 | SRTPProtectionProfile uint16 // the negotiated DTLS-SRTP protection profile |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 259 | TLSUnique []byte // the tls-unique channel binding |
| 260 | SCTList []byte // signed certificate timestamp list |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 261 | PeerSignatureAlgorithm signatureAlgorithm // algorithm used by the peer in the handshake |
| 262 | CurveID CurveID // the curve used in ECDHE |
Robert Sloan | 8542c08 | 2018-02-05 09:07:34 -0800 | [diff] [blame] | 263 | QUICTransportParams []byte // the QUIC transport params received from the peer |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 |
Robert Sloan | db4251a | 2017-09-18 09:38:15 -0700 | [diff] [blame] | 284 | wireVersion uint16 // Wire SSL/TLS version negotiated for the session |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 290 | sctList []byte |
| 291 | ocspResponse []byte |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 292 | earlyALPN string |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 293 | ticketCreationTime time.Time |
| 294 | ticketExpiration time.Time |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 295 | ticketAgeAdd uint32 |
Robert Sloan | 47f43ed | 2017-02-06 14:55:15 -0800 | [diff] [blame] | 296 | maxEarlyDataSize uint32 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 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 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
Robert Sloan | 978112c | 2018-01-22 12:53:01 -0800 | [diff] [blame] | 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 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
Robert Sloan | 47f43ed | 2017-02-06 14:55:15 -0800 | [diff] [blame] | 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 |
Robert Sloan | b1b54b8 | 2017-11-06 13:50:02 -0800 | [diff] [blame] | 483 | // the early_data extension in the NewSessionTicketMsg will be omitted. |
Robert Sloan | 47f43ed | 2017-02-06 14:55:15 -0800 | [diff] [blame] | 484 | MaxEarlyDataSize uint32 |
| 485 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 486 | // SRTPProtectionProfiles, if not nil, is the list of SRTP |
| 487 | // protection profiles to offer in DTLS-SRTP. |
| 488 | SRTPProtectionProfiles []uint16 |
| 489 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 497 | |
Robert Sloan | 8542c08 | 2018-02-05 09:07:34 -0800 | [diff] [blame] | 498 | // QUICTransportParams, if not empty, will be sent in the QUIC |
| 499 | // transport parameters extension. |
| 500 | QUICTransportParams []byte |
| 501 | |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 502 | CertCompressionAlgs map[uint16]CertCompressionAlg |
| 503 | |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame^] | 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 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 527 | type RSABadValue int |
| 528 | |
| 529 | const ( |
| 530 | RSABadValueNone RSABadValue = iota |
| 531 | RSABadValueCorrupt |
| 532 | RSABadValueTooLong |
| 533 | RSABadValueTooShort |
Robert Sloan | 921ef2c | 2017-10-17 09:02:20 -0700 | [diff] [blame] | 534 | RSABadValueWrongVersion1 |
| 535 | RSABadValueWrongVersion2 |
| 536 | RSABadValueWrongBlockType |
| 537 | RSABadValueWrongLeadingByte |
| 538 | RSABadValueNoZero |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 539 | NumRSABadValues |
| 540 | ) |
| 541 | |
Robert Sloan | 5cbb5c8 | 2018-04-24 11:35:46 -0700 | [diff] [blame] | 542 | type RSAPSSSupport int |
| 543 | |
| 544 | const ( |
| 545 | RSAPSSSupportAny RSAPSSSupport = iota |
| 546 | RSAPSSSupportNone |
| 547 | RSAPSSSupportOnlineSignatureOnly |
| 548 | RSAPSSSupportBoth |
| 549 | ) |
| 550 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 551 | type ProtocolBugs struct { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 552 | // InvalidSignature specifies that the signature in a ServerKeyExchange |
| 553 | // or CertificateVerify message should be invalid. |
| 554 | InvalidSignature bool |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 555 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 560 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 561 | // InvalidECDHPoint, if true, causes the ECC points in |
| 562 | // ServerKeyExchange or ClientKeyExchange messages to be invalid. |
| 563 | InvalidECDHPoint bool |
| 564 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 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 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 602 | // SkipServerKeyExchange causes the server to skip sending |
| 603 | // ServerKeyExchange messages. |
| 604 | SkipServerKeyExchange bool |
| 605 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 606 | // SkipNewSessionTicket causes the server to skip sending the |
| 607 | // NewSessionTicket message despite promising to in ServerHello. |
| 608 | SkipNewSessionTicket bool |
| 609 | |
Robert Sloan | 921ef2c | 2017-10-17 09:02:20 -0700 | [diff] [blame] | 610 | // UseFirstSessionTicket causes the client to cache only the first session |
| 611 | // ticket received. |
| 612 | UseFirstSessionTicket bool |
| 613 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 614 | // SkipClientCertificate causes the client to skip the Certificate |
| 615 | // message. |
| 616 | SkipClientCertificate bool |
| 617 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 623 | // SkipFinished causes the implementation to skip sending the Finished |
| 624 | // message. |
| 625 | SkipFinished bool |
| 626 | |
Robert Sloan | b1b54b8 | 2017-11-06 13:50:02 -0800 | [diff] [blame] | 627 | // SkipEndOfEarlyData causes the implementation to skip |
| 628 | // end_of_early_data. |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 629 | SkipEndOfEarlyData bool |
| 630 | |
Robert Sloan | b1b54b8 | 2017-11-06 13:50:02 -0800 | [diff] [blame] | 631 | // NonEmptyEndOfEarlyData causes the implementation to end an extra byte in the |
| 632 | // EndOfEarlyData. |
| 633 | NonEmptyEndOfEarlyData bool |
| 634 | |
Robert Sloan | 8437709 | 2017-08-14 09:33:19 -0700 | [diff] [blame] | 635 | // SkipCertificateVerify, if true causes peer to skip sending a |
| 636 | // CertificateVerify message after the Certificate message. |
| 637 | SkipCertificateVerify bool |
| 638 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 639 | // EarlyChangeCipherSpec causes the client to send an early |
| 640 | // ChangeCipherSpec message before the ClientKeyExchange. A value of |
Robert Sloan | 73fa5d6 | 2017-10-09 13:53:06 -0700 | [diff] [blame] | 641 | // zero disables this behavior. One and two configure variants for |
| 642 | // 1.0.1 and 0.9.8 modes, respectively. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 643 | EarlyChangeCipherSpec int |
| 644 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 | |
Robert Sloan | fe7cd21 | 2017-08-07 09:03:39 -0700 | [diff] [blame] | 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 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 655 | // FragmentAcrossChangeCipherSpec causes the implementation to fragment |
| 656 | // the Finished (or NextProto) message around the ChangeCipherSpec |
| 657 | // messages. |
| 658 | FragmentAcrossChangeCipherSpec bool |
| 659 | |
Robert Sloan | d5c2215 | 2017-11-13 09:22:12 -0800 | [diff] [blame] | 660 | // SendExtraChangeCipherSpec causes the implementation to send extra |
| 661 | // ChangeCipherSpec messages. |
| 662 | SendExtraChangeCipherSpec int |
| 663 | |
Robert Sloan | 99319a1 | 2017-11-27 10:32:46 -0800 | [diff] [blame] | 664 | // SendPostHandshakeChangeCipherSpec causes the implementation to send |
| 665 | // a ChangeCipherSpec record before every application data record. |
| 666 | SendPostHandshakeChangeCipherSpec bool |
| 667 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 690 | // SendRenegotiationSCSV causes the client to include the renegotiation |
| 691 | // SCSV in the ClientHello. |
| 692 | SendRenegotiationSCSV bool |
| 693 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 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|. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 710 | // DoubleAlert will cause all alerts to be sent as two copies packed |
| 711 | // within one record. |
| 712 | DoubleAlert bool |
| 713 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 714 | // SendSpuriousAlert, if non-zero, will cause an spurious, unwanted |
| 715 | // alert to be sent. |
| 716 | SendSpuriousAlert alert |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 717 | |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 718 | // BadRSAClientKeyExchange causes the client to send a corrupted RSA |
| 719 | // ClientKeyExchange which would not pass padding checks. |
| 720 | BadRSAClientKeyExchange RSABadValue |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 726 | // SendClientVersion, if non-zero, causes the client to send the |
| 727 | // specified value in the ClientHello version field. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 728 | SendClientVersion uint16 |
| 729 | |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 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 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 738 | // NegotiateVersion, if non-zero, causes the server to negotiate the |
Robert Sloan | f6200e7 | 2017-07-10 08:09:18 -0700 | [diff] [blame] | 739 | // specifed wire version rather than the version supported by either |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 740 | // peer. |
| 741 | NegotiateVersion uint16 |
| 742 | |
| 743 | // NegotiateVersionOnRenego, if non-zero, causes the server to negotiate |
Robert Sloan | f6200e7 | 2017-07-10 08:09:18 -0700 | [diff] [blame] | 744 | // the specified wire version on renegotiation rather than retaining it. |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 745 | NegotiateVersionOnRenego uint16 |
| 746 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 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 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 760 | // ExpectServerName, if not empty, is the hostname the client |
| 761 | // must specify in the server_name extension. |
| 762 | ExpectServerName string |
| 763 | |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 764 | // SwapNPNAndALPN switches the relative order between NPN and ALPN in |
| 765 | // both ClientHello and ServerHello. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 766 | SwapNPNAndALPN bool |
| 767 | |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 768 | // ALPNProtocol, if not nil, sets the ALPN protocol that a server will |
| 769 | // return. |
| 770 | ALPNProtocol *string |
| 771 | |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 781 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 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) |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 785 | |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 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 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 796 | |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame] | 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 |
Robert Sloan | 309a31e | 2018-01-29 10:22:47 -0800 | [diff] [blame] | 802 | // connection if there is not a session ID in the ClientHello. |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame] | 803 | ExpectClientHelloSessionID bool |
| 804 | |
Robert Sloan | 309a31e | 2018-01-29 10:22:47 -0800 | [diff] [blame] | 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 | |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 | |
Robert Sloan | b1b54b8 | 2017-11-06 13:50:02 -0800 | [diff] [blame] | 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 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 826 | // they didn't support an extended master secret in the initial |
| 827 | // handshake. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 828 | NoExtendedMasterSecret bool |
| 829 | |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 |
Robert Sloan | f6200e7 | 2017-07-10 08:09:18 -0700 | [diff] [blame] | 840 | // renegotiation handshake to be incorrect at the start. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 841 | BadRenegotiationInfo bool |
| 842 | |
Robert Sloan | f6200e7 | 2017-07-10 08:09:18 -0700 | [diff] [blame] | 843 | // BadRenegotiationInfoEnd causes the renegotiation extension value in |
| 844 | // a renegotiation handshake to be incorrect at the end. |
| 845 | BadRenegotiationInfoEnd bool |
| 846 | |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 847 | // NoRenegotiationInfo disables renegotiation info support in all |
| 848 | // handshakes. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 849 | NoRenegotiationInfo bool |
| 850 | |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 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 | |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 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 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 868 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 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 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 883 | // NoSignatureAlgorithms, if true, causes the client to omit the |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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. |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 889 | NoSignatureAlgorithms bool |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 890 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 891 | // NoSupportedCurves, if true, causes the client to omit the |
| 892 | // supported_curves extension. |
| 893 | NoSupportedCurves bool |
| 894 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 900 | // ExpectInitialRecordVersion, if non-zero, is the expected value of |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 901 | // record-layer version field before the protocol version is determined. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 902 | ExpectInitialRecordVersion uint16 |
| 903 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 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 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 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 | |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 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 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 931 | // be sent immediately after ChangeCipherSpec. |
| 932 | AppDataAfterChangeCipherSpec []byte |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 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 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 951 | // ReverseHandshakeFragments, if true, causes handshake fragments in |
| 952 | // DTLS to be reversed within a flight. |
| 953 | ReverseHandshakeFragments bool |
| 954 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 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 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 960 | // RetransmitFinished, if true, causes the DTLS Finished message to be |
| 961 | // sent twice. |
| 962 | RetransmitFinished bool |
| 963 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 964 | // SendInvalidRecordType, if true, causes a record with an invalid |
| 965 | // content type to be sent immediately following the handshake. |
| 966 | SendInvalidRecordType bool |
| 967 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 968 | // SendWrongMessageType, if non-zero, causes messages of the specified |
| 969 | // type to be sent with the wrong value. |
| 970 | SendWrongMessageType byte |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 971 | |
David Benjamin | 7c0d06c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 972 | // SendTrailingMessageData, if non-zero, causes messages of the |
| 973 | // specified type to be sent with trailing data. |
| 974 | SendTrailingMessageData byte |
| 975 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 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 | |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 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 |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 988 | |
| 989 | // SendEmptyFragments, if true, causes handshakes to include empty |
| 990 | // fragments in DTLS. |
| 991 | SendEmptyFragments bool |
| 992 | |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 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 |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 997 | |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 998 | // FailIfResumeOnRenego, if true, causes renegotiations to fail if the |
| 999 | // client offers a resumption or the server accepts one. |
| 1000 | FailIfResumeOnRenego bool |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 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 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 1014 | // BadFinished, if true, causes the Finished hash to be broken. |
| 1015 | BadFinished bool |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 1016 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1017 | // PackHandshakeFragments, if true, causes handshake fragments in DTLS |
| 1018 | // to be packed into individual handshake records, up to the specified |
| 1019 | // record size. |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 1020 | PackHandshakeFragments int |
| 1021 | |
Robert Sloan | 921ef2c | 2017-10-17 09:02:20 -0700 | [diff] [blame] | 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. |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 1025 | PackHandshakeRecords int |
| 1026 | |
Robert Sloan | 921ef2c | 2017-10-17 09:02:20 -0700 | [diff] [blame] | 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 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 | |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 1042 | // AdvertiseAllConfiguredCiphers, if true, causes the client to |
| 1043 | // advertise all configured cipher suite values. |
| 1044 | AdvertiseAllConfiguredCiphers bool |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 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 | |
David Benjamin | 95add82 | 2016-10-19 01:09:12 -0400 | [diff] [blame] | 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 | |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 1066 | // ExpectedCustomExtension, if not nil, contains the expected contents |
| 1067 | // of a custom extension. |
| 1068 | ExpectedCustomExtension *string |
| 1069 | |
David Benjamin | 95add82 | 2016-10-19 01:09:12 -0400 | [diff] [blame] | 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 | |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 1078 | // NoCloseNotify, if true, causes the close_notify alert to be skipped |
| 1079 | // on connection shutdown. |
| 1080 | NoCloseNotify bool |
| 1081 | |
David Benjamin | d316cba | 2016-06-02 16:17:39 -0400 | [diff] [blame] | 1082 | // SendAlertOnShutdown, if non-zero, is the alert to send instead of |
| 1083 | // close_notify on shutdown. |
| 1084 | SendAlertOnShutdown alert |
| 1085 | |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 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 |
Kenny Root | e99801b | 2015-11-06 15:31:15 -0800 | [diff] [blame] | 1098 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 | |
David Benjamin | 95add82 | 2016-10-19 01:09:12 -0400 | [diff] [blame] | 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 | |
Kenny Root | e99801b | 2015-11-06 15:31:15 -0800 | [diff] [blame] | 1108 | // SendEmptySessionTicket, if true, causes the server to send an empty |
| 1109 | // session ticket. |
| 1110 | SendEmptySessionTicket bool |
| 1111 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1112 | // SendPSKKeyExchangeModes, if present, determines the PSK key exchange modes |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 1113 | // to send. |
| 1114 | SendPSKKeyExchangeModes []byte |
| 1115 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1116 | // ExpectNoNewSessionTicket, if present, means that the client will fail upon |
| 1117 | // receipt of a NewSessionTicket message. |
| 1118 | ExpectNoNewSessionTicket bool |
| 1119 | |
Robert Sloan | b1b54b8 | 2017-11-06 13:50:02 -0800 | [diff] [blame] | 1120 | // DuplicateTicketEarlyData causes an extra empty extension of early_data to |
| 1121 | // be sent in NewSessionTicket. |
| 1122 | DuplicateTicketEarlyData bool |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 1123 | |
Robert Sloan | b1b54b8 | 2017-11-06 13:50:02 -0800 | [diff] [blame] | 1124 | // ExpectTicketEarlyData, if true, means that the client will fail upon |
| 1125 | // absence of the early_data extension. |
| 1126 | ExpectTicketEarlyData bool |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 1127 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1128 | // ExpectTicketAge, if non-zero, is the expected age of the ticket that the |
| 1129 | // server receives from the client. |
| 1130 | ExpectTicketAge time.Duration |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 1131 | |
Robert Sloan | 1c9db53 | 2017-03-13 08:03:59 -0700 | [diff] [blame] | 1132 | // SendTicketAge, if non-zero, is the ticket age to be sent by the |
| 1133 | // client. |
| 1134 | SendTicketAge time.Duration |
| 1135 | |
Kenny Root | e99801b | 2015-11-06 15:31:15 -0800 | [diff] [blame] | 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 |
Adam Langley | fad6327 | 2015-11-12 12:15:39 -0800 | [diff] [blame] | 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 |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 1145 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 | |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 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 |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1158 | |
| 1159 | // RequireSessionTickets, if true, causes the client to require new |
| 1160 | // sessions use session tickets instead of session IDs. |
| 1161 | RequireSessionTickets bool |
| 1162 | |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 1163 | // RequireSessionIDs, if true, causes the client to require new sessions use |
| 1164 | // session IDs instead of session tickets. |
| 1165 | RequireSessionIDs bool |
| 1166 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1167 | // NullAllCiphers, if true, causes every cipher to behave like the null |
| 1168 | // cipher. |
| 1169 | NullAllCiphers bool |
David Benjamin | d316cba | 2016-06-02 16:17:39 -0400 | [diff] [blame] | 1170 | |
| 1171 | // SendSCTListOnResume, if not nil, causes the server to send the |
| 1172 | // supplied SCT list in resumption handshakes. |
| 1173 | SendSCTListOnResume []byte |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1174 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 1175 | // SendSCTListOnRenegotiation, if not nil, causes the server to send the |
| 1176 | // supplied SCT list on renegotiation. |
| 1177 | SendSCTListOnRenegotiation []byte |
| 1178 | |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 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 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 1184 | // SendOCSPResponseOnResume, if not nil, causes the server to send the |
| 1185 | // supplied OCSP response on renegotiation. |
| 1186 | SendOCSPResponseOnRenegotiation []byte |
| 1187 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 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 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 | |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 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 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1261 | // ExtraPSKIdentity, if true, causes the client to send an extra PSK |
| 1262 | // identity. |
| 1263 | ExtraPSKIdentity bool |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 1264 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1284 | // SendEarlyAlert, if true, sends a fatal alert after the ClientHello. |
| 1285 | SendEarlyAlert bool |
| 1286 | |
Robert Sloan | 47f43ed | 2017-02-06 14:55:15 -0800 | [diff] [blame] | 1287 | // SendFakeEarlyDataLength, if non-zero, is the amount of early data to |
| 1288 | // send after the ClientHello. |
| 1289 | SendFakeEarlyDataLength int |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1290 | |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 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 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 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 | |
Robert Sloan | 47f43ed | 2017-02-06 14:55:15 -0800 | [diff] [blame] | 1307 | // SendEarlyData causes a TLS 1.3 client to send the provided data |
| 1308 | // in application data records immediately after the ClientHello, |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 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. |
Robert Sloan | 47f43ed | 2017-02-06 14:55:15 -0800 | [diff] [blame] | 1311 | SendEarlyData [][]byte |
| 1312 | |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 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 | |
Robert Sloan | 47f43ed | 2017-02-06 14:55:15 -0800 | [diff] [blame] | 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 | |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 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 | |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 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 | |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 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 |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 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 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 | |
David Benjamin | 95add82 | 2016-10-19 01:09:12 -0400 | [diff] [blame] | 1366 | // AlwaysSendHelloRetryRequest, if true, causes a HelloRetryRequest to |
| 1367 | // be sent by the server, even if empty. |
| 1368 | AlwaysSendHelloRetryRequest bool |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1369 | |
| 1370 | // SecondHelloRetryRequest, if true, causes the TLS 1.3 server to send |
| 1371 | // two HelloRetryRequests instead of one. |
| 1372 | SecondHelloRetryRequest bool |
| 1373 | |
David Benjamin | 95add82 | 2016-10-19 01:09:12 -0400 | [diff] [blame] | 1374 | // SendHelloRetryRequestCurve, if non-zero, causes the server to send |
| 1375 | // the specified curve in a HelloRetryRequest. |
| 1376 | SendHelloRetryRequestCurve CurveID |
| 1377 | |
Robert Sloan | b1b54b8 | 2017-11-06 13:50:02 -0800 | [diff] [blame] | 1378 | // SendHelloRetryRequestCipherSuite, if non-zero, causes the server to send |
| 1379 | // the specified cipher suite in a HelloRetryRequest. |
| 1380 | SendHelloRetryRequestCipherSuite uint16 |
| 1381 | |
David Benjamin | 95add82 | 2016-10-19 01:09:12 -0400 | [diff] [blame] | 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 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1390 | // SendServerHelloVersion, if non-zero, causes the server to send the |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 1391 | // specified value in ServerHello version field. |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1392 | SendServerHelloVersion uint16 |
| 1393 | |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 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 |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 1403 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 | |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1417 | // SendExtraFinished, if true, causes an extra Finished message to be |
| 1418 | // sent. |
| 1419 | SendExtraFinished bool |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1420 | |
| 1421 | // SendRequestContext, if not empty, is the request context to send in |
| 1422 | // a TLS 1.3 CertificateRequest. |
| 1423 | SendRequestContext []byte |
| 1424 | |
Robert Sloan | b1b54b8 | 2017-11-06 13:50:02 -0800 | [diff] [blame] | 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 | |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 |
David Benjamin | 7c0d06c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1440 | |
Robert Sloan | f6200e7 | 2017-07-10 08:09:18 -0700 | [diff] [blame] | 1441 | // SendCompressionMethod is the compression method to send in the |
| 1442 | // ServerHello. |
| 1443 | SendCompressionMethod byte |
| 1444 | |
David Benjamin | 7c0d06c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 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 |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 1453 | |
| 1454 | // InvalidChannelIDSignature, if true, causes the client to generate an |
| 1455 | // invalid Channel ID signature. |
| 1456 | InvalidChannelIDSignature bool |
| 1457 | |
David Benjamin | 95add82 | 2016-10-19 01:09:12 -0400 | [diff] [blame] | 1458 | // ExpectGREASE, if true, causes messages without GREASE values to be |
| 1459 | // rejected. See draft-davidben-tls-grease-01. |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 1460 | ExpectGREASE bool |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1461 | |
| 1462 | // SendShortPSKBinder, if true, causes the client to send a PSK binder |
| 1463 | // that is one byte shorter than it should be. |
| 1464 | SendShortPSKBinder bool |
| 1465 | |
| 1466 | // SendInvalidPSKBinder, if true, causes the client to send an invalid |
| 1467 | // PSK binder. |
| 1468 | SendInvalidPSKBinder bool |
| 1469 | |
| 1470 | // SendNoPSKBinder, if true, causes the client to send no PSK binders. |
| 1471 | SendNoPSKBinder bool |
| 1472 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1473 | // SendExtraPSKBinder, if true, causes the client to send an extra PSK |
| 1474 | // binder. |
| 1475 | SendExtraPSKBinder bool |
| 1476 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1477 | // PSKBinderFirst, if true, causes the client to send the PSK Binder |
| 1478 | // extension as the first extension instead of the last extension. |
| 1479 | PSKBinderFirst bool |
| 1480 | |
| 1481 | // NoOCSPStapling, if true, causes the client to not request OCSP |
| 1482 | // stapling. |
| 1483 | NoOCSPStapling bool |
| 1484 | |
| 1485 | // NoSignedCertificateTimestamps, if true, causes the client to not |
| 1486 | // request signed certificate timestamps. |
| 1487 | NoSignedCertificateTimestamps bool |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 1488 | |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 1489 | // SendSupportedPointFormats, if not nil, is the list of supported point |
| 1490 | // formats to send in ClientHello or ServerHello. If set to a non-nil |
| 1491 | // empty slice, no extension will be sent. |
| 1492 | SendSupportedPointFormats []byte |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 1493 | |
Robert Sloan | ae1abf9 | 2017-10-05 12:50:08 -0700 | [diff] [blame] | 1494 | // SendServerSupportedCurves, if true, causes the server to send its |
| 1495 | // supported curves list in the ServerHello (TLS 1.2) or |
| 1496 | // EncryptedExtensions (TLS 1.3) message. This is invalid in TLS 1.2 and |
| 1497 | // valid in TLS 1.3. |
| 1498 | SendServerSupportedCurves bool |
| 1499 | |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 1500 | // MaxReceivePlaintext, if non-zero, is the maximum plaintext record |
| 1501 | // length accepted from the peer. |
| 1502 | MaxReceivePlaintext int |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 1503 | |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 1504 | // ExpectPackedEncryptedHandshake, if non-zero, requires that the peer maximally |
| 1505 | // pack their encrypted handshake messages, fitting at most the |
| 1506 | // specified number of plaintext bytes per record. |
| 1507 | ExpectPackedEncryptedHandshake int |
| 1508 | |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 1509 | // SendTicketLifetime, if non-zero, is the ticket lifetime to send in |
| 1510 | // NewSessionTicket messages. |
| 1511 | SendTicketLifetime time.Duration |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 1512 | |
| 1513 | // SendServerNameAck, if true, causes the server to acknowledge the SNI |
| 1514 | // extension. |
| 1515 | SendServerNameAck bool |
Robert Sloan | 7d422bc | 2017-03-06 10:04:29 -0800 | [diff] [blame] | 1516 | |
| 1517 | // ExpectCertificateReqNames, if not nil, contains the list of X.509 |
| 1518 | // names that must be sent in a CertificateRequest from the server. |
| 1519 | ExpectCertificateReqNames [][]byte |
| 1520 | |
| 1521 | // RenegotiationCertificate, if not nil, is the certificate to use on |
| 1522 | // renegotiation handshakes. |
| 1523 | RenegotiationCertificate *Certificate |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1524 | |
Robert Sloan | b1b54b8 | 2017-11-06 13:50:02 -0800 | [diff] [blame] | 1525 | // ExpectNoCertificateAuthoritiesExtension, if true, causes the client to |
| 1526 | // reject CertificateRequest with the CertificateAuthorities extension. |
| 1527 | ExpectNoCertificateAuthoritiesExtension bool |
| 1528 | |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1529 | // UseLegacySigningAlgorithm, if non-zero, is the signature algorithm |
| 1530 | // to use when signing in TLS 1.1 and earlier where algorithms are not |
| 1531 | // negotiated. |
| 1532 | UseLegacySigningAlgorithm signatureAlgorithm |
| 1533 | |
| 1534 | // SendServerHelloAsHelloRetryRequest, if true, causes the server to |
| 1535 | // send ServerHello messages with a HelloRetryRequest type field. |
| 1536 | SendServerHelloAsHelloRetryRequest bool |
| 1537 | |
| 1538 | // RejectUnsolicitedKeyUpdate, if true, causes all unsolicited |
| 1539 | // KeyUpdates from the peer to be rejected. |
| 1540 | RejectUnsolicitedKeyUpdate bool |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 1541 | |
| 1542 | // OmitExtensions, if true, causes the extensions field in ClientHello |
| 1543 | // and ServerHello messages to be omitted. |
| 1544 | OmitExtensions bool |
| 1545 | |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame] | 1546 | // EmptyExtensions, if true, causes the extensions field in ClientHello |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 1547 | // and ServerHello messages to be present, but empty. |
| 1548 | EmptyExtensions bool |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame] | 1549 | |
Robert Sloan | a27a6a4 | 2017-09-05 08:39:28 -0700 | [diff] [blame] | 1550 | // ExpectOmitExtensions, if true, causes the client to reject |
| 1551 | // ServerHello messages that do not omit extensions. |
| 1552 | ExpectOmitExtensions bool |
| 1553 | |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame] | 1554 | // ExpectRecordSplitting, if true, causes application records to only be |
| 1555 | // accepted if they follow a 1/n-1 record split. |
| 1556 | ExpectRecordSplitting bool |
Robert Sloan | d1d118f | 2017-09-11 09:00:48 -0700 | [diff] [blame] | 1557 | |
| 1558 | // PadClientHello, if non-zero, pads the ClientHello to a multiple of |
| 1559 | // that many bytes. |
| 1560 | PadClientHello int |
Robert Sloan | 0da4395 | 2018-01-03 15:13:14 -0800 | [diff] [blame] | 1561 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 1562 | // SendTLS13DowngradeRandom, if true, causes the server to send the |
| 1563 | // TLS 1.3 anti-downgrade signal. |
| 1564 | SendTLS13DowngradeRandom bool |
Robert Sloan | 0da4395 | 2018-01-03 15:13:14 -0800 | [diff] [blame] | 1565 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 1566 | // CheckTLS13DowngradeRandom, if true, causes the client to check the |
| 1567 | // TLS 1.3 anti-downgrade signal regardless of its variant. |
| 1568 | CheckTLS13DowngradeRandom bool |
Robert Sloan | 0db7f54 | 2018-01-16 15:48:33 -0800 | [diff] [blame] | 1569 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 1570 | // IgnoreTLS13DowngradeRandom, if true, causes the client to ignore the |
| 1571 | // TLS 1.3 anti-downgrade signal. |
| 1572 | IgnoreTLS13DowngradeRandom bool |
Robert Sloan | ab8b888 | 2018-03-26 11:39:51 -0700 | [diff] [blame] | 1573 | |
| 1574 | // SendCompressedCoordinates, if true, causes ECDH key shares over NIST |
| 1575 | // curves to use compressed coordinates. |
| 1576 | SendCompressedCoordinates bool |
Robert Sloan | 5cbb5c8 | 2018-04-24 11:35:46 -0700 | [diff] [blame] | 1577 | |
| 1578 | // ExpectRSAPSSSupport specifies the level of RSA-PSS support expected |
| 1579 | // from the peer. |
| 1580 | ExpectRSAPSSSupport RSAPSSSupport |
| 1581 | |
| 1582 | // SetX25519HighBit, if true, causes X25519 key shares to set their |
| 1583 | // high-order bit. |
| 1584 | SetX25519HighBit bool |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 1585 | |
| 1586 | // DuplicateCompressedCertAlgs, if true, causes two, equal, certificate |
| 1587 | // compression algorithm IDs to be sent. |
| 1588 | DuplicateCompressedCertAlgs bool |
| 1589 | |
| 1590 | // ExpectedCompressedCert specifies the compression algorithm ID that must be |
| 1591 | // used on this connection, or zero if there are no special requirements. |
| 1592 | ExpectedCompressedCert uint16 |
| 1593 | |
| 1594 | // SendCertCompressionAlgId, if not zero, sets the algorithm ID that will be |
| 1595 | // sent in the compressed certificate message. |
| 1596 | SendCertCompressionAlgId uint16 |
| 1597 | |
| 1598 | // SendCertUncompressedLength, if not zero, sets the uncompressed length that |
| 1599 | // will be sent in the compressed certificate message. |
| 1600 | SendCertUncompressedLength uint32 |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame] | 1601 | |
| 1602 | // SendClientHelloWithFixes, if not nil, sends the specified byte string |
| 1603 | // instead of the ClientHello. This string is incorporated into the |
| 1604 | // transcript as if it were the real ClientHello, but the handshake will |
| 1605 | // otherwise behave as if this was not sent in terms of what ciphers it |
| 1606 | // will accept, etc. |
| 1607 | // |
| 1608 | // The input is modified to match key share entries. DefaultCurves must |
| 1609 | // be configured to match. The random and session ID fields are |
| 1610 | // extracted from the ClientHello. |
| 1611 | SendClientHelloWithFixes []byte |
| 1612 | |
| 1613 | // SendJDK11DowngradeRandom, if true, causes the server to send the JDK |
| 1614 | // 11 downgrade signal. |
| 1615 | SendJDK11DowngradeRandom bool |
| 1616 | |
| 1617 | // ExpectJDK11DowngradeRandom is whether the client should expect the |
| 1618 | // server to send the JDK 11 downgrade signal. |
| 1619 | ExpectJDK11DowngradeRandom bool |
Robert Sloan | 11c28bd | 2018-12-17 12:09:20 -0800 | [diff] [blame] | 1620 | |
| 1621 | // FailIfHelloRetryRequested causes a handshake failure if a server requests a |
| 1622 | // hello retry. |
| 1623 | FailIfHelloRetryRequested bool |
| 1624 | |
| 1625 | // FailedIfCECPQ2Offered will cause a server to reject a ClientHello if CECPQ2 |
| 1626 | // is supported. |
| 1627 | FailIfCECPQ2Offered bool |
| 1628 | |
| 1629 | // ExpectKeyShares, if not nil, lists (in order) the curves that a ClientHello |
| 1630 | // should have key shares for. |
| 1631 | ExpectedKeyShares []CurveID |
Robert Sloan | 4c22c5f | 2019-03-01 15:53:37 -0800 | [diff] [blame] | 1632 | |
| 1633 | // ExpectDelegatedCredentials, if true, requires that the handshake present |
| 1634 | // delegated credentials. |
| 1635 | ExpectDelegatedCredentials bool |
| 1636 | |
| 1637 | // FailIfDelegatedCredentials, if true, causes a handshake failure if the |
| 1638 | // server returns delegated credentials. |
| 1639 | FailIfDelegatedCredentials bool |
| 1640 | |
| 1641 | // DisableDelegatedCredentials, if true, disables client support for delegated |
| 1642 | // credentials. |
| 1643 | DisableDelegatedCredentials bool |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame^] | 1644 | |
| 1645 | // ExpectPQExperimentSignal specifies whether or not the post-quantum |
| 1646 | // experiment signal should be received by a client or server. |
| 1647 | ExpectPQExperimentSignal bool |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | func (c *Config) serverInit() { |
| 1651 | if c.SessionTicketsDisabled { |
| 1652 | return |
| 1653 | } |
| 1654 | |
| 1655 | // If the key has already been set then we have nothing to do. |
| 1656 | for _, b := range c.SessionTicketKey { |
| 1657 | if b != 0 { |
| 1658 | return |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | if _, err := io.ReadFull(c.rand(), c.SessionTicketKey[:]); err != nil { |
| 1663 | c.SessionTicketsDisabled = true |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | func (c *Config) rand() io.Reader { |
| 1668 | r := c.Rand |
| 1669 | if r == nil { |
| 1670 | return rand.Reader |
| 1671 | } |
| 1672 | return r |
| 1673 | } |
| 1674 | |
| 1675 | func (c *Config) time() time.Time { |
| 1676 | t := c.Time |
| 1677 | if t == nil { |
| 1678 | t = time.Now |
| 1679 | } |
| 1680 | return t() |
| 1681 | } |
| 1682 | |
| 1683 | func (c *Config) cipherSuites() []uint16 { |
| 1684 | s := c.CipherSuites |
| 1685 | if s == nil { |
| 1686 | s = defaultCipherSuites() |
| 1687 | } |
| 1688 | return s |
| 1689 | } |
| 1690 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1691 | func (c *Config) minVersion(isDTLS bool) uint16 { |
| 1692 | ret := uint16(minVersion) |
| 1693 | if c != nil && c.MinVersion != 0 { |
| 1694 | ret = c.MinVersion |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 1695 | } |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1696 | if isDTLS { |
| 1697 | // The lowest version of DTLS is 1.0. There is no DSSL 3.0. |
| 1698 | if ret < VersionTLS10 { |
| 1699 | return VersionTLS10 |
| 1700 | } |
| 1701 | // There is no such thing as DTLS 1.1. |
| 1702 | if ret == VersionTLS11 { |
| 1703 | return VersionTLS12 |
| 1704 | } |
| 1705 | } |
| 1706 | return ret |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 1707 | } |
| 1708 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1709 | func (c *Config) maxVersion(isDTLS bool) uint16 { |
| 1710 | ret := uint16(maxVersion) |
| 1711 | if c != nil && c.MaxVersion != 0 { |
| 1712 | ret = c.MaxVersion |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 1713 | } |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1714 | if isDTLS { |
| 1715 | // We only implement up to DTLS 1.2. |
| 1716 | if ret > VersionTLS12 { |
| 1717 | return VersionTLS12 |
| 1718 | } |
| 1719 | // There is no such thing as DTLS 1.1. |
| 1720 | if ret == VersionTLS11 { |
| 1721 | return VersionTLS10 |
| 1722 | } |
| 1723 | } |
| 1724 | return ret |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 1725 | } |
| 1726 | |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame^] | 1727 | var defaultCurvePreferences = []CurveID{CurveCECPQ2b, CurveCECPQ2, CurveX25519, CurveP256, CurveP384, CurveP521} |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 1728 | |
| 1729 | func (c *Config) curvePreferences() []CurveID { |
| 1730 | if c == nil || len(c.CurvePreferences) == 0 { |
| 1731 | return defaultCurvePreferences |
| 1732 | } |
| 1733 | return c.CurvePreferences |
| 1734 | } |
| 1735 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1736 | func (c *Config) defaultCurves() map[CurveID]bool { |
| 1737 | defaultCurves := make(map[CurveID]bool) |
| 1738 | curves := c.DefaultCurves |
| 1739 | if c == nil || c.DefaultCurves == nil { |
| 1740 | curves = c.curvePreferences() |
| 1741 | } |
| 1742 | for _, curveID := range curves { |
| 1743 | defaultCurves[curveID] = true |
| 1744 | } |
| 1745 | return defaultCurves |
| 1746 | } |
| 1747 | |
Robert Sloan | db4251a | 2017-09-18 09:38:15 -0700 | [diff] [blame] | 1748 | func wireToVersion(vers uint16, isDTLS bool) (uint16, bool) { |
| 1749 | if isDTLS { |
| 1750 | switch vers { |
| 1751 | case VersionDTLS12: |
| 1752 | return VersionTLS12, true |
| 1753 | case VersionDTLS10: |
| 1754 | return VersionTLS10, true |
| 1755 | } |
| 1756 | } else { |
| 1757 | switch vers { |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 1758 | case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12, VersionTLS13: |
Robert Sloan | db4251a | 2017-09-18 09:38:15 -0700 | [diff] [blame] | 1759 | return vers, true |
Robert Sloan | db4251a | 2017-09-18 09:38:15 -0700 | [diff] [blame] | 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | return 0, false |
| 1764 | } |
| 1765 | |
Robert Sloan | f6200e7 | 2017-07-10 08:09:18 -0700 | [diff] [blame] | 1766 | // isSupportedVersion checks if the specified wire version is acceptable. If so, |
| 1767 | // it returns true and the corresponding protocol version. Otherwise, it returns |
| 1768 | // false. |
| 1769 | func (c *Config) isSupportedVersion(wireVers uint16, isDTLS bool) (uint16, bool) { |
| 1770 | vers, ok := wireToVersion(wireVers, isDTLS) |
| 1771 | if !ok || c.minVersion(isDTLS) > vers || vers > c.maxVersion(isDTLS) { |
| 1772 | return 0, false |
| 1773 | } |
| 1774 | return vers, true |
| 1775 | } |
| 1776 | |
| 1777 | func (c *Config) supportedVersions(isDTLS bool) []uint16 { |
| 1778 | versions := allTLSWireVersions |
| 1779 | if isDTLS { |
| 1780 | versions = allDTLSWireVersions |
| 1781 | } |
| 1782 | var ret []uint16 |
| 1783 | for _, vers := range versions { |
| 1784 | if _, ok := c.isSupportedVersion(vers, isDTLS); ok { |
| 1785 | ret = append(ret, vers) |
| 1786 | } |
| 1787 | } |
| 1788 | return ret |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | // getCertificateForName returns the best certificate for the given name, |
| 1792 | // defaulting to the first element of c.Certificates if there are no good |
| 1793 | // options. |
| 1794 | func (c *Config) getCertificateForName(name string) *Certificate { |
| 1795 | if len(c.Certificates) == 1 || c.NameToCertificate == nil { |
| 1796 | // There's only one choice, so no point doing any work. |
| 1797 | return &c.Certificates[0] |
| 1798 | } |
| 1799 | |
| 1800 | name = strings.ToLower(name) |
| 1801 | for len(name) > 0 && name[len(name)-1] == '.' { |
| 1802 | name = name[:len(name)-1] |
| 1803 | } |
| 1804 | |
| 1805 | if cert, ok := c.NameToCertificate[name]; ok { |
| 1806 | return cert |
| 1807 | } |
| 1808 | |
| 1809 | // try replacing labels in the name with wildcards until we get a |
| 1810 | // match. |
| 1811 | labels := strings.Split(name, ".") |
| 1812 | for i := range labels { |
| 1813 | labels[i] = "*" |
| 1814 | candidate := strings.Join(labels, ".") |
| 1815 | if cert, ok := c.NameToCertificate[candidate]; ok { |
| 1816 | return cert |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | // If nothing matches, return the first certificate. |
| 1821 | return &c.Certificates[0] |
| 1822 | } |
| 1823 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1824 | func (c *Config) signSignatureAlgorithms() []signatureAlgorithm { |
| 1825 | if c != nil && c.SignSignatureAlgorithms != nil { |
| 1826 | return c.SignSignatureAlgorithms |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 1827 | } |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1828 | return supportedSignatureAlgorithms |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 1829 | } |
| 1830 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1831 | func (c *Config) verifySignatureAlgorithms() []signatureAlgorithm { |
| 1832 | if c != nil && c.VerifySignatureAlgorithms != nil { |
| 1833 | return c.VerifySignatureAlgorithms |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 1834 | } |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1835 | return supportedSignatureAlgorithms |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | // BuildNameToCertificate parses c.Certificates and builds c.NameToCertificate |
| 1839 | // from the CommonName and SubjectAlternateName fields of each of the leaf |
| 1840 | // certificates. |
| 1841 | func (c *Config) BuildNameToCertificate() { |
| 1842 | c.NameToCertificate = make(map[string]*Certificate) |
| 1843 | for i := range c.Certificates { |
| 1844 | cert := &c.Certificates[i] |
| 1845 | x509Cert, err := x509.ParseCertificate(cert.Certificate[0]) |
| 1846 | if err != nil { |
| 1847 | continue |
| 1848 | } |
| 1849 | if len(x509Cert.Subject.CommonName) > 0 { |
| 1850 | c.NameToCertificate[x509Cert.Subject.CommonName] = cert |
| 1851 | } |
| 1852 | for _, san := range x509Cert.DNSNames { |
| 1853 | c.NameToCertificate[san] = cert |
| 1854 | } |
| 1855 | } |
| 1856 | } |
| 1857 | |
| 1858 | // A Certificate is a chain of one or more certificates, leaf first. |
| 1859 | type Certificate struct { |
| 1860 | Certificate [][]byte |
| 1861 | PrivateKey crypto.PrivateKey // supported types: *rsa.PrivateKey, *ecdsa.PrivateKey |
| 1862 | // OCSPStaple contains an optional OCSP response which will be served |
| 1863 | // to clients that request it. |
| 1864 | OCSPStaple []byte |
| 1865 | // SignedCertificateTimestampList contains an optional encoded |
| 1866 | // SignedCertificateTimestampList structure which will be |
| 1867 | // served to clients that request it. |
| 1868 | SignedCertificateTimestampList []byte |
| 1869 | // Leaf is the parsed form of the leaf certificate, which may be |
| 1870 | // initialized using x509.ParseCertificate to reduce per-handshake |
| 1871 | // processing for TLS clients doing client authentication. If nil, the |
| 1872 | // leaf certificate will be parsed as needed. |
| 1873 | Leaf *x509.Certificate |
| 1874 | } |
| 1875 | |
| 1876 | // A TLS record. |
| 1877 | type record struct { |
| 1878 | contentType recordType |
| 1879 | major, minor uint8 |
| 1880 | payload []byte |
| 1881 | } |
| 1882 | |
| 1883 | type handshakeMessage interface { |
| 1884 | marshal() []byte |
| 1885 | unmarshal([]byte) bool |
| 1886 | } |
| 1887 | |
| 1888 | // lruSessionCache is a client or server session cache implementation |
| 1889 | // that uses an LRU caching strategy. |
| 1890 | type lruSessionCache struct { |
| 1891 | sync.Mutex |
| 1892 | |
| 1893 | m map[string]*list.Element |
| 1894 | q *list.List |
| 1895 | capacity int |
| 1896 | } |
| 1897 | |
| 1898 | type lruSessionCacheEntry struct { |
| 1899 | sessionKey string |
| 1900 | state interface{} |
| 1901 | } |
| 1902 | |
| 1903 | // Put adds the provided (sessionKey, cs) pair to the cache. |
| 1904 | func (c *lruSessionCache) Put(sessionKey string, cs interface{}) { |
| 1905 | c.Lock() |
| 1906 | defer c.Unlock() |
| 1907 | |
| 1908 | if elem, ok := c.m[sessionKey]; ok { |
| 1909 | entry := elem.Value.(*lruSessionCacheEntry) |
| 1910 | entry.state = cs |
| 1911 | c.q.MoveToFront(elem) |
| 1912 | return |
| 1913 | } |
| 1914 | |
| 1915 | if c.q.Len() < c.capacity { |
| 1916 | entry := &lruSessionCacheEntry{sessionKey, cs} |
| 1917 | c.m[sessionKey] = c.q.PushFront(entry) |
| 1918 | return |
| 1919 | } |
| 1920 | |
| 1921 | elem := c.q.Back() |
| 1922 | entry := elem.Value.(*lruSessionCacheEntry) |
| 1923 | delete(c.m, entry.sessionKey) |
| 1924 | entry.sessionKey = sessionKey |
| 1925 | entry.state = cs |
| 1926 | c.q.MoveToFront(elem) |
| 1927 | c.m[sessionKey] = elem |
| 1928 | } |
| 1929 | |
| 1930 | // Get returns the value associated with a given key. It returns (nil, |
| 1931 | // false) if no value is found. |
| 1932 | func (c *lruSessionCache) Get(sessionKey string) (interface{}, bool) { |
| 1933 | c.Lock() |
| 1934 | defer c.Unlock() |
| 1935 | |
| 1936 | if elem, ok := c.m[sessionKey]; ok { |
| 1937 | c.q.MoveToFront(elem) |
| 1938 | return elem.Value.(*lruSessionCacheEntry).state, true |
| 1939 | } |
| 1940 | return nil, false |
| 1941 | } |
| 1942 | |
| 1943 | // lruClientSessionCache is a ClientSessionCache implementation that |
| 1944 | // uses an LRU caching strategy. |
| 1945 | type lruClientSessionCache struct { |
| 1946 | lruSessionCache |
| 1947 | } |
| 1948 | |
| 1949 | func (c *lruClientSessionCache) Put(sessionKey string, cs *ClientSessionState) { |
| 1950 | c.lruSessionCache.Put(sessionKey, cs) |
| 1951 | } |
| 1952 | |
| 1953 | func (c *lruClientSessionCache) Get(sessionKey string) (*ClientSessionState, bool) { |
| 1954 | cs, ok := c.lruSessionCache.Get(sessionKey) |
| 1955 | if !ok { |
| 1956 | return nil, false |
| 1957 | } |
| 1958 | return cs.(*ClientSessionState), true |
| 1959 | } |
| 1960 | |
| 1961 | // lruServerSessionCache is a ServerSessionCache implementation that |
| 1962 | // uses an LRU caching strategy. |
| 1963 | type lruServerSessionCache struct { |
| 1964 | lruSessionCache |
| 1965 | } |
| 1966 | |
| 1967 | func (c *lruServerSessionCache) Put(sessionId string, session *sessionState) { |
| 1968 | c.lruSessionCache.Put(sessionId, session) |
| 1969 | } |
| 1970 | |
| 1971 | func (c *lruServerSessionCache) Get(sessionId string) (*sessionState, bool) { |
| 1972 | cs, ok := c.lruSessionCache.Get(sessionId) |
| 1973 | if !ok { |
| 1974 | return nil, false |
| 1975 | } |
| 1976 | return cs.(*sessionState), true |
| 1977 | } |
| 1978 | |
| 1979 | // NewLRUClientSessionCache returns a ClientSessionCache with the given |
| 1980 | // capacity that uses an LRU strategy. If capacity is < 1, a default capacity |
| 1981 | // is used instead. |
| 1982 | func NewLRUClientSessionCache(capacity int) ClientSessionCache { |
| 1983 | const defaultSessionCacheCapacity = 64 |
| 1984 | |
| 1985 | if capacity < 1 { |
| 1986 | capacity = defaultSessionCacheCapacity |
| 1987 | } |
| 1988 | return &lruClientSessionCache{ |
| 1989 | lruSessionCache{ |
| 1990 | m: make(map[string]*list.Element), |
| 1991 | q: list.New(), |
| 1992 | capacity: capacity, |
| 1993 | }, |
| 1994 | } |
| 1995 | } |
| 1996 | |
| 1997 | // NewLRUServerSessionCache returns a ServerSessionCache with the given |
| 1998 | // capacity that uses an LRU strategy. If capacity is < 1, a default capacity |
| 1999 | // is used instead. |
| 2000 | func NewLRUServerSessionCache(capacity int) ServerSessionCache { |
| 2001 | const defaultSessionCacheCapacity = 64 |
| 2002 | |
| 2003 | if capacity < 1 { |
| 2004 | capacity = defaultSessionCacheCapacity |
| 2005 | } |
| 2006 | return &lruServerSessionCache{ |
| 2007 | lruSessionCache{ |
| 2008 | m: make(map[string]*list.Element), |
| 2009 | q: list.New(), |
| 2010 | capacity: capacity, |
| 2011 | }, |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | // TODO(jsing): Make these available to both crypto/x509 and crypto/tls. |
| 2016 | type dsaSignature struct { |
| 2017 | R, S *big.Int |
| 2018 | } |
| 2019 | |
| 2020 | type ecdsaSignature dsaSignature |
| 2021 | |
| 2022 | var emptyConfig Config |
| 2023 | |
| 2024 | func defaultConfig() *Config { |
| 2025 | return &emptyConfig |
| 2026 | } |
| 2027 | |
| 2028 | var ( |
| 2029 | once sync.Once |
| 2030 | varDefaultCipherSuites []uint16 |
| 2031 | ) |
| 2032 | |
| 2033 | func defaultCipherSuites() []uint16 { |
| 2034 | once.Do(initDefaultCipherSuites) |
| 2035 | return varDefaultCipherSuites |
| 2036 | } |
| 2037 | |
| 2038 | func initDefaultCipherSuites() { |
| 2039 | for _, suite := range cipherSuites { |
| 2040 | if suite.flags&suitePSK == 0 { |
| 2041 | varDefaultCipherSuites = append(varDefaultCipherSuites, suite.id) |
| 2042 | } |
| 2043 | } |
| 2044 | } |
| 2045 | |
| 2046 | func unexpectedMessageError(wanted, got interface{}) error { |
| 2047 | return fmt.Errorf("tls: received unexpected handshake message of type %T when waiting for %T", got, wanted) |
| 2048 | } |
| 2049 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 2050 | func isSupportedSignatureAlgorithm(sigAlg signatureAlgorithm, sigAlgs []signatureAlgorithm) bool { |
| 2051 | for _, s := range sigAlgs { |
| 2052 | if s == sigAlg { |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 2053 | return true |
| 2054 | } |
| 2055 | } |
| 2056 | return false |
| 2057 | } |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 2058 | |
| 2059 | var ( |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 2060 | // See RFC 8446, section 4.1.3. |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 2061 | downgradeTLS13 = []byte{0x44, 0x4f, 0x57, 0x4e, 0x47, 0x52, 0x44, 0x01} |
| 2062 | downgradeTLS12 = []byte{0x44, 0x4f, 0x57, 0x4e, 0x47, 0x52, 0x44, 0x00} |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame] | 2063 | |
| 2064 | // This is a non-standard randomly-generated value. |
| 2065 | downgradeJDK11 = []byte{0xed, 0xbf, 0xb4, 0xa8, 0xc2, 0x47, 0x10, 0xff} |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 2066 | ) |
Robert Sloan | f6200e7 | 2017-07-10 08:09:18 -0700 | [diff] [blame] | 2067 | |
| 2068 | func containsGREASE(values []uint16) bool { |
| 2069 | for _, v := range values { |
| 2070 | if isGREASEValue(v) { |
| 2071 | return true |
| 2072 | } |
| 2073 | } |
| 2074 | return false |
| 2075 | } |
Robert Sloan | 5cbb5c8 | 2018-04-24 11:35:46 -0700 | [diff] [blame] | 2076 | |
| 2077 | func checkRSAPSSSupport(support RSAPSSSupport, sigAlgs, sigAlgsCert []signatureAlgorithm) error { |
| 2078 | if sigAlgsCert == nil { |
| 2079 | sigAlgsCert = sigAlgs |
| 2080 | } else if eqSignatureAlgorithms(sigAlgs, sigAlgsCert) { |
| 2081 | // The peer should have only sent the list once. |
| 2082 | return errors.New("tls: signature_algorithms and signature_algorithms_cert extensions were identical") |
| 2083 | } |
| 2084 | |
| 2085 | if support == RSAPSSSupportAny { |
| 2086 | return nil |
| 2087 | } |
| 2088 | |
| 2089 | var foundPSS, foundPSSCert bool |
| 2090 | for _, sigAlg := range sigAlgs { |
| 2091 | if sigAlg == signatureRSAPSSWithSHA256 || sigAlg == signatureRSAPSSWithSHA384 || sigAlg == signatureRSAPSSWithSHA512 { |
| 2092 | foundPSS = true |
| 2093 | break |
| 2094 | } |
| 2095 | } |
| 2096 | for _, sigAlg := range sigAlgsCert { |
| 2097 | if sigAlg == signatureRSAPSSWithSHA256 || sigAlg == signatureRSAPSSWithSHA384 || sigAlg == signatureRSAPSSWithSHA512 { |
| 2098 | foundPSSCert = true |
| 2099 | break |
| 2100 | } |
| 2101 | } |
| 2102 | |
| 2103 | expectPSS := support != RSAPSSSupportNone |
| 2104 | if foundPSS != expectPSS { |
| 2105 | if expectPSS { |
| 2106 | return errors.New("tls: peer did not support PSS") |
| 2107 | } else { |
| 2108 | return errors.New("tls: peer unexpectedly supported PSS") |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | expectPSSCert := support == RSAPSSSupportBoth |
| 2113 | if foundPSSCert != expectPSSCert { |
| 2114 | if expectPSSCert { |
| 2115 | return errors.New("tls: peer did not support PSS in certificates") |
| 2116 | } else { |
| 2117 | return errors.New("tls: peer unexpectedly supported PSS in certificates") |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | return nil |
| 2122 | } |