blob: b40f222f91c7b58e338bffa90cb97b91f6bd9fc0 [file] [log] [blame]
Adam Langley95c29f32014-06-20 12:00:00 -07001// 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
Adam Langleydc7e9c42015-09-29 15:21:04 -07005package runner
Adam Langley95c29f32014-06-20 12:00:00 -07006
7import (
8 "container/list"
9 "crypto"
David Benjamind30a9902014-08-24 01:44:23 -040010 "crypto/ecdsa"
Adam Langley95c29f32014-06-20 12:00:00 -070011 "crypto/rand"
12 "crypto/x509"
13 "fmt"
14 "io"
15 "math/big"
16 "strings"
17 "sync"
18 "time"
19)
20
21const (
22 VersionSSL30 = 0x0300
23 VersionTLS10 = 0x0301
24 VersionTLS11 = 0x0302
25 VersionTLS12 = 0x0303
Nick Harper1fd39d82016-06-14 18:14:35 -070026 VersionTLS13 = 0x0304
Adam Langley95c29f32014-06-20 12:00:00 -070027)
28
David Benjamin353577c2017-06-29 15:54:58 -040029const (
30 VersionDTLS10 = 0xfeff
31 VersionDTLS12 = 0xfefd
32)
33
Steven Valdezfdd10992016-09-15 16:27:05 -040034// A draft version of TLS 1.3 that is sent over the wire for the current draft.
Steven Valdez520e1222017-06-13 12:45:25 -040035const (
36 tls13DraftVersion = 0x7f12
37 tls13ExperimentVersion = 0x7e01
38)
39
40const (
41 TLS13Default = 0
42 TLS13Experiment = 1
43)
Nick Harper4d90c102016-07-17 10:53:26 +020044
Steven Valdezc94998a2017-06-20 10:55:02 -040045var allTLSWireVersions = []uint16{
46 tls13DraftVersion,
Steven Valdez520e1222017-06-13 12:45:25 -040047 tls13ExperimentVersion,
Steven Valdezc94998a2017-06-20 10:55:02 -040048 VersionTLS12,
49 VersionTLS11,
50 VersionTLS10,
51 VersionSSL30,
52}
53
54var allDTLSWireVersions = []uint16{
55 VersionDTLS12,
56 VersionDTLS10,
57}
58
Adam Langley95c29f32014-06-20 12:00:00 -070059const (
David Benjamin83c0bc92014-08-04 01:23:53 -040060 maxPlaintext = 16384 // maximum plaintext payload length
61 maxCiphertext = 16384 + 2048 // maximum ciphertext payload length
62 tlsRecordHeaderLen = 5 // record header length
63 dtlsRecordHeaderLen = 13
64 maxHandshake = 65536 // maximum handshake we support (protocol max is 16 MB)
Adam Langley95c29f32014-06-20 12:00:00 -070065
66 minVersion = VersionSSL30
Nick Harper1fd39d82016-06-14 18:14:35 -070067 maxVersion = VersionTLS13
Adam Langley95c29f32014-06-20 12:00:00 -070068)
69
70// TLS record types.
71type recordType uint8
72
73const (
74 recordTypeChangeCipherSpec recordType = 20
75 recordTypeAlert recordType = 21
76 recordTypeHandshake recordType = 22
77 recordTypeApplicationData recordType = 23
78)
79
80// TLS handshake message types.
81const (
David Benjamincedff872016-06-30 18:55:18 -040082 typeHelloRequest uint8 = 0
83 typeClientHello uint8 = 1
84 typeServerHello uint8 = 2
85 typeHelloVerifyRequest uint8 = 3
86 typeNewSessionTicket uint8 = 4
David Benjamina128a552016-10-13 14:26:33 -040087 typeHelloRetryRequest uint8 = 6 // draft-ietf-tls-tls13-16
88 typeEncryptedExtensions uint8 = 8 // draft-ietf-tls-tls13-16
David Benjamincedff872016-06-30 18:55:18 -040089 typeCertificate uint8 = 11
90 typeServerKeyExchange uint8 = 12
91 typeCertificateRequest uint8 = 13
92 typeServerHelloDone uint8 = 14
93 typeCertificateVerify uint8 = 15
94 typeClientKeyExchange uint8 = 16
95 typeFinished uint8 = 20
96 typeCertificateStatus uint8 = 22
David Benjamina128a552016-10-13 14:26:33 -040097 typeKeyUpdate uint8 = 24 // draft-ietf-tls-tls13-16
David Benjamincedff872016-06-30 18:55:18 -040098 typeNextProtocol uint8 = 67 // Not IANA assigned
99 typeChannelID uint8 = 203 // Not IANA assigned
Adam Langley95c29f32014-06-20 12:00:00 -0700100)
101
102// TLS compression types.
103const (
104 compressionNone uint8 = 0
105)
106
107// TLS extension numbers
108const (
David Benjamin61f95272014-11-25 01:55:35 -0500109 extensionServerName uint16 = 0
110 extensionStatusRequest uint16 = 5
111 extensionSupportedCurves uint16 = 10
112 extensionSupportedPoints uint16 = 11
113 extensionSignatureAlgorithms uint16 = 13
114 extensionUseSRTP uint16 = 14
115 extensionALPN uint16 = 16
116 extensionSignedCertificateTimestamp uint16 = 18
117 extensionExtendedMasterSecret uint16 = 23
118 extensionSessionTicket uint16 = 35
David Benjamina128a552016-10-13 14:26:33 -0400119 extensionKeyShare uint16 = 40 // draft-ietf-tls-tls13-16
120 extensionPreSharedKey uint16 = 41 // draft-ietf-tls-tls13-16
121 extensionEarlyData uint16 = 42 // draft-ietf-tls-tls13-16
Steven Valdezfdd10992016-09-15 16:27:05 -0400122 extensionSupportedVersions uint16 = 43 // draft-ietf-tls-tls13-16
David Benjamina128a552016-10-13 14:26:33 -0400123 extensionCookie uint16 = 44 // draft-ietf-tls-tls13-16
Steven Valdeza833c352016-11-01 13:39:36 -0400124 extensionPSKKeyExchangeModes uint16 = 45 // draft-ietf-tls-tls13-18
Steven Valdez08b65f42016-12-07 15:29:45 -0500125 extensionTicketEarlyDataInfo uint16 = 46 // draft-ietf-tls-tls13-18
David Benjamin399e7c92015-07-30 23:01:27 -0400126 extensionCustom uint16 = 1234 // not IANA assigned
David Benjamin61f95272014-11-25 01:55:35 -0500127 extensionNextProtoNeg uint16 = 13172 // not IANA assigned
128 extensionRenegotiationInfo uint16 = 0xff01
129 extensionChannelID uint16 = 30032 // not IANA assigned
Adam Langley95c29f32014-06-20 12:00:00 -0700130)
131
132// TLS signaling cipher suite values
133const (
134 scsvRenegotiation uint16 = 0x00ff
135)
136
137// CurveID is the type of a TLS identifier for an elliptic curve. See
138// http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-8
139type CurveID uint16
140
141const (
David Benjamincba2b622015-12-18 22:13:41 -0500142 CurveP224 CurveID = 21
143 CurveP256 CurveID = 23
144 CurveP384 CurveID = 24
145 CurveP521 CurveID = 25
146 CurveX25519 CurveID = 29
Adam Langley95c29f32014-06-20 12:00:00 -0700147)
148
149// TLS Elliptic Curve Point Formats
150// http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-9
151const (
David Benjamina81967b2016-12-22 09:16:57 -0500152 pointFormatUncompressed uint8 = 0
153 pointFormatCompressedPrime uint8 = 1
Adam Langley95c29f32014-06-20 12:00:00 -0700154)
155
156// TLS CertificateStatusType (RFC 3546)
157const (
158 statusTypeOCSP uint8 = 1
159)
160
161// Certificate types (for certificateRequestMsg)
162const (
David Benjamin7b030512014-07-08 17:30:11 -0400163 CertTypeRSASign = 1 // A certificate containing an RSA key
164 CertTypeDSSSign = 2 // A certificate containing a DSA key
165 CertTypeRSAFixedDH = 3 // A certificate containing a static DH key
166 CertTypeDSSFixedDH = 4 // A certificate containing a static DH key
Adam Langley95c29f32014-06-20 12:00:00 -0700167
168 // See RFC4492 sections 3 and 5.5.
David Benjamin7b030512014-07-08 17:30:11 -0400169 CertTypeECDSASign = 64 // A certificate containing an ECDSA-capable public key, signed with ECDSA.
170 CertTypeRSAFixedECDH = 65 // A certificate containing an ECDH-capable public key, signed with RSA.
171 CertTypeECDSAFixedECDH = 66 // A certificate containing an ECDH-capable public key, signed with ECDSA.
Adam Langley95c29f32014-06-20 12:00:00 -0700172
173 // Rest of these are reserved by the TLS spec
174)
175
Nick Harper60edffd2016-06-21 15:19:24 -0700176// signatureAlgorithm corresponds to a SignatureScheme value from TLS 1.3. Note
177// that TLS 1.3 names the production 'SignatureScheme' to avoid colliding with
178// TLS 1.2's SignatureAlgorithm but otherwise refers to them as 'signature
179// algorithms' throughout. We match the latter.
180type signatureAlgorithm uint16
Adam Langley95c29f32014-06-20 12:00:00 -0700181
Adam Langley95c29f32014-06-20 12:00:00 -0700182const (
Nick Harper60edffd2016-06-21 15:19:24 -0700183 // RSASSA-PKCS1-v1_5 algorithms
184 signatureRSAPKCS1WithMD5 signatureAlgorithm = 0x0101
185 signatureRSAPKCS1WithSHA1 signatureAlgorithm = 0x0201
186 signatureRSAPKCS1WithSHA256 signatureAlgorithm = 0x0401
187 signatureRSAPKCS1WithSHA384 signatureAlgorithm = 0x0501
188 signatureRSAPKCS1WithSHA512 signatureAlgorithm = 0x0601
Adam Langley95c29f32014-06-20 12:00:00 -0700189
Nick Harper60edffd2016-06-21 15:19:24 -0700190 // ECDSA algorithms
191 signatureECDSAWithSHA1 signatureAlgorithm = 0x0203
192 signatureECDSAWithP256AndSHA256 signatureAlgorithm = 0x0403
193 signatureECDSAWithP384AndSHA384 signatureAlgorithm = 0x0503
194 signatureECDSAWithP521AndSHA512 signatureAlgorithm = 0x0603
195
196 // RSASSA-PSS algorithms
David Benjaminaf56fbd2016-09-21 14:38:06 -0400197 signatureRSAPSSWithSHA256 signatureAlgorithm = 0x0804
198 signatureRSAPSSWithSHA384 signatureAlgorithm = 0x0805
199 signatureRSAPSSWithSHA512 signatureAlgorithm = 0x0806
Nick Harper60edffd2016-06-21 15:19:24 -0700200
201 // EdDSA algorithms
David Benjaminaf56fbd2016-09-21 14:38:06 -0400202 signatureEd25519 signatureAlgorithm = 0x0807
203 signatureEd448 signatureAlgorithm = 0x0808
Nick Harper60edffd2016-06-21 15:19:24 -0700204)
Adam Langley95c29f32014-06-20 12:00:00 -0700205
David Benjamin7a41d372016-07-09 11:21:54 -0700206// supportedSignatureAlgorithms contains the default supported signature
207// algorithms.
208var supportedSignatureAlgorithms = []signatureAlgorithm{
209 signatureRSAPSSWithSHA256,
Nick Harper60edffd2016-06-21 15:19:24 -0700210 signatureRSAPKCS1WithSHA256,
211 signatureECDSAWithP256AndSHA256,
212 signatureRSAPKCS1WithSHA1,
213 signatureECDSAWithSHA1,
David Benjamind768c5d2017-03-28 18:28:44 -0500214 signatureEd25519,
Adam Langley95c29f32014-06-20 12:00:00 -0700215}
216
David Benjaminca6c8262014-11-15 19:06:08 -0500217// SRTP protection profiles (See RFC 5764, section 4.1.2)
218const (
219 SRTP_AES128_CM_HMAC_SHA1_80 uint16 = 0x0001
220 SRTP_AES128_CM_HMAC_SHA1_32 = 0x0002
221)
222
David Benjamina128a552016-10-13 14:26:33 -0400223// PskKeyExchangeMode values (see draft-ietf-tls-tls13-16)
David Benjamin58104882016-07-18 01:25:41 +0200224const (
Steven Valdez5b986082016-09-01 12:29:49 -0400225 pskKEMode = 0
226 pskDHEKEMode = 1
227)
228
Steven Valdezc4aa7272016-10-03 12:25:56 -0400229// KeyUpdateRequest values (see draft-ietf-tls-tls13-16, section 4.5.3)
230const (
231 keyUpdateNotRequested = 0
232 keyUpdateRequested = 1
233)
234
Adam Langley95c29f32014-06-20 12:00:00 -0700235// ConnectionState records basic TLS details about the connection.
236type ConnectionState struct {
237 Version uint16 // TLS version used by the connection (e.g. VersionTLS12)
238 HandshakeComplete bool // TLS handshake is complete
239 DidResume bool // connection resumes a previous TLS connection
240 CipherSuite uint16 // cipher suite in use (TLS_RSA_WITH_RC4_128_SHA, ...)
241 NegotiatedProtocol string // negotiated next protocol (from Config.NextProtos)
242 NegotiatedProtocolIsMutual bool // negotiated protocol was advertised by server
David Benjaminfc7b0862014-09-06 13:21:53 -0400243 NegotiatedProtocolFromALPN bool // protocol negotiated with ALPN
Adam Langley95c29f32014-06-20 12:00:00 -0700244 ServerName string // server name requested by client, if any (server side only)
245 PeerCertificates []*x509.Certificate // certificate chain presented by remote peer
246 VerifiedChains [][]*x509.Certificate // verified chains built from PeerCertificates
David Benjamind30a9902014-08-24 01:44:23 -0400247 ChannelID *ecdsa.PublicKey // the channel ID for this connection
David Benjaminca6c8262014-11-15 19:06:08 -0500248 SRTPProtectionProfile uint16 // the negotiated DTLS-SRTP protection profile
David Benjaminc0577622015-09-12 18:28:38 -0400249 TLSUnique []byte // the tls-unique channel binding
Paul Lietar4fac72e2015-09-09 13:44:55 +0100250 SCTList []byte // signed certificate timestamp list
Nick Harper60edffd2016-06-21 15:19:24 -0700251 PeerSignatureAlgorithm signatureAlgorithm // algorithm used by the peer in the handshake
Steven Valdez5440fe02016-07-18 12:40:30 -0400252 CurveID CurveID // the curve used in ECDHE
Adam Langley95c29f32014-06-20 12:00:00 -0700253}
254
255// ClientAuthType declares the policy the server will follow for
256// TLS Client Authentication.
257type ClientAuthType int
258
259const (
260 NoClientCert ClientAuthType = iota
261 RequestClientCert
262 RequireAnyClientCert
263 VerifyClientCertIfGiven
264 RequireAndVerifyClientCert
265)
266
267// ClientSessionState contains the state needed by clients to resume TLS
268// sessions.
269type ClientSessionState struct {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500270 sessionId []uint8 // Session ID supplied by the server. nil if the session has a ticket.
Adam Langley75712922014-10-10 16:23:43 -0700271 sessionTicket []uint8 // Encrypted ticket used for session resumption with server
272 vers uint16 // SSL/TLS version negotiated for the session
273 cipherSuite uint16 // Ciphersuite negotiated for the session
274 masterSecret []byte // MasterSecret generated by client on a full handshake
275 handshakeHash []byte // Handshake hash for Channel ID purposes.
276 serverCertificates []*x509.Certificate // Certificate chain presented by the server
277 extendedMasterSecret bool // Whether an extended master secret was used to generate the session
Paul Lietar62be8ac2015-09-16 10:03:30 +0100278 sctList []byte
279 ocspResponse []byte
Steven Valdez2d850622017-01-11 11:34:52 -0500280 earlyALPN string
Nick Harper0b3625b2016-07-25 16:16:28 -0700281 ticketCreationTime time.Time
282 ticketExpiration time.Time
Steven Valdeza833c352016-11-01 13:39:36 -0400283 ticketAgeAdd uint32
Nick Harperf2511f12016-12-06 16:02:31 -0800284 maxEarlyDataSize uint32
Adam Langley95c29f32014-06-20 12:00:00 -0700285}
286
287// ClientSessionCache is a cache of ClientSessionState objects that can be used
288// by a client to resume a TLS session with a given server. ClientSessionCache
289// implementations should expect to be called concurrently from different
290// goroutines.
291type ClientSessionCache interface {
292 // Get searches for a ClientSessionState associated with the given key.
293 // On return, ok is true if one was found.
294 Get(sessionKey string) (session *ClientSessionState, ok bool)
295
296 // Put adds the ClientSessionState to the cache with the given key.
297 Put(sessionKey string, cs *ClientSessionState)
298}
299
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500300// ServerSessionCache is a cache of sessionState objects that can be used by a
301// client to resume a TLS session with a given server. ServerSessionCache
302// implementations should expect to be called concurrently from different
303// goroutines.
304type ServerSessionCache interface {
305 // Get searches for a sessionState associated with the given session
306 // ID. On return, ok is true if one was found.
307 Get(sessionId string) (session *sessionState, ok bool)
308
309 // Put adds the sessionState to the cache with the given session ID.
310 Put(sessionId string, session *sessionState)
311}
312
Adam Langley95c29f32014-06-20 12:00:00 -0700313// A Config structure is used to configure a TLS client or server.
314// After one has been passed to a TLS function it must not be
315// modified. A Config may be reused; the tls package will also not
316// modify it.
317type Config struct {
318 // Rand provides the source of entropy for nonces and RSA blinding.
319 // If Rand is nil, TLS uses the cryptographic random reader in package
320 // crypto/rand.
321 // The Reader must be safe for use by multiple goroutines.
322 Rand io.Reader
323
324 // Time returns the current time as the number of seconds since the epoch.
325 // If Time is nil, TLS uses time.Now.
326 Time func() time.Time
327
328 // Certificates contains one or more certificate chains
329 // to present to the other side of the connection.
330 // Server configurations must include at least one certificate.
331 Certificates []Certificate
332
333 // NameToCertificate maps from a certificate name to an element of
334 // Certificates. Note that a certificate name can be of the form
335 // '*.example.com' and so doesn't have to be a domain name as such.
336 // See Config.BuildNameToCertificate
337 // The nil value causes the first element of Certificates to be used
338 // for all connections.
339 NameToCertificate map[string]*Certificate
340
341 // RootCAs defines the set of root certificate authorities
342 // that clients use when verifying server certificates.
343 // If RootCAs is nil, TLS uses the host's root CA set.
344 RootCAs *x509.CertPool
345
346 // NextProtos is a list of supported, application level protocols.
347 NextProtos []string
348
349 // ServerName is used to verify the hostname on the returned
350 // certificates unless InsecureSkipVerify is given. It is also included
351 // in the client's handshake to support virtual hosting.
352 ServerName string
353
354 // ClientAuth determines the server's policy for
355 // TLS Client Authentication. The default is NoClientCert.
356 ClientAuth ClientAuthType
357
358 // ClientCAs defines the set of root certificate authorities
359 // that servers use if required to verify a client certificate
360 // by the policy in ClientAuth.
361 ClientCAs *x509.CertPool
362
David Benjamin7b030512014-07-08 17:30:11 -0400363 // ClientCertificateTypes defines the set of allowed client certificate
364 // types. The default is CertTypeRSASign and CertTypeECDSASign.
365 ClientCertificateTypes []byte
366
Adam Langley95c29f32014-06-20 12:00:00 -0700367 // InsecureSkipVerify controls whether a client verifies the
368 // server's certificate chain and host name.
369 // If InsecureSkipVerify is true, TLS accepts any certificate
370 // presented by the server and any host name in that certificate.
371 // In this mode, TLS is susceptible to man-in-the-middle attacks.
372 // This should be used only for testing.
373 InsecureSkipVerify bool
374
375 // CipherSuites is a list of supported cipher suites. If CipherSuites
376 // is nil, TLS uses a list of suites supported by the implementation.
377 CipherSuites []uint16
378
379 // PreferServerCipherSuites controls whether the server selects the
380 // client's most preferred ciphersuite, or the server's most preferred
381 // ciphersuite. If true then the server's preference, as expressed in
382 // the order of elements in CipherSuites, is used.
383 PreferServerCipherSuites bool
384
385 // SessionTicketsDisabled may be set to true to disable session ticket
386 // (resumption) support.
387 SessionTicketsDisabled bool
388
389 // SessionTicketKey is used by TLS servers to provide session
390 // resumption. See RFC 5077. If zero, it will be filled with
391 // random data before the first server handshake.
392 //
393 // If multiple servers are terminating connections for the same host
394 // they should all have the same SessionTicketKey. If the
395 // SessionTicketKey leaks, previously recorded and future TLS
396 // connections using that key are compromised.
397 SessionTicketKey [32]byte
398
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500399 // ClientSessionCache is a cache of ClientSessionState entries
400 // for TLS session resumption.
Adam Langley95c29f32014-06-20 12:00:00 -0700401 ClientSessionCache ClientSessionCache
402
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500403 // ServerSessionCache is a cache of sessionState entries for TLS session
404 // resumption.
405 ServerSessionCache ServerSessionCache
406
Adam Langley95c29f32014-06-20 12:00:00 -0700407 // MinVersion contains the minimum SSL/TLS version that is acceptable.
408 // If zero, then SSLv3 is taken as the minimum.
409 MinVersion uint16
410
411 // MaxVersion contains the maximum SSL/TLS version that is acceptable.
412 // If zero, then the maximum version supported by this package is used,
413 // which is currently TLS 1.2.
414 MaxVersion uint16
415
Steven Valdez520e1222017-06-13 12:45:25 -0400416 // TLS13Variant is the variant of TLS 1.3 to use.
417 TLS13Variant int
418
Adam Langley95c29f32014-06-20 12:00:00 -0700419 // CurvePreferences contains the elliptic curves that will be used in
420 // an ECDHE handshake, in preference order. If empty, the default will
421 // be used.
422 CurvePreferences []CurveID
423
Nick Harperdcfbc672016-07-16 17:47:31 +0200424 // DefaultCurves contains the elliptic curves for which public values will
425 // be sent in the ClientHello's KeyShare extension. If this value is nil,
426 // all supported curves will have public values sent. This field is ignored
427 // on servers.
428 DefaultCurves []CurveID
429
David Benjamind30a9902014-08-24 01:44:23 -0400430 // ChannelID contains the ECDSA key for the client to use as
431 // its TLS Channel ID.
432 ChannelID *ecdsa.PrivateKey
433
434 // RequestChannelID controls whether the server requests a TLS
435 // Channel ID. If negotiated, the client's public key is
436 // returned in the ConnectionState.
437 RequestChannelID bool
438
David Benjamin48cae082014-10-27 01:06:24 -0400439 // PreSharedKey, if not nil, is the pre-shared key to use with
440 // the PSK cipher suites.
441 PreSharedKey []byte
442
443 // PreSharedKeyIdentity, if not empty, is the identity to use
444 // with the PSK cipher suites.
445 PreSharedKeyIdentity string
446
Nick Harperab20cec2016-12-19 17:38:41 -0800447 // MaxEarlyDataSize controls the maximum number of bytes that the
448 // server will accept in early data and advertise in a
449 // NewSessionTicketMsg. If 0, no early data will be accepted and
450 // the TicketEarlyDataInfo extension in the NewSessionTicketMsg
451 // will be omitted.
452 MaxEarlyDataSize uint32
453
David Benjaminca6c8262014-11-15 19:06:08 -0500454 // SRTPProtectionProfiles, if not nil, is the list of SRTP
455 // protection profiles to offer in DTLS-SRTP.
456 SRTPProtectionProfiles []uint16
457
David Benjamin7a41d372016-07-09 11:21:54 -0700458 // SignSignatureAlgorithms, if not nil, overrides the default set of
459 // supported signature algorithms to sign with.
460 SignSignatureAlgorithms []signatureAlgorithm
461
462 // VerifySignatureAlgorithms, if not nil, overrides the default set of
463 // supported signature algorithms that are accepted.
464 VerifySignatureAlgorithms []signatureAlgorithm
David Benjamin000800a2014-11-14 01:43:59 -0500465
Adam Langley95c29f32014-06-20 12:00:00 -0700466 // Bugs specifies optional misbehaviour to be used for testing other
467 // implementations.
468 Bugs ProtocolBugs
469
470 serverInitOnce sync.Once // guards calling (*Config).serverInit
471}
472
473type BadValue int
474
475const (
476 BadValueNone BadValue = iota
477 BadValueNegative
478 BadValueZero
479 BadValueLimit
480 BadValueLarge
481 NumBadValues
482)
483
David Benjaminb36a3952015-12-01 18:53:13 -0500484type RSABadValue int
485
486const (
487 RSABadValueNone RSABadValue = iota
488 RSABadValueCorrupt
489 RSABadValueTooLong
490 RSABadValueTooShort
491 RSABadValueWrongVersion
492 NumRSABadValues
493)
494
Adam Langley95c29f32014-06-20 12:00:00 -0700495type ProtocolBugs struct {
David Benjamin5208fd42016-07-13 21:43:25 -0400496 // InvalidSignature specifies that the signature in a ServerKeyExchange
497 // or CertificateVerify message should be invalid.
498 InvalidSignature bool
David Benjamin6de0e532015-07-28 22:43:19 -0400499
Steven Valdez5440fe02016-07-18 12:40:30 -0400500 // SendCurve, if non-zero, causes the server to send the specified curve
501 // ID in ServerKeyExchange (TLS 1.2) or ServerHello (TLS 1.3) rather
502 // than the negotiated one.
David Benjamin4c3ddf72016-06-29 18:13:53 -0400503 SendCurve CurveID
Adam Langley95c29f32014-06-20 12:00:00 -0700504
David Benjamin2b07fa42016-03-02 00:23:57 -0500505 // InvalidECDHPoint, if true, causes the ECC points in
506 // ServerKeyExchange or ClientKeyExchange messages to be invalid.
507 InvalidECDHPoint bool
508
Adam Langley95c29f32014-06-20 12:00:00 -0700509 // BadECDSAR controls ways in which the 'r' value of an ECDSA signature
510 // can be invalid.
511 BadECDSAR BadValue
512 BadECDSAS BadValue
Adam Langley80842bd2014-06-20 12:00:00 -0700513
514 // MaxPadding causes CBC records to have the maximum possible padding.
515 MaxPadding bool
516 // PaddingFirstByteBad causes the first byte of the padding to be
517 // incorrect.
518 PaddingFirstByteBad bool
519 // PaddingFirstByteBadIf255 causes the first byte of padding to be
520 // incorrect if there's a maximum amount of padding (i.e. 255 bytes).
521 PaddingFirstByteBadIf255 bool
Adam Langleyac61fa32014-06-23 12:03:11 -0700522
523 // FailIfNotFallbackSCSV causes a server handshake to fail if the
524 // client doesn't send the fallback SCSV value.
525 FailIfNotFallbackSCSV bool
David Benjamin35a7a442014-07-05 00:23:20 -0400526
527 // DuplicateExtension causes an extra empty extension of bogus type to
528 // be emitted in either the ClientHello or the ServerHello.
529 DuplicateExtension bool
David Benjamin1c375dd2014-07-12 00:48:23 -0400530
531 // UnauthenticatedECDH causes the server to pretend ECDHE_RSA
532 // and ECDHE_ECDSA cipher suites are actually ECDH_anon. No
533 // Certificate message is sent and no signature is added to
534 // ServerKeyExchange.
535 UnauthenticatedECDH bool
David Benjamin9c651c92014-07-12 13:27:45 -0400536
David Benjaminb80168e2015-02-08 18:30:14 -0500537 // SkipHelloVerifyRequest causes a DTLS server to skip the
538 // HelloVerifyRequest message.
539 SkipHelloVerifyRequest bool
540
David Benjamindcd979f2015-04-20 18:26:52 -0400541 // SkipCertificateStatus, if true, causes the server to skip the
542 // CertificateStatus message. This is legal because CertificateStatus is
543 // optional, even with a status_request in ServerHello.
544 SkipCertificateStatus bool
545
David Benjamin9c651c92014-07-12 13:27:45 -0400546 // SkipServerKeyExchange causes the server to skip sending
547 // ServerKeyExchange messages.
548 SkipServerKeyExchange bool
David Benjamina0e52232014-07-19 17:39:58 -0400549
David Benjaminb80168e2015-02-08 18:30:14 -0500550 // SkipNewSessionTicket causes the server to skip sending the
551 // NewSessionTicket message despite promising to in ServerHello.
552 SkipNewSessionTicket bool
553
David Benjamin0b7ca7d2016-03-10 15:44:22 -0500554 // SkipClientCertificate causes the client to skip the Certificate
555 // message.
556 SkipClientCertificate bool
557
David Benjamina0e52232014-07-19 17:39:58 -0400558 // SkipChangeCipherSpec causes the implementation to skip
559 // sending the ChangeCipherSpec message (and adjusting cipher
560 // state accordingly for the Finished message).
561 SkipChangeCipherSpec bool
David Benjaminf3ec83d2014-07-21 22:42:34 -0400562
David Benjaminb80168e2015-02-08 18:30:14 -0500563 // SkipFinished causes the implementation to skip sending the Finished
564 // message.
565 SkipFinished bool
566
David Benjamin32c89272017-03-26 13:54:21 -0500567 // SkipEndOfEarlyData causes the implementation to skip the
568 // end_of_early_data alert.
569 SkipEndOfEarlyData bool
570
David Benjaminf3ec83d2014-07-21 22:42:34 -0400571 // EarlyChangeCipherSpec causes the client to send an early
572 // ChangeCipherSpec message before the ClientKeyExchange. A value of
573 // zero disables this behavior. One and two configure variants for 0.9.8
574 // and 1.0.1 modes, respectively.
575 EarlyChangeCipherSpec int
David Benjamind23f4122014-07-23 15:09:48 -0400576
David Benjamin8144f992016-06-22 17:05:13 -0400577 // StrayChangeCipherSpec causes every pre-ChangeCipherSpec handshake
578 // message in DTLS to be prefaced by stray ChangeCipherSpec record. This
579 // may be used to test DTLS's handling of reordered ChangeCipherSpec.
580 StrayChangeCipherSpec bool
581
David Benjamin86271ee2014-07-21 16:14:03 -0400582 // FragmentAcrossChangeCipherSpec causes the implementation to fragment
583 // the Finished (or NextProto) message around the ChangeCipherSpec
584 // messages.
585 FragmentAcrossChangeCipherSpec bool
586
David Benjamin61672812016-07-14 23:10:43 -0400587 // SendUnencryptedFinished, if true, causes the Finished message to be
588 // send unencrypted before ChangeCipherSpec rather than after it.
589 SendUnencryptedFinished bool
590
David Benjamin7964b182016-07-14 23:36:30 -0400591 // PartialEncryptedExtensionsWithServerHello, if true, causes the TLS
592 // 1.3 server to send part of EncryptedExtensions unencrypted
593 // in the same record as ServerHello.
594 PartialEncryptedExtensionsWithServerHello bool
595
596 // PartialClientFinishedWithClientHello, if true, causes the TLS 1.3
597 // client to send part of Finished unencrypted in the same record as
598 // ClientHello.
599 PartialClientFinishedWithClientHello bool
600
David Benjamind86c7672014-08-02 04:07:12 -0400601 // SendV2ClientHello causes the client to send a V2ClientHello
602 // instead of a normal ClientHello.
603 SendV2ClientHello bool
David Benjaminbef270a2014-08-02 04:22:02 -0400604
605 // SendFallbackSCSV causes the client to include
606 // TLS_FALLBACK_SCSV in the ClientHello.
607 SendFallbackSCSV bool
David Benjamin43ec06f2014-08-05 02:28:57 -0400608
Adam Langley5021b222015-06-12 18:27:58 -0700609 // SendRenegotiationSCSV causes the client to include the renegotiation
610 // SCSV in the ClientHello.
611 SendRenegotiationSCSV bool
612
David Benjamin43ec06f2014-08-05 02:28:57 -0400613 // MaxHandshakeRecordLength, if non-zero, is the maximum size of a
David Benjamin98214542014-08-07 18:02:39 -0400614 // handshake record. Handshake messages will be split into multiple
615 // records at the specified size, except that the client_version will
David Benjaminbd15a8e2015-05-29 18:48:16 -0400616 // never be fragmented. For DTLS, it is the maximum handshake fragment
617 // size, not record size; DTLS allows multiple handshake fragments in a
618 // single handshake record. See |PackHandshakeFragments|.
David Benjamin43ec06f2014-08-05 02:28:57 -0400619 MaxHandshakeRecordLength int
David Benjamina8e3e0e2014-08-06 22:11:10 -0400620
David Benjamin98214542014-08-07 18:02:39 -0400621 // FragmentClientVersion will allow MaxHandshakeRecordLength to apply to
622 // the first 6 bytes of the ClientHello.
623 FragmentClientVersion bool
624
Alex Chernyakhovsky4cd8c432014-11-01 19:39:08 -0400625 // FragmentAlert will cause all alerts to be fragmented across
626 // two records.
627 FragmentAlert bool
628
David Benjamin0d3a8c62016-03-11 22:25:18 -0500629 // DoubleAlert will cause all alerts to be sent as two copies packed
630 // within one record.
631 DoubleAlert bool
632
David Benjamin3fd1fbd2015-02-03 16:07:32 -0500633 // SendSpuriousAlert, if non-zero, will cause an spurious, unwanted
634 // alert to be sent.
635 SendSpuriousAlert alert
Alex Chernyakhovsky4cd8c432014-11-01 19:39:08 -0400636
David Benjaminb36a3952015-12-01 18:53:13 -0500637 // BadRSAClientKeyExchange causes the client to send a corrupted RSA
638 // ClientKeyExchange which would not pass padding checks.
639 BadRSAClientKeyExchange RSABadValue
David Benjaminbed9aae2014-08-07 19:13:38 -0400640
641 // RenewTicketOnResume causes the server to renew the session ticket and
642 // send a NewSessionTicket message during an abbreviated handshake.
643 RenewTicketOnResume bool
David Benjamin98e882e2014-08-08 13:24:34 -0400644
David Benjamin3c6a1ea2016-09-26 18:30:05 -0400645 // SendClientVersion, if non-zero, causes the client to send the
646 // specified value in the ClientHello version field.
David Benjamin98e882e2014-08-08 13:24:34 -0400647 SendClientVersion uint16
David Benjamin83c0bc92014-08-04 01:23:53 -0400648
Steven Valdezfdd10992016-09-15 16:27:05 -0400649 // OmitSupportedVersions, if true, causes the client to omit the
650 // supported versions extension.
651 OmitSupportedVersions bool
652
653 // SendSupportedVersions, if non-empty, causes the client to send a
654 // supported versions extension with the values from array.
655 SendSupportedVersions []uint16
656
David Benjamin1f61f0d2016-07-10 12:20:35 -0400657 // NegotiateVersion, if non-zero, causes the server to negotiate the
Steven Valdezc94998a2017-06-20 10:55:02 -0400658 // specifed wire version rather than the version supported by either
David Benjamin1f61f0d2016-07-10 12:20:35 -0400659 // peer.
660 NegotiateVersion uint16
661
David Benjamine7e36aa2016-08-08 12:39:41 -0400662 // NegotiateVersionOnRenego, if non-zero, causes the server to negotiate
Steven Valdezc94998a2017-06-20 10:55:02 -0400663 // the specified wire version on renegotiation rather than retaining it.
David Benjamine7e36aa2016-08-08 12:39:41 -0400664 NegotiateVersionOnRenego uint16
665
David Benjamine58c4f52014-08-24 03:47:07 -0400666 // ExpectFalseStart causes the server to, on full handshakes,
667 // expect the peer to False Start; the server Finished message
668 // isn't sent until we receive an application data record
669 // from the peer.
670 ExpectFalseStart bool
David Benjamin5c24a1d2014-08-31 00:59:27 -0400671
David Benjamin1c633152015-04-02 20:19:11 -0400672 // AlertBeforeFalseStartTest, if non-zero, causes the server to, on full
673 // handshakes, send an alert just before reading the application data
674 // record to test False Start. This can be used in a negative False
675 // Start test to determine whether the peer processed the alert (and
676 // closed the connection) before or after sending app data.
677 AlertBeforeFalseStartTest alert
678
David Benjamine78bfde2014-09-06 12:45:15 -0400679 // ExpectServerName, if not empty, is the hostname the client
680 // must specify in the server_name extension.
681 ExpectServerName string
David Benjaminfc7b0862014-09-06 13:21:53 -0400682
David Benjamin76c2efc2015-08-31 14:24:29 -0400683 // SwapNPNAndALPN switches the relative order between NPN and ALPN in
684 // both ClientHello and ServerHello.
David Benjaminfc7b0862014-09-06 13:21:53 -0400685 SwapNPNAndALPN bool
David Benjamin01fe8202014-09-24 15:21:44 -0400686
Adam Langleyefb0e162015-07-09 11:35:04 -0700687 // ALPNProtocol, if not nil, sets the ALPN protocol that a server will
688 // return.
689 ALPNProtocol *string
690
David Benjamin405da482016-08-08 17:25:07 -0400691 // AcceptAnySession causes the server to resume sessions regardless of
692 // the version associated with the session or cipher suite. It also
693 // causes the server to look in both TLS 1.2 and 1.3 extensions to
694 // process a ticket.
695 AcceptAnySession bool
696
697 // SendBothTickets, if true, causes the client to send tickets in both
698 // TLS 1.2 and 1.3 extensions.
699 SendBothTickets bool
Adam Langley38311732014-10-16 19:04:35 -0700700
David Benjamin4199b0d2016-11-01 13:58:25 -0400701 // FilterTicket, if not nil, causes the client to modify a session
702 // ticket before sending it in a resume handshake.
703 FilterTicket func([]byte) ([]byte, error)
Adam Langley38311732014-10-16 19:04:35 -0700704
David Benjamind4c349b2017-02-09 14:07:17 -0500705 // TicketSessionIDLength, if non-zero, is the length of the session ID
706 // to send with a ticket resumption offer.
707 TicketSessionIDLength int
708
709 // EmptyTicketSessionID, if true, causes the client to send an empty
710 // session ID with a ticket resumption offer. For simplicity, this will
711 // also cause the client to interpret a ServerHello with empty session
712 // ID as a resumption. (A client which sends empty session ID is
713 // normally expected to look ahead for ChangeCipherSpec.)
714 EmptyTicketSessionID bool
Adam Langley75712922014-10-10 16:23:43 -0700715
David Benjamin405da482016-08-08 17:25:07 -0400716 // ExpectNoTLS12Session, if true, causes the server to fail the
717 // connection if either a session ID or TLS 1.2 ticket is offered.
718 ExpectNoTLS12Session bool
719
720 // ExpectNoTLS13PSK, if true, causes the server to fail the connection
721 // if a TLS 1.3 PSK is offered.
722 ExpectNoTLS13PSK bool
723
Adam Langley75712922014-10-10 16:23:43 -0700724 // RequireExtendedMasterSecret, if true, requires that the peer support
725 // the extended master secret option.
726 RequireExtendedMasterSecret bool
727
David Benjaminca6554b2014-11-08 12:31:52 -0500728 // NoExtendedMasterSecret causes the client and server to behave as if
David Benjamin163c9562016-08-29 23:14:17 -0400729 // they didn't support an extended master secret in the initial
730 // handshake.
Adam Langley75712922014-10-10 16:23:43 -0700731 NoExtendedMasterSecret bool
Adam Langley2ae77d22014-10-28 17:29:33 -0700732
David Benjamin163c9562016-08-29 23:14:17 -0400733 // NoExtendedMasterSecretOnRenegotiation causes the client and server to
734 // behave as if they didn't support an extended master secret in
735 // renegotiation handshakes.
736 NoExtendedMasterSecretOnRenegotiation bool
737
Adam Langley2ae77d22014-10-28 17:29:33 -0700738 // EmptyRenegotiationInfo causes the renegotiation extension to be
739 // empty in a renegotiation handshake.
740 EmptyRenegotiationInfo bool
741
742 // BadRenegotiationInfo causes the renegotiation extension value in a
David Benjamin9343b0b2017-07-01 00:31:27 -0400743 // renegotiation handshake to be incorrect at the start.
Adam Langley2ae77d22014-10-28 17:29:33 -0700744 BadRenegotiationInfo bool
David Benjamin5e961c12014-11-07 01:48:35 -0500745
David Benjamin9343b0b2017-07-01 00:31:27 -0400746 // BadRenegotiationInfoEnd causes the renegotiation extension value in
747 // a renegotiation handshake to be incorrect at the end.
748 BadRenegotiationInfoEnd bool
749
David Benjamin3e052de2015-11-25 20:10:31 -0500750 // NoRenegotiationInfo disables renegotiation info support in all
751 // handshakes.
David Benjaminca6554b2014-11-08 12:31:52 -0500752 NoRenegotiationInfo bool
753
David Benjamin3e052de2015-11-25 20:10:31 -0500754 // NoRenegotiationInfoInInitial disables renegotiation info support in
755 // the initial handshake.
756 NoRenegotiationInfoInInitial bool
757
758 // NoRenegotiationInfoAfterInitial disables renegotiation info support
759 // in renegotiation handshakes.
760 NoRenegotiationInfoAfterInitial bool
761
Adam Langley5021b222015-06-12 18:27:58 -0700762 // RequireRenegotiationInfo, if true, causes the client to return an
763 // error if the server doesn't reply with the renegotiation extension.
764 RequireRenegotiationInfo bool
765
David Benjamin8e6db492015-07-25 18:29:23 -0400766 // SequenceNumberMapping, if non-nil, is the mapping function to apply
767 // to the sequence number of outgoing packets. For both TLS and DTLS,
768 // the two most-significant bytes in the resulting sequence number are
769 // ignored so that the DTLS epoch cannot be changed.
770 SequenceNumberMapping func(uint64) uint64
David Benjamin9114fae2014-11-08 11:41:14 -0500771
David Benjamina3e89492015-02-26 15:16:22 -0500772 // RSAEphemeralKey, if true, causes the server to send a
773 // ServerKeyExchange message containing an ephemeral key (as in
774 // RSA_EXPORT) in the plain RSA key exchange.
775 RSAEphemeralKey bool
David Benjaminca6c8262014-11-15 19:06:08 -0500776
777 // SRTPMasterKeyIdentifer, if not empty, is the SRTP MKI value that the
778 // client offers when negotiating SRTP. MKI support is still missing so
779 // the peer must still send none.
780 SRTPMasterKeyIdentifer string
781
782 // SendSRTPProtectionProfile, if non-zero, is the SRTP profile that the
783 // server sends in the ServerHello instead of the negotiated one.
784 SendSRTPProtectionProfile uint16
David Benjamin000800a2014-11-14 01:43:59 -0500785
Nick Harper60edffd2016-06-21 15:19:24 -0700786 // NoSignatureAlgorithms, if true, causes the client to omit the
David Benjamin000800a2014-11-14 01:43:59 -0500787 // signature and hashes extension.
788 //
789 // For a server, it will cause an empty list to be sent in the
790 // CertificateRequest message. None the less, the configured set will
791 // still be enforced.
Nick Harper60edffd2016-06-21 15:19:24 -0700792 NoSignatureAlgorithms bool
David Benjaminc44b1df2014-11-23 12:11:01 -0500793
David Benjamin55a43642015-04-20 14:45:55 -0400794 // NoSupportedCurves, if true, causes the client to omit the
795 // supported_curves extension.
796 NoSupportedCurves bool
797
David Benjaminc44b1df2014-11-23 12:11:01 -0500798 // RequireSameRenegoClientVersion, if true, causes the server
799 // to require that all ClientHellos match in offered version
800 // across a renego.
801 RequireSameRenegoClientVersion bool
Feng Lu41aa3252014-11-21 22:47:56 -0800802
David Benjaminb1dd8cd2016-09-26 19:20:48 -0400803 // ExpectInitialRecordVersion, if non-zero, is the expected value of
David Benjamine6f22212016-11-08 14:28:24 -0500804 // record-layer version field before the protocol version is determined.
David Benjamin1e29a6b2014-12-10 02:27:24 -0500805 ExpectInitialRecordVersion uint16
David Benjamin13be1de2015-01-11 16:29:36 -0500806
David Benjamine6f22212016-11-08 14:28:24 -0500807 // SendRecordVersion, if non-zero, is the value to send as the
808 // record-layer version.
809 SendRecordVersion uint16
810
811 // SendInitialRecordVersion, if non-zero, is the value to send as the
812 // record-layer version before the protocol version is determined.
813 SendInitialRecordVersion uint16
814
David Benjamin13be1de2015-01-11 16:29:36 -0500815 // MaxPacketLength, if non-zero, is the maximum acceptable size for a
816 // packet.
817 MaxPacketLength int
David Benjamin6095de82014-12-27 01:50:38 -0500818
819 // SendCipherSuite, if non-zero, is the cipher suite value that the
820 // server will send in the ServerHello. This does not affect the cipher
821 // the server believes it has actually negotiated.
822 SendCipherSuite uint16
David Benjamin4189bd92015-01-25 23:52:39 -0500823
David Benjamin75f99142016-11-12 12:36:06 +0900824 // SendCipherSuites, if not nil, is the cipher suite list that the
825 // client will send in the ClientHello. This does not affect the cipher
826 // the client believes it has actually offered.
827 SendCipherSuites []uint16
828
David Benjamin4cf369b2015-08-22 01:35:43 -0400829 // AppDataBeforeHandshake, if not nil, causes application data to be
830 // sent immediately before the first handshake message.
831 AppDataBeforeHandshake []byte
832
833 // AppDataAfterChangeCipherSpec, if not nil, causes application data to
David Benjamin4189bd92015-01-25 23:52:39 -0500834 // be sent immediately after ChangeCipherSpec.
835 AppDataAfterChangeCipherSpec []byte
David Benjamin83f90402015-01-27 01:09:43 -0500836
David Benjamindc3da932015-03-12 15:09:02 -0400837 // AlertAfterChangeCipherSpec, if non-zero, causes an alert to be sent
838 // immediately after ChangeCipherSpec.
839 AlertAfterChangeCipherSpec alert
840
David Benjamin83f90402015-01-27 01:09:43 -0500841 // TimeoutSchedule is the schedule of packet drops and simulated
842 // timeouts for before each handshake leg from the peer.
843 TimeoutSchedule []time.Duration
844
845 // PacketAdaptor is the packetAdaptor to use to simulate timeouts.
846 PacketAdaptor *packetAdaptor
David Benjaminb3774b92015-01-31 17:16:01 -0500847
848 // ReorderHandshakeFragments, if true, causes handshake fragments in
849 // DTLS to overlap and be sent in the wrong order. It also causes
850 // pre-CCS flights to be sent twice. (Post-CCS flights consist of
851 // Finished and will trigger a spurious retransmit.)
852 ReorderHandshakeFragments bool
David Benjaminddb9f152015-02-03 15:44:39 -0500853
David Benjamin61672812016-07-14 23:10:43 -0400854 // ReverseHandshakeFragments, if true, causes handshake fragments in
855 // DTLS to be reversed within a flight.
856 ReverseHandshakeFragments bool
857
David Benjamin75381222015-03-02 19:30:30 -0500858 // MixCompleteMessageWithFragments, if true, causes handshake
859 // messages in DTLS to redundantly both fragment the message
860 // and include a copy of the full one.
861 MixCompleteMessageWithFragments bool
862
David Benjaminddb9f152015-02-03 15:44:39 -0500863 // SendInvalidRecordType, if true, causes a record with an invalid
864 // content type to be sent immediately following the handshake.
865 SendInvalidRecordType bool
David Benjaminbcb2d912015-02-24 23:45:43 -0500866
David Benjamin0b8d5da2016-07-15 00:39:56 -0400867 // SendWrongMessageType, if non-zero, causes messages of the specified
868 // type to be sent with the wrong value.
869 SendWrongMessageType byte
David Benjamin75381222015-03-02 19:30:30 -0500870
David Benjamin639846e2016-09-09 11:41:18 -0400871 // SendTrailingMessageData, if non-zero, causes messages of the
872 // specified type to be sent with trailing data.
873 SendTrailingMessageData byte
874
David Benjamin75381222015-03-02 19:30:30 -0500875 // FragmentMessageTypeMismatch, if true, causes all non-initial
876 // handshake fragments in DTLS to have the wrong message type.
877 FragmentMessageTypeMismatch bool
878
879 // FragmentMessageLengthMismatch, if true, causes all non-initial
880 // handshake fragments in DTLS to have the wrong message length.
881 FragmentMessageLengthMismatch bool
882
David Benjamin11fc66a2015-06-16 11:40:24 -0400883 // SplitFragments, if non-zero, causes the handshake fragments in DTLS
884 // to be split across two records. The value of |SplitFragments| is the
885 // number of bytes in the first fragment.
886 SplitFragments int
David Benjamin75381222015-03-02 19:30:30 -0500887
888 // SendEmptyFragments, if true, causes handshakes to include empty
889 // fragments in DTLS.
890 SendEmptyFragments bool
David Benjamincdea40c2015-03-19 14:09:43 -0400891
David Benjamin9a41d1b2015-05-16 01:30:09 -0400892 // SendSplitAlert, if true, causes an alert to be sent with the header
893 // and record body split across multiple packets. The peer should
894 // discard these packets rather than process it.
895 SendSplitAlert bool
896
David Benjamin4b27d9f2015-05-12 22:42:52 -0400897 // FailIfResumeOnRenego, if true, causes renegotiations to fail if the
898 // client offers a resumption or the server accepts one.
899 FailIfResumeOnRenego bool
David Benjamin3c9746a2015-03-19 15:00:10 -0400900
David Benjamin67d1fb52015-03-16 15:16:23 -0400901 // IgnorePeerCipherPreferences, if true, causes the peer's cipher
902 // preferences to be ignored.
903 IgnorePeerCipherPreferences bool
David Benjamin72dc7832015-03-16 17:49:43 -0400904
905 // IgnorePeerSignatureAlgorithmPreferences, if true, causes the peer's
906 // signature algorithm preferences to be ignored.
907 IgnorePeerSignatureAlgorithmPreferences bool
David Benjamin340d5ed2015-03-21 02:21:37 -0400908
David Benjaminc574f412015-04-20 11:13:01 -0400909 // IgnorePeerCurvePreferences, if true, causes the peer's curve
910 // preferences to be ignored.
911 IgnorePeerCurvePreferences bool
912
David Benjamin513f0ea2015-04-02 19:33:31 -0400913 // BadFinished, if true, causes the Finished hash to be broken.
914 BadFinished bool
Adam Langleya7997f12015-05-14 17:38:50 -0700915
David Benjamin582ba042016-07-07 12:33:25 -0700916 // PackHandshakeFragments, if true, causes handshake fragments in DTLS
917 // to be packed into individual handshake records, up to the specified
918 // record size.
David Benjaminbd15a8e2015-05-29 18:48:16 -0400919 PackHandshakeFragments int
920
David Benjamin582ba042016-07-07 12:33:25 -0700921 // PackHandshakeRecords, if true, causes handshake records in DTLS to be
922 // packed into individual packets, up to the specified packet size.
David Benjaminbd15a8e2015-05-29 18:48:16 -0400923 PackHandshakeRecords int
David Benjamin0fa40122015-05-30 17:13:12 -0400924
David Benjamin582ba042016-07-07 12:33:25 -0700925 // PackHandshakeFlight, if true, causes each handshake flight in TLS to
926 // be packed into records, up to the largest size record available.
927 PackHandshakeFlight bool
928
David Benjamin5ecb88b2016-10-04 17:51:35 -0400929 // AdvertiseAllConfiguredCiphers, if true, causes the client to
930 // advertise all configured cipher suite values.
931 AdvertiseAllConfiguredCiphers bool
David Benjamin8923c0b2015-06-07 11:42:34 -0400932
933 // EmptyCertificateList, if true, causes the server to send an empty
934 // certificate list in the Certificate message.
935 EmptyCertificateList bool
David Benjamind98452d2015-06-16 14:16:23 -0400936
937 // ExpectNewTicket, if true, causes the client to abort if it does not
938 // receive a new ticket.
939 ExpectNewTicket bool
Adam Langley33ad2b52015-07-20 17:43:53 -0700940
941 // RequireClientHelloSize, if not zero, is the required length in bytes
942 // of the ClientHello /record/. This is checked by the server.
943 RequireClientHelloSize int
Adam Langley09505632015-07-30 18:10:13 -0700944
945 // CustomExtension, if not empty, contains the contents of an extension
946 // that will be added to client/server hellos.
947 CustomExtension string
948
David Benjamin490469f2016-10-05 22:44:38 -0400949 // CustomUnencryptedExtension, if not empty, contains the contents of
950 // an extension that will be added to ServerHello in TLS 1.3.
951 CustomUnencryptedExtension string
952
Adam Langley09505632015-07-30 18:10:13 -0700953 // ExpectedCustomExtension, if not nil, contains the expected contents
954 // of a custom extension.
955 ExpectedCustomExtension *string
David Benjamin30789da2015-08-29 22:56:45 -0400956
David Benjamin1286bee2016-10-07 15:25:06 -0400957 // CustomTicketExtension, if not empty, contains the contents of an
958 // extension what will be added to NewSessionTicket in TLS 1.3.
959 CustomTicketExtension string
960
David Benjamin3baa6e12016-10-07 21:10:38 -0400961 // CustomTicketExtension, if not empty, contains the contents of an
962 // extension what will be added to HelloRetryRequest in TLS 1.3.
963 CustomHelloRetryRequestExtension string
964
David Benjamin30789da2015-08-29 22:56:45 -0400965 // NoCloseNotify, if true, causes the close_notify alert to be skipped
966 // on connection shutdown.
967 NoCloseNotify bool
968
David Benjaminfa214e42016-05-10 17:03:10 -0400969 // SendAlertOnShutdown, if non-zero, is the alert to send instead of
970 // close_notify on shutdown.
971 SendAlertOnShutdown alert
972
David Benjamin30789da2015-08-29 22:56:45 -0400973 // ExpectCloseNotify, if true, requires a close_notify from the peer on
974 // shutdown. Records from the peer received after close_notify is sent
975 // are not discard.
976 ExpectCloseNotify bool
David Benjamin2c99d282015-09-01 10:23:00 -0400977
978 // SendLargeRecords, if true, allows outgoing records to be sent
979 // arbitrarily large.
980 SendLargeRecords bool
David Benjamin76c2efc2015-08-31 14:24:29 -0400981
982 // NegotiateALPNAndNPN, if true, causes the server to negotiate both
983 // ALPN and NPN in the same connetion.
984 NegotiateALPNAndNPN bool
David Benjamindd6fed92015-10-23 17:41:12 -0400985
David Benjamin0c40a962016-08-01 12:05:50 -0400986 // SendALPN, if non-empty, causes the server to send the specified
David Benjamin3e517572016-08-11 11:52:23 -0400987 // string in the ALPN extension regardless of the content or presence of
988 // the client offer.
David Benjamin0c40a962016-08-01 12:05:50 -0400989 SendALPN string
990
David Benjamin490469f2016-10-05 22:44:38 -0400991 // SendUnencryptedALPN, if non-empty, causes the server to send the
992 // specified string in a ServerHello ALPN extension in TLS 1.3.
993 SendUnencryptedALPN string
994
David Benjamindd6fed92015-10-23 17:41:12 -0400995 // SendEmptySessionTicket, if true, causes the server to send an empty
996 // session ticket.
997 SendEmptySessionTicket bool
998
Steven Valdeza833c352016-11-01 13:39:36 -0400999 // SendPSKKeyExchangeModes, if present, determines the PSK key exchange modes
Steven Valdez5b986082016-09-01 12:29:49 -04001000 // to send.
1001 SendPSKKeyExchangeModes []byte
1002
Steven Valdeza833c352016-11-01 13:39:36 -04001003 // ExpectNoNewSessionTicket, if present, means that the client will fail upon
1004 // receipt of a NewSessionTicket message.
1005 ExpectNoNewSessionTicket bool
1006
David Benjamin9c33ae82017-01-08 06:04:43 -05001007 // DuplicateTicketEarlyDataInfo causes an extra empty extension of
1008 // ticket_early_data_info to be sent in NewSessionTicket.
1009 DuplicateTicketEarlyDataInfo bool
1010
Steven Valdez08b65f42016-12-07 15:29:45 -05001011 // ExpectTicketEarlyDataInfo, if true, means that the client will fail upon
1012 // absence of the ticket_early_data_info extension.
1013 ExpectTicketEarlyDataInfo bool
1014
Steven Valdeza833c352016-11-01 13:39:36 -04001015 // ExpectTicketAge, if non-zero, is the expected age of the ticket that the
1016 // server receives from the client.
1017 ExpectTicketAge time.Duration
Steven Valdez5b986082016-09-01 12:29:49 -04001018
David Benjamin35ac5b72017-03-03 15:05:56 -05001019 // SendTicketAge, if non-zero, is the ticket age to be sent by the
1020 // client.
1021 SendTicketAge time.Duration
1022
David Benjamindd6fed92015-10-23 17:41:12 -04001023 // FailIfSessionOffered, if true, causes the server to fail any
1024 // connections where the client offers a non-empty session ID or session
1025 // ticket.
1026 FailIfSessionOffered bool
Adam Langley27a0d082015-11-03 13:34:10 -08001027
1028 // SendHelloRequestBeforeEveryAppDataRecord, if true, causes a
1029 // HelloRequest handshake message to be sent before each application
1030 // data record. This only makes sense for a server.
1031 SendHelloRequestBeforeEveryAppDataRecord bool
Adam Langleyc4f25ce2015-11-26 16:39:08 -08001032
David Benjamin71dd6662016-07-08 14:10:48 -07001033 // SendHelloRequestBeforeEveryHandshakeMessage, if true, causes a
1034 // HelloRequest handshake message to be sent before each handshake
1035 // message. This only makes sense for a server.
1036 SendHelloRequestBeforeEveryHandshakeMessage bool
1037
David Benjamin8411b242015-11-26 12:07:28 -05001038 // BadChangeCipherSpec, if not nil, is the body to be sent in
1039 // ChangeCipherSpec records instead of {1}.
1040 BadChangeCipherSpec []byte
David Benjaminef5dfd22015-12-06 13:17:07 -05001041
1042 // BadHelloRequest, if not nil, is what to send instead of a
1043 // HelloRequest.
1044 BadHelloRequest []byte
David Benjaminef1b0092015-11-21 14:05:44 -05001045
1046 // RequireSessionTickets, if true, causes the client to require new
1047 // sessions use session tickets instead of session IDs.
1048 RequireSessionTickets bool
David Benjaminf2b83632016-03-01 22:57:46 -05001049
1050 // NullAllCiphers, if true, causes every cipher to behave like the null
1051 // cipher.
1052 NullAllCiphers bool
David Benjamin80d1b352016-05-04 19:19:06 -04001053
1054 // SendSCTListOnResume, if not nil, causes the server to send the
1055 // supplied SCT list in resumption handshakes.
1056 SendSCTListOnResume []byte
Matt Braithwaite54217e42016-06-13 13:03:47 -07001057
David Benjamindaa88502016-10-04 16:32:16 -04001058 // SendOCSPResponseOnResume, if not nil, causes the server to advertise
1059 // OCSP stapling in resumption handshakes and, if applicable, send the
1060 // supplied stapled response.
1061 SendOCSPResponseOnResume []byte
1062
Steven Valdeza833c352016-11-01 13:39:36 -04001063 // SendExtensionOnCertificate, if not nil, causes the runner to send the
1064 // supplied bytes in the extensions on the Certificate message.
1065 SendExtensionOnCertificate []byte
1066
1067 // SendOCSPOnIntermediates, if not nil, causes the server to send the
1068 // supplied OCSP on intermediate certificates in the Certificate message.
1069 SendOCSPOnIntermediates []byte
1070
1071 // SendSCTOnIntermediates, if not nil, causes the server to send the
1072 // supplied SCT on intermediate certificates in the Certificate message.
1073 SendSCTOnIntermediates []byte
1074
1075 // SendDuplicateCertExtensions, if true, causes the server to send an extra
1076 // copy of the OCSP/SCT extensions in the Certificate message.
1077 SendDuplicateCertExtensions bool
1078
1079 // ExpectNoExtensionsOnIntermediate, if true, causes the client to
1080 // reject extensions on intermediate certificates.
1081 ExpectNoExtensionsOnIntermediate bool
1082
David Benjaminc9ae27c2016-06-24 22:56:37 -04001083 // RecordPadding is the number of bytes of padding to add to each
1084 // encrypted record in TLS 1.3.
1085 RecordPadding int
1086
1087 // OmitRecordContents, if true, causes encrypted records in TLS 1.3 to
1088 // be missing their body and content type. Padding, if configured, is
1089 // still added.
1090 OmitRecordContents bool
1091
1092 // OuterRecordType, if non-zero, is the outer record type to use instead
1093 // of application data.
1094 OuterRecordType recordType
David Benjamina95e9f32016-07-08 16:28:04 -07001095
1096 // SendSignatureAlgorithm, if non-zero, causes all signatures to be sent
1097 // with the given signature algorithm rather than the one negotiated.
1098 SendSignatureAlgorithm signatureAlgorithm
David Benjamin1fb125c2016-07-08 18:52:12 -07001099
1100 // SkipECDSACurveCheck, if true, causes all ECDSA curve checks to be
1101 // skipped.
1102 SkipECDSACurveCheck bool
David Benjaminfd5c45f2016-06-30 18:30:40 -04001103
1104 // IgnoreSignatureVersionChecks, if true, causes all signature
1105 // algorithms to be enabled at all TLS versions.
1106 IgnoreSignatureVersionChecks bool
Steven Valdez143e8b32016-07-11 13:19:03 -04001107
1108 // NegotiateRenegotiationInfoAtAllVersions, if true, causes
1109 // Renegotiation Info to be negotiated at all versions.
1110 NegotiateRenegotiationInfoAtAllVersions bool
1111
Steven Valdez143e8b32016-07-11 13:19:03 -04001112 // NegotiateNPNAtAllVersions, if true, causes NPN to be negotiated at
1113 // all versions.
1114 NegotiateNPNAtAllVersions bool
1115
1116 // NegotiateEMSAtAllVersions, if true, causes EMS to be negotiated at
1117 // all versions.
1118 NegotiateEMSAtAllVersions bool
1119
1120 // AdvertiseTicketExtension, if true, causes the ticket extension to be
1121 // advertised in server extensions
1122 AdvertiseTicketExtension bool
1123
Steven Valdez803c77a2016-09-06 14:13:43 -04001124 // NegotiatePSKResumption, if true, causes the server to attempt pure PSK
1125 // resumption.
1126 NegotiatePSKResumption bool
1127
David Benjamin7f78df42016-10-05 22:33:19 -04001128 // AlwaysSelectPSKIdentity, if true, causes the server in TLS 1.3 to
1129 // always acknowledge a session, regardless of one was offered.
1130 AlwaysSelectPSKIdentity bool
1131
1132 // SelectPSKIdentityOnResume, if non-zero, causes the server to select
1133 // the specified PSK identity index rather than the actual value.
1134 SelectPSKIdentityOnResume uint16
1135
Steven Valdezaf3b8a92016-11-01 12:49:22 -04001136 // ExtraPSKIdentity, if true, causes the client to send an extra PSK
1137 // identity.
1138 ExtraPSKIdentity bool
1139
Steven Valdez143e8b32016-07-11 13:19:03 -04001140 // MissingKeyShare, if true, causes the TLS 1.3 implementation to skip
1141 // sending a key_share extension and use the zero ECDHE secret
1142 // instead.
1143 MissingKeyShare bool
1144
Steven Valdez5440fe02016-07-18 12:40:30 -04001145 // SecondClientHelloMissingKeyShare, if true, causes the second TLS 1.3
1146 // ClientHello to skip sending a key_share extension and use the zero
1147 // ECDHE secret instead.
1148 SecondClientHelloMissingKeyShare bool
1149
1150 // MisinterpretHelloRetryRequestCurve, if non-zero, causes the TLS 1.3
1151 // client to pretend the server requested a HelloRetryRequest with the
1152 // given curve rather than the actual one.
1153 MisinterpretHelloRetryRequestCurve CurveID
1154
Steven Valdez143e8b32016-07-11 13:19:03 -04001155 // DuplicateKeyShares, if true, causes the TLS 1.3 client to send two
1156 // copies of each KeyShareEntry.
1157 DuplicateKeyShares bool
1158
Steven Valdeza4ee74d2016-11-29 13:36:45 -05001159 // SendEarlyAlert, if true, sends a fatal alert after the ClientHello.
1160 SendEarlyAlert bool
1161
Nick Harperf2511f12016-12-06 16:02:31 -08001162 // SendFakeEarlyDataLength, if non-zero, is the amount of early data to
1163 // send after the ClientHello.
1164 SendFakeEarlyDataLength int
Steven Valdeza4ee74d2016-11-29 13:36:45 -05001165
Steven Valdez681eb6a2016-12-19 13:19:29 -05001166 // SendStrayEarlyHandshake, if non-zero, causes the client to send a stray
1167 // handshake record before sending end of early data.
1168 SendStrayEarlyHandshake bool
1169
Steven Valdeza4ee74d2016-11-29 13:36:45 -05001170 // OmitEarlyDataExtension, if true, causes the early data extension to
1171 // be omitted in the ClientHello.
1172 OmitEarlyDataExtension bool
1173
1174 // SendEarlyDataOnSecondClientHello, if true, causes the TLS 1.3 client to
1175 // send early data after the second ClientHello.
1176 SendEarlyDataOnSecondClientHello bool
1177
1178 // InterleaveEarlyData, if true, causes the TLS 1.3 client to send early
1179 // data interleaved with the second ClientHello and the client Finished.
1180 InterleaveEarlyData bool
1181
Nick Harperf2511f12016-12-06 16:02:31 -08001182 // SendEarlyData causes a TLS 1.3 client to send the provided data
1183 // in application data records immediately after the ClientHello,
Steven Valdez2d850622017-01-11 11:34:52 -05001184 // provided that the client offers a TLS 1.3 session. It will do this
1185 // whether or not the server advertised early data for the ticket.
Nick Harperf2511f12016-12-06 16:02:31 -08001186 SendEarlyData [][]byte
1187
Steven Valdez2d850622017-01-11 11:34:52 -05001188 // ExpectEarlyDataAccepted causes a TLS 1.3 client to check that early data
1189 // was accepted by the server.
1190 ExpectEarlyDataAccepted bool
1191
1192 // AlwaysAcceptEarlyData causes a TLS 1.3 server to always accept early data
1193 // regardless of ALPN mismatch.
1194 AlwaysAcceptEarlyData bool
1195
1196 // AlwaysRejectEarlyData causes a TLS 1.3 server to always reject early data.
1197 AlwaysRejectEarlyData bool
1198
1199 // SendEarlyDataExtension, if true, causes a TLS 1.3 server to send the
1200 // early_data extension in EncryptedExtensions, independent of whether
1201 // it was accepted.
1202 SendEarlyDataExtension bool
1203
Nick Harperab20cec2016-12-19 17:38:41 -08001204 // ExpectEarlyData causes a TLS 1.3 server to read application
1205 // data after the ClientHello (assuming the server is able to
1206 // derive the key under which the data is encrypted) before it
1207 // sends a ServerHello. It checks that the application data it
1208 // reads matches what is provided in ExpectEarlyData and errors if
1209 // the number of records or their content do not match.
1210 ExpectEarlyData [][]byte
1211
Steven Valdeze831a812017-03-09 14:56:07 -05001212 // ExpectLateEarlyData causes a TLS 1.3 server to read application
1213 // data after the ServerFinished (assuming the server is able to
1214 // derive the key under which the data is encrypted) before it
1215 // sends the ClientFinished. It checks that the application data it
1216 // reads matches what is provided in ExpectLateEarlyData and errors if
1217 // the number of records or their content do not match.
1218 ExpectLateEarlyData [][]byte
1219
Nick Harper7cd0a972016-12-02 11:08:40 -08001220 // SendHalfRTTData causes a TLS 1.3 server to send the provided
1221 // data in application data records before reading the client's
1222 // Finished message.
1223 SendHalfRTTData [][]byte
1224
David Benjamin794cc592017-03-25 22:24:23 -05001225 // ExpectHalfRTTData causes a TLS 1.3 client, if 0-RTT was accepted, to
1226 // read application data after reading the server's Finished message and
1227 // before sending any subsequent handshake messages. It checks that the
Nick Harper7cd0a972016-12-02 11:08:40 -08001228 // application data it reads matches what is provided in
1229 // ExpectHalfRTTData and errors if the number of records or their
1230 // content do not match.
1231 ExpectHalfRTTData [][]byte
1232
Steven Valdez143e8b32016-07-11 13:19:03 -04001233 // EmptyEncryptedExtensions, if true, causes the TLS 1.3 server to
1234 // emit an empty EncryptedExtensions block.
1235 EmptyEncryptedExtensions bool
1236
1237 // EncryptedExtensionsWithKeyShare, if true, causes the TLS 1.3 server to
1238 // include the KeyShare extension in the EncryptedExtensions block.
1239 EncryptedExtensionsWithKeyShare bool
Steven Valdez5440fe02016-07-18 12:40:30 -04001240
David Benjamin3baa6e12016-10-07 21:10:38 -04001241 // AlwaysSendHelloRetryRequest, if true, causes a HelloRetryRequest to
1242 // be sent by the server, even if empty.
1243 AlwaysSendHelloRetryRequest bool
Steven Valdez5440fe02016-07-18 12:40:30 -04001244
1245 // SecondHelloRetryRequest, if true, causes the TLS 1.3 server to send
1246 // two HelloRetryRequests instead of one.
1247 SecondHelloRetryRequest bool
1248
David Benjamin3baa6e12016-10-07 21:10:38 -04001249 // SendHelloRetryRequestCurve, if non-zero, causes the server to send
1250 // the specified curve in a HelloRetryRequest.
1251 SendHelloRetryRequestCurve CurveID
1252
1253 // SendHelloRetryRequestCookie, if not nil, contains a cookie to be
1254 // sent by the server in HelloRetryRequest.
1255 SendHelloRetryRequestCookie []byte
1256
1257 // DuplicateHelloRetryRequestExtensions, if true, causes all
1258 // HelloRetryRequest extensions to be sent twice.
1259 DuplicateHelloRetryRequestExtensions bool
1260
Steven Valdez5440fe02016-07-18 12:40:30 -04001261 // SendServerHelloVersion, if non-zero, causes the server to send the
David Benjamin3c6a1ea2016-09-26 18:30:05 -04001262 // specified value in ServerHello version field.
Steven Valdez5440fe02016-07-18 12:40:30 -04001263 SendServerHelloVersion uint16
1264
Steven Valdez038da9b2017-07-10 12:57:25 -04001265 // SendServerSupportedExtensionVersion, if non-zero, causes the server to send
1266 // the specified value in supported_versions extension in the ServerHello.
1267 SendServerSupportedExtensionVersion uint16
1268
Steven Valdez5440fe02016-07-18 12:40:30 -04001269 // SkipHelloRetryRequest, if true, causes the TLS 1.3 server to not send
1270 // HelloRetryRequest.
1271 SkipHelloRetryRequest bool
David Benjamin12d2c482016-07-24 10:56:51 -04001272
1273 // PackHelloRequestWithFinished, if true, causes the TLS server to send
1274 // HelloRequest in the same record as Finished.
1275 PackHelloRequestWithFinished bool
David Benjamin02edcd02016-07-27 17:40:37 -04001276
David Benjamine73c7f42016-08-17 00:29:33 -04001277 // ExpectMissingKeyShare, if true, causes the TLS server to fail the
1278 // connection if the selected curve appears in the client's initial
1279 // ClientHello. That is, it requires that a HelloRetryRequest be sent.
1280 ExpectMissingKeyShare bool
1281
David Benjamin02edcd02016-07-27 17:40:37 -04001282 // SendExtraFinished, if true, causes an extra Finished message to be
1283 // sent.
1284 SendExtraFinished bool
David Benjamin8a8349b2016-08-18 02:32:23 -04001285
1286 // SendRequestContext, if not empty, is the request context to send in
1287 // a TLS 1.3 CertificateRequest.
1288 SendRequestContext []byte
David Benjaminabe94e32016-09-04 14:18:58 -04001289
1290 // SendSNIWarningAlert, if true, causes the server to send an
1291 // unrecognized_name alert before the ServerHello.
1292 SendSNIWarningAlert bool
David Benjaminc241d792016-09-09 10:34:20 -04001293
1294 // SendCompressionMethods, if not nil, is the compression method list to
1295 // send in the ClientHello.
1296 SendCompressionMethods []byte
David Benjamin78679342016-09-16 19:42:05 -04001297
David Benjamin413e79e2017-07-01 10:11:53 -04001298 // SendCompressionMethod is the compression method to send in the
1299 // ServerHello.
1300 SendCompressionMethod byte
1301
David Benjamin78679342016-09-16 19:42:05 -04001302 // AlwaysSendPreSharedKeyIdentityHint, if true, causes the server to
1303 // always send a ServerKeyExchange for PSK ciphers, even if the identity
1304 // hint is empty.
1305 AlwaysSendPreSharedKeyIdentityHint bool
David Benjamin7e1f9842016-09-20 19:24:40 -04001306
1307 // TrailingKeyShareData, if true, causes the client key share list to
1308 // include a trailing byte.
1309 TrailingKeyShareData bool
David Benjamin196df5b2016-09-21 16:23:27 -04001310
1311 // InvalidChannelIDSignature, if true, causes the client to generate an
1312 // invalid Channel ID signature.
1313 InvalidChannelIDSignature bool
David Benjamin65ac9972016-09-02 21:35:25 -04001314
David Benjamin1a5e8ec2016-10-07 15:19:18 -04001315 // ExpectGREASE, if true, causes messages without GREASE values to be
1316 // rejected. See draft-davidben-tls-grease-01.
David Benjamin65ac9972016-09-02 21:35:25 -04001317 ExpectGREASE bool
Steven Valdeza833c352016-11-01 13:39:36 -04001318
1319 // SendShortPSKBinder, if true, causes the client to send a PSK binder
1320 // that is one byte shorter than it should be.
1321 SendShortPSKBinder bool
1322
1323 // SendInvalidPSKBinder, if true, causes the client to send an invalid
1324 // PSK binder.
1325 SendInvalidPSKBinder bool
1326
1327 // SendNoPSKBinder, if true, causes the client to send no PSK binders.
1328 SendNoPSKBinder bool
1329
David Benjaminaedf3032016-12-01 16:47:56 -05001330 // SendExtraPSKBinder, if true, causes the client to send an extra PSK
1331 // binder.
1332 SendExtraPSKBinder bool
1333
Steven Valdeza833c352016-11-01 13:39:36 -04001334 // PSKBinderFirst, if true, causes the client to send the PSK Binder
1335 // extension as the first extension instead of the last extension.
1336 PSKBinderFirst bool
David Benjamin53210cb2016-11-16 09:01:48 +09001337
1338 // NoOCSPStapling, if true, causes the client to not request OCSP
1339 // stapling.
1340 NoOCSPStapling bool
1341
1342 // NoSignedCertificateTimestamps, if true, causes the client to not
1343 // request signed certificate timestamps.
1344 NoSignedCertificateTimestamps bool
David Benjamin6f600d62016-12-21 16:06:54 -05001345
David Benjamina81967b2016-12-22 09:16:57 -05001346 // SendSupportedPointFormats, if not nil, is the list of supported point
1347 // formats to send in ClientHello or ServerHello. If set to a non-nil
1348 // empty slice, no extension will be sent.
1349 SendSupportedPointFormats []byte
David Benjamine3fbb362017-01-06 16:19:28 -05001350
1351 // MaxReceivePlaintext, if non-zero, is the maximum plaintext record
1352 // length accepted from the peer.
1353 MaxReceivePlaintext int
David Benjamin17b30832017-01-28 14:00:32 -05001354
1355 // SendTicketLifetime, if non-zero, is the ticket lifetime to send in
1356 // NewSessionTicket messages.
1357 SendTicketLifetime time.Duration
David Benjamin023d4192017-02-06 13:49:07 -05001358
1359 // SendServerNameAck, if true, causes the server to acknowledge the SNI
1360 // extension.
1361 SendServerNameAck bool
Adam Langley2ff79332017-02-28 13:45:39 -08001362
1363 // ExpectCertificateReqNames, if not nil, contains the list of X.509
1364 // names that must be sent in a CertificateRequest from the server.
1365 ExpectCertificateReqNames [][]byte
David Benjamina58baaf2017-02-28 20:54:28 -05001366
1367 // RenegotiationCertificate, if not nil, is the certificate to use on
1368 // renegotiation handshakes.
1369 RenegotiationCertificate *Certificate
David Benjamin69522112017-03-28 15:38:29 -05001370
1371 // UseLegacySigningAlgorithm, if non-zero, is the signature algorithm
1372 // to use when signing in TLS 1.1 and earlier where algorithms are not
1373 // negotiated.
1374 UseLegacySigningAlgorithm signatureAlgorithm
David Benjaminebacdee2017-04-08 11:00:45 -04001375
1376 // SendServerHelloAsHelloRetryRequest, if true, causes the server to
1377 // send ServerHello messages with a HelloRetryRequest type field.
1378 SendServerHelloAsHelloRetryRequest bool
David Benjaminbbba9392017-04-06 12:54:12 -04001379
1380 // RejectUnsolicitedKeyUpdate, if true, causes all unsolicited
1381 // KeyUpdates from the peer to be rejected.
1382 RejectUnsolicitedKeyUpdate bool
Adam Langley95c29f32014-06-20 12:00:00 -07001383}
1384
1385func (c *Config) serverInit() {
1386 if c.SessionTicketsDisabled {
1387 return
1388 }
1389
1390 // If the key has already been set then we have nothing to do.
1391 for _, b := range c.SessionTicketKey {
1392 if b != 0 {
1393 return
1394 }
1395 }
1396
1397 if _, err := io.ReadFull(c.rand(), c.SessionTicketKey[:]); err != nil {
1398 c.SessionTicketsDisabled = true
1399 }
1400}
1401
1402func (c *Config) rand() io.Reader {
1403 r := c.Rand
1404 if r == nil {
1405 return rand.Reader
1406 }
1407 return r
1408}
1409
1410func (c *Config) time() time.Time {
1411 t := c.Time
1412 if t == nil {
1413 t = time.Now
1414 }
1415 return t()
1416}
1417
1418func (c *Config) cipherSuites() []uint16 {
1419 s := c.CipherSuites
1420 if s == nil {
1421 s = defaultCipherSuites()
1422 }
1423 return s
1424}
1425
David Benjamincecee272016-06-30 13:33:47 -04001426func (c *Config) minVersion(isDTLS bool) uint16 {
1427 ret := uint16(minVersion)
1428 if c != nil && c.MinVersion != 0 {
1429 ret = c.MinVersion
Adam Langley95c29f32014-06-20 12:00:00 -07001430 }
David Benjamincecee272016-06-30 13:33:47 -04001431 if isDTLS {
1432 // The lowest version of DTLS is 1.0. There is no DSSL 3.0.
1433 if ret < VersionTLS10 {
1434 return VersionTLS10
1435 }
1436 // There is no such thing as DTLS 1.1.
1437 if ret == VersionTLS11 {
1438 return VersionTLS12
1439 }
1440 }
1441 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001442}
1443
David Benjamincecee272016-06-30 13:33:47 -04001444func (c *Config) maxVersion(isDTLS bool) uint16 {
1445 ret := uint16(maxVersion)
1446 if c != nil && c.MaxVersion != 0 {
1447 ret = c.MaxVersion
Adam Langley95c29f32014-06-20 12:00:00 -07001448 }
David Benjamincecee272016-06-30 13:33:47 -04001449 if isDTLS {
1450 // We only implement up to DTLS 1.2.
1451 if ret > VersionTLS12 {
1452 return VersionTLS12
1453 }
1454 // There is no such thing as DTLS 1.1.
1455 if ret == VersionTLS11 {
1456 return VersionTLS10
1457 }
1458 }
1459 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001460}
1461
David Benjamincba2b622015-12-18 22:13:41 -05001462var defaultCurvePreferences = []CurveID{CurveX25519, CurveP256, CurveP384, CurveP521}
Adam Langley95c29f32014-06-20 12:00:00 -07001463
1464func (c *Config) curvePreferences() []CurveID {
1465 if c == nil || len(c.CurvePreferences) == 0 {
1466 return defaultCurvePreferences
1467 }
1468 return c.CurvePreferences
1469}
1470
Nick Harperdcfbc672016-07-16 17:47:31 +02001471func (c *Config) defaultCurves() map[CurveID]bool {
1472 defaultCurves := make(map[CurveID]bool)
1473 curves := c.DefaultCurves
1474 if c == nil || c.DefaultCurves == nil {
1475 curves = c.curvePreferences()
1476 }
1477 for _, curveID := range curves {
1478 defaultCurves[curveID] = true
1479 }
1480 return defaultCurves
1481}
1482
Steven Valdezc94998a2017-06-20 10:55:02 -04001483// isSupportedVersion checks if the specified wire version is acceptable. If so,
1484// it returns true and the corresponding protocol version. Otherwise, it returns
1485// false.
1486func (c *Config) isSupportedVersion(wireVers uint16, isDTLS bool) (uint16, bool) {
Steven Valdez520e1222017-06-13 12:45:25 -04001487 if (c.TLS13Variant != TLS13Experiment && wireVers == tls13ExperimentVersion) ||
1488 (c.TLS13Variant != TLS13Default && wireVers == tls13DraftVersion) {
1489 return 0, false
1490 }
1491
Steven Valdezc94998a2017-06-20 10:55:02 -04001492 vers, ok := wireToVersion(wireVers, isDTLS)
1493 if !ok || c.minVersion(isDTLS) > vers || vers > c.maxVersion(isDTLS) {
1494 return 0, false
1495 }
1496 return vers, true
1497}
1498
1499func (c *Config) supportedVersions(isDTLS bool) []uint16 {
1500 versions := allTLSWireVersions
1501 if isDTLS {
1502 versions = allDTLSWireVersions
1503 }
1504 var ret []uint16
1505 for _, vers := range versions {
1506 if _, ok := c.isSupportedVersion(vers, isDTLS); ok {
1507 ret = append(ret, vers)
1508 }
1509 }
1510 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001511}
1512
1513// getCertificateForName returns the best certificate for the given name,
1514// defaulting to the first element of c.Certificates if there are no good
1515// options.
1516func (c *Config) getCertificateForName(name string) *Certificate {
1517 if len(c.Certificates) == 1 || c.NameToCertificate == nil {
1518 // There's only one choice, so no point doing any work.
1519 return &c.Certificates[0]
1520 }
1521
1522 name = strings.ToLower(name)
1523 for len(name) > 0 && name[len(name)-1] == '.' {
1524 name = name[:len(name)-1]
1525 }
1526
1527 if cert, ok := c.NameToCertificate[name]; ok {
1528 return cert
1529 }
1530
1531 // try replacing labels in the name with wildcards until we get a
1532 // match.
1533 labels := strings.Split(name, ".")
1534 for i := range labels {
1535 labels[i] = "*"
1536 candidate := strings.Join(labels, ".")
1537 if cert, ok := c.NameToCertificate[candidate]; ok {
1538 return cert
1539 }
1540 }
1541
1542 // If nothing matches, return the first certificate.
1543 return &c.Certificates[0]
1544}
1545
David Benjamin7a41d372016-07-09 11:21:54 -07001546func (c *Config) signSignatureAlgorithms() []signatureAlgorithm {
1547 if c != nil && c.SignSignatureAlgorithms != nil {
1548 return c.SignSignatureAlgorithms
David Benjamin000800a2014-11-14 01:43:59 -05001549 }
David Benjamin7a41d372016-07-09 11:21:54 -07001550 return supportedSignatureAlgorithms
David Benjamin000800a2014-11-14 01:43:59 -05001551}
1552
David Benjamin7a41d372016-07-09 11:21:54 -07001553func (c *Config) verifySignatureAlgorithms() []signatureAlgorithm {
1554 if c != nil && c.VerifySignatureAlgorithms != nil {
1555 return c.VerifySignatureAlgorithms
David Benjamin000800a2014-11-14 01:43:59 -05001556 }
David Benjamin7a41d372016-07-09 11:21:54 -07001557 return supportedSignatureAlgorithms
David Benjamin000800a2014-11-14 01:43:59 -05001558}
1559
Adam Langley95c29f32014-06-20 12:00:00 -07001560// BuildNameToCertificate parses c.Certificates and builds c.NameToCertificate
1561// from the CommonName and SubjectAlternateName fields of each of the leaf
1562// certificates.
1563func (c *Config) BuildNameToCertificate() {
1564 c.NameToCertificate = make(map[string]*Certificate)
1565 for i := range c.Certificates {
1566 cert := &c.Certificates[i]
1567 x509Cert, err := x509.ParseCertificate(cert.Certificate[0])
1568 if err != nil {
1569 continue
1570 }
1571 if len(x509Cert.Subject.CommonName) > 0 {
1572 c.NameToCertificate[x509Cert.Subject.CommonName] = cert
1573 }
1574 for _, san := range x509Cert.DNSNames {
1575 c.NameToCertificate[san] = cert
1576 }
1577 }
1578}
1579
1580// A Certificate is a chain of one or more certificates, leaf first.
1581type Certificate struct {
1582 Certificate [][]byte
1583 PrivateKey crypto.PrivateKey // supported types: *rsa.PrivateKey, *ecdsa.PrivateKey
1584 // OCSPStaple contains an optional OCSP response which will be served
1585 // to clients that request it.
1586 OCSPStaple []byte
David Benjamin61f95272014-11-25 01:55:35 -05001587 // SignedCertificateTimestampList contains an optional encoded
1588 // SignedCertificateTimestampList structure which will be
1589 // served to clients that request it.
1590 SignedCertificateTimestampList []byte
Adam Langley95c29f32014-06-20 12:00:00 -07001591 // Leaf is the parsed form of the leaf certificate, which may be
1592 // initialized using x509.ParseCertificate to reduce per-handshake
1593 // processing for TLS clients doing client authentication. If nil, the
1594 // leaf certificate will be parsed as needed.
1595 Leaf *x509.Certificate
1596}
1597
1598// A TLS record.
1599type record struct {
1600 contentType recordType
1601 major, minor uint8
1602 payload []byte
1603}
1604
1605type handshakeMessage interface {
1606 marshal() []byte
1607 unmarshal([]byte) bool
1608}
1609
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001610// lruSessionCache is a client or server session cache implementation
1611// that uses an LRU caching strategy.
Adam Langley95c29f32014-06-20 12:00:00 -07001612type lruSessionCache struct {
1613 sync.Mutex
1614
1615 m map[string]*list.Element
1616 q *list.List
1617 capacity int
1618}
1619
1620type lruSessionCacheEntry struct {
1621 sessionKey string
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001622 state interface{}
Adam Langley95c29f32014-06-20 12:00:00 -07001623}
1624
1625// Put adds the provided (sessionKey, cs) pair to the cache.
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001626func (c *lruSessionCache) Put(sessionKey string, cs interface{}) {
Adam Langley95c29f32014-06-20 12:00:00 -07001627 c.Lock()
1628 defer c.Unlock()
1629
1630 if elem, ok := c.m[sessionKey]; ok {
1631 entry := elem.Value.(*lruSessionCacheEntry)
1632 entry.state = cs
1633 c.q.MoveToFront(elem)
1634 return
1635 }
1636
1637 if c.q.Len() < c.capacity {
1638 entry := &lruSessionCacheEntry{sessionKey, cs}
1639 c.m[sessionKey] = c.q.PushFront(entry)
1640 return
1641 }
1642
1643 elem := c.q.Back()
1644 entry := elem.Value.(*lruSessionCacheEntry)
1645 delete(c.m, entry.sessionKey)
1646 entry.sessionKey = sessionKey
1647 entry.state = cs
1648 c.q.MoveToFront(elem)
1649 c.m[sessionKey] = elem
1650}
1651
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001652// Get returns the value associated with a given key. It returns (nil,
1653// false) if no value is found.
1654func (c *lruSessionCache) Get(sessionKey string) (interface{}, bool) {
Adam Langley95c29f32014-06-20 12:00:00 -07001655 c.Lock()
1656 defer c.Unlock()
1657
1658 if elem, ok := c.m[sessionKey]; ok {
1659 c.q.MoveToFront(elem)
1660 return elem.Value.(*lruSessionCacheEntry).state, true
1661 }
1662 return nil, false
1663}
1664
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001665// lruClientSessionCache is a ClientSessionCache implementation that
1666// uses an LRU caching strategy.
1667type lruClientSessionCache struct {
1668 lruSessionCache
1669}
1670
1671func (c *lruClientSessionCache) Put(sessionKey string, cs *ClientSessionState) {
1672 c.lruSessionCache.Put(sessionKey, cs)
1673}
1674
1675func (c *lruClientSessionCache) Get(sessionKey string) (*ClientSessionState, bool) {
1676 cs, ok := c.lruSessionCache.Get(sessionKey)
1677 if !ok {
1678 return nil, false
1679 }
1680 return cs.(*ClientSessionState), true
1681}
1682
1683// lruServerSessionCache is a ServerSessionCache implementation that
1684// uses an LRU caching strategy.
1685type lruServerSessionCache struct {
1686 lruSessionCache
1687}
1688
1689func (c *lruServerSessionCache) Put(sessionId string, session *sessionState) {
1690 c.lruSessionCache.Put(sessionId, session)
1691}
1692
1693func (c *lruServerSessionCache) Get(sessionId string) (*sessionState, bool) {
1694 cs, ok := c.lruSessionCache.Get(sessionId)
1695 if !ok {
1696 return nil, false
1697 }
1698 return cs.(*sessionState), true
1699}
1700
1701// NewLRUClientSessionCache returns a ClientSessionCache with the given
1702// capacity that uses an LRU strategy. If capacity is < 1, a default capacity
1703// is used instead.
1704func NewLRUClientSessionCache(capacity int) ClientSessionCache {
1705 const defaultSessionCacheCapacity = 64
1706
1707 if capacity < 1 {
1708 capacity = defaultSessionCacheCapacity
1709 }
1710 return &lruClientSessionCache{
1711 lruSessionCache{
1712 m: make(map[string]*list.Element),
1713 q: list.New(),
1714 capacity: capacity,
1715 },
1716 }
1717}
1718
1719// NewLRUServerSessionCache returns a ServerSessionCache with the given
1720// capacity that uses an LRU strategy. If capacity is < 1, a default capacity
1721// is used instead.
1722func NewLRUServerSessionCache(capacity int) ServerSessionCache {
1723 const defaultSessionCacheCapacity = 64
1724
1725 if capacity < 1 {
1726 capacity = defaultSessionCacheCapacity
1727 }
1728 return &lruServerSessionCache{
1729 lruSessionCache{
1730 m: make(map[string]*list.Element),
1731 q: list.New(),
1732 capacity: capacity,
1733 },
1734 }
1735}
1736
Adam Langley95c29f32014-06-20 12:00:00 -07001737// TODO(jsing): Make these available to both crypto/x509 and crypto/tls.
1738type dsaSignature struct {
1739 R, S *big.Int
1740}
1741
1742type ecdsaSignature dsaSignature
1743
1744var emptyConfig Config
1745
1746func defaultConfig() *Config {
1747 return &emptyConfig
1748}
1749
1750var (
1751 once sync.Once
1752 varDefaultCipherSuites []uint16
1753)
1754
1755func defaultCipherSuites() []uint16 {
1756 once.Do(initDefaultCipherSuites)
1757 return varDefaultCipherSuites
1758}
1759
1760func initDefaultCipherSuites() {
David Benjamin48cae082014-10-27 01:06:24 -04001761 for _, suite := range cipherSuites {
1762 if suite.flags&suitePSK == 0 {
1763 varDefaultCipherSuites = append(varDefaultCipherSuites, suite.id)
1764 }
Adam Langley95c29f32014-06-20 12:00:00 -07001765 }
1766}
1767
1768func unexpectedMessageError(wanted, got interface{}) error {
1769 return fmt.Errorf("tls: received unexpected handshake message of type %T when waiting for %T", got, wanted)
1770}
David Benjamin000800a2014-11-14 01:43:59 -05001771
Nick Harper60edffd2016-06-21 15:19:24 -07001772func isSupportedSignatureAlgorithm(sigAlg signatureAlgorithm, sigAlgs []signatureAlgorithm) bool {
1773 for _, s := range sigAlgs {
1774 if s == sigAlg {
David Benjamin000800a2014-11-14 01:43:59 -05001775 return true
1776 }
1777 }
1778 return false
1779}
Nick Harper85f20c22016-07-04 10:11:59 -07001780
1781var (
David Benjamina128a552016-10-13 14:26:33 -04001782 // See draft-ietf-tls-tls13-16, section 6.3.1.2.
Nick Harper85f20c22016-07-04 10:11:59 -07001783 downgradeTLS13 = []byte{0x44, 0x4f, 0x57, 0x4e, 0x47, 0x52, 0x44, 0x01}
1784 downgradeTLS12 = []byte{0x44, 0x4f, 0x57, 0x4e, 0x47, 0x52, 0x44, 0x00}
1785)
Steven Valdezc94998a2017-06-20 10:55:02 -04001786
1787func containsGREASE(values []uint16) bool {
1788 for _, v := range values {
1789 if isGREASEValue(v) {
1790 return true
1791 }
1792 }
1793 return false
1794}