Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [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 | |
Adam Langley | dc7e9c4 | 2015-09-29 15:21:04 -0700 | [diff] [blame] | 5 | package runner |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6 | |
| 7 | import ( |
| 8 | "container/list" |
| 9 | "crypto" |
David Benjamin | d30a990 | 2014-08-24 01:44:23 -0400 | [diff] [blame] | 10 | "crypto/ecdsa" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 11 | "crypto/rand" |
| 12 | "crypto/x509" |
| 13 | "fmt" |
| 14 | "io" |
| 15 | "math/big" |
| 16 | "strings" |
| 17 | "sync" |
| 18 | "time" |
| 19 | ) |
| 20 | |
| 21 | const ( |
| 22 | VersionSSL30 = 0x0300 |
| 23 | VersionTLS10 = 0x0301 |
| 24 | VersionTLS11 = 0x0302 |
| 25 | VersionTLS12 = 0x0303 |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame^] | 26 | VersionTLS13 = 0x0304 |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | const ( |
David Benjamin | 83c0bc9 | 2014-08-04 01:23:53 -0400 | [diff] [blame] | 30 | maxPlaintext = 16384 // maximum plaintext payload length |
| 31 | maxCiphertext = 16384 + 2048 // maximum ciphertext payload length |
| 32 | tlsRecordHeaderLen = 5 // record header length |
| 33 | dtlsRecordHeaderLen = 13 |
| 34 | maxHandshake = 65536 // maximum handshake we support (protocol max is 16 MB) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 35 | |
| 36 | minVersion = VersionSSL30 |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame^] | 37 | maxVersion = VersionTLS13 |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 38 | ) |
| 39 | |
| 40 | // TLS record types. |
| 41 | type recordType uint8 |
| 42 | |
| 43 | const ( |
| 44 | recordTypeChangeCipherSpec recordType = 20 |
| 45 | recordTypeAlert recordType = 21 |
| 46 | recordTypeHandshake recordType = 22 |
| 47 | recordTypeApplicationData recordType = 23 |
| 48 | ) |
| 49 | |
| 50 | // TLS handshake message types. |
| 51 | const ( |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 52 | typeHelloRequest uint8 = 0 |
David Benjamin | d30a990 | 2014-08-24 01:44:23 -0400 | [diff] [blame] | 53 | typeClientHello uint8 = 1 |
| 54 | typeServerHello uint8 = 2 |
| 55 | typeHelloVerifyRequest uint8 = 3 |
| 56 | typeNewSessionTicket uint8 = 4 |
| 57 | typeCertificate uint8 = 11 |
| 58 | typeServerKeyExchange uint8 = 12 |
| 59 | typeCertificateRequest uint8 = 13 |
| 60 | typeServerHelloDone uint8 = 14 |
| 61 | typeCertificateVerify uint8 = 15 |
| 62 | typeClientKeyExchange uint8 = 16 |
| 63 | typeFinished uint8 = 20 |
| 64 | typeCertificateStatus uint8 = 22 |
| 65 | typeNextProtocol uint8 = 67 // Not IANA assigned |
| 66 | typeEncryptedExtensions uint8 = 203 // Not IANA assigned |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 67 | ) |
| 68 | |
| 69 | // TLS compression types. |
| 70 | const ( |
| 71 | compressionNone uint8 = 0 |
| 72 | ) |
| 73 | |
| 74 | // TLS extension numbers |
| 75 | const ( |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 76 | extensionServerName uint16 = 0 |
| 77 | extensionStatusRequest uint16 = 5 |
| 78 | extensionSupportedCurves uint16 = 10 |
| 79 | extensionSupportedPoints uint16 = 11 |
| 80 | extensionSignatureAlgorithms uint16 = 13 |
| 81 | extensionUseSRTP uint16 = 14 |
| 82 | extensionALPN uint16 = 16 |
| 83 | extensionSignedCertificateTimestamp uint16 = 18 |
| 84 | extensionExtendedMasterSecret uint16 = 23 |
| 85 | extensionSessionTicket uint16 = 35 |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 86 | extensionCustom uint16 = 1234 // not IANA assigned |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 87 | extensionNextProtoNeg uint16 = 13172 // not IANA assigned |
| 88 | extensionRenegotiationInfo uint16 = 0xff01 |
| 89 | extensionChannelID uint16 = 30032 // not IANA assigned |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 90 | ) |
| 91 | |
| 92 | // TLS signaling cipher suite values |
| 93 | const ( |
| 94 | scsvRenegotiation uint16 = 0x00ff |
| 95 | ) |
| 96 | |
| 97 | // CurveID is the type of a TLS identifier for an elliptic curve. See |
| 98 | // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-8 |
| 99 | type CurveID uint16 |
| 100 | |
| 101 | const ( |
David Benjamin | cba2b62 | 2015-12-18 22:13:41 -0500 | [diff] [blame] | 102 | CurveP224 CurveID = 21 |
| 103 | CurveP256 CurveID = 23 |
| 104 | CurveP384 CurveID = 24 |
| 105 | CurveP521 CurveID = 25 |
| 106 | CurveX25519 CurveID = 29 |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 107 | ) |
| 108 | |
| 109 | // TLS Elliptic Curve Point Formats |
| 110 | // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-9 |
| 111 | const ( |
| 112 | pointFormatUncompressed uint8 = 0 |
| 113 | ) |
| 114 | |
| 115 | // TLS CertificateStatusType (RFC 3546) |
| 116 | const ( |
| 117 | statusTypeOCSP uint8 = 1 |
| 118 | ) |
| 119 | |
| 120 | // Certificate types (for certificateRequestMsg) |
| 121 | const ( |
David Benjamin | 7b03051 | 2014-07-08 17:30:11 -0400 | [diff] [blame] | 122 | CertTypeRSASign = 1 // A certificate containing an RSA key |
| 123 | CertTypeDSSSign = 2 // A certificate containing a DSA key |
| 124 | CertTypeRSAFixedDH = 3 // A certificate containing a static DH key |
| 125 | CertTypeDSSFixedDH = 4 // A certificate containing a static DH key |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 126 | |
| 127 | // See RFC4492 sections 3 and 5.5. |
David Benjamin | 7b03051 | 2014-07-08 17:30:11 -0400 | [diff] [blame] | 128 | CertTypeECDSASign = 64 // A certificate containing an ECDSA-capable public key, signed with ECDSA. |
| 129 | CertTypeRSAFixedECDH = 65 // A certificate containing an ECDH-capable public key, signed with RSA. |
| 130 | CertTypeECDSAFixedECDH = 66 // A certificate containing an ECDH-capable public key, signed with ECDSA. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 131 | |
| 132 | // Rest of these are reserved by the TLS spec |
| 133 | ) |
| 134 | |
| 135 | // Hash functions for TLS 1.2 (See RFC 5246, section A.4.1) |
| 136 | const ( |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 137 | hashMD5 uint8 = 1 |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 138 | hashSHA1 uint8 = 2 |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 139 | hashSHA224 uint8 = 3 |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 140 | hashSHA256 uint8 = 4 |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 141 | hashSHA384 uint8 = 5 |
| 142 | hashSHA512 uint8 = 6 |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 143 | ) |
| 144 | |
| 145 | // Signature algorithms for TLS 1.2 (See RFC 5246, section A.4.1) |
| 146 | const ( |
| 147 | signatureRSA uint8 = 1 |
| 148 | signatureECDSA uint8 = 3 |
| 149 | ) |
| 150 | |
| 151 | // signatureAndHash mirrors the TLS 1.2, SignatureAndHashAlgorithm struct. See |
| 152 | // RFC 5246, section A.4.1. |
| 153 | type signatureAndHash struct { |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 154 | signature, hash uint8 |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | // supportedSKXSignatureAlgorithms contains the signature and hash algorithms |
| 158 | // that the code advertises as supported in a TLS 1.2 ClientHello. |
| 159 | var supportedSKXSignatureAlgorithms = []signatureAndHash{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 160 | {signatureRSA, hashSHA256}, |
| 161 | {signatureECDSA, hashSHA256}, |
| 162 | {signatureRSA, hashSHA1}, |
| 163 | {signatureECDSA, hashSHA1}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | // supportedClientCertSignatureAlgorithms contains the signature and hash |
| 167 | // algorithms that the code advertises as supported in a TLS 1.2 |
| 168 | // CertificateRequest. |
| 169 | var supportedClientCertSignatureAlgorithms = []signatureAndHash{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 170 | {signatureRSA, hashSHA256}, |
| 171 | {signatureECDSA, hashSHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 172 | } |
| 173 | |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 174 | // SRTP protection profiles (See RFC 5764, section 4.1.2) |
| 175 | const ( |
| 176 | SRTP_AES128_CM_HMAC_SHA1_80 uint16 = 0x0001 |
| 177 | SRTP_AES128_CM_HMAC_SHA1_32 = 0x0002 |
| 178 | ) |
| 179 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 180 | // ConnectionState records basic TLS details about the connection. |
| 181 | type ConnectionState struct { |
| 182 | Version uint16 // TLS version used by the connection (e.g. VersionTLS12) |
| 183 | HandshakeComplete bool // TLS handshake is complete |
| 184 | DidResume bool // connection resumes a previous TLS connection |
| 185 | CipherSuite uint16 // cipher suite in use (TLS_RSA_WITH_RC4_128_SHA, ...) |
| 186 | NegotiatedProtocol string // negotiated next protocol (from Config.NextProtos) |
| 187 | NegotiatedProtocolIsMutual bool // negotiated protocol was advertised by server |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 188 | NegotiatedProtocolFromALPN bool // protocol negotiated with ALPN |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 189 | ServerName string // server name requested by client, if any (server side only) |
| 190 | PeerCertificates []*x509.Certificate // certificate chain presented by remote peer |
| 191 | VerifiedChains [][]*x509.Certificate // verified chains built from PeerCertificates |
David Benjamin | d30a990 | 2014-08-24 01:44:23 -0400 | [diff] [blame] | 192 | ChannelID *ecdsa.PublicKey // the channel ID for this connection |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 193 | SRTPProtectionProfile uint16 // the negotiated DTLS-SRTP protection profile |
David Benjamin | c057762 | 2015-09-12 18:28:38 -0400 | [diff] [blame] | 194 | TLSUnique []byte // the tls-unique channel binding |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 195 | SCTList []byte // signed certificate timestamp list |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 196 | ClientCertSignatureHash uint8 // TLS id of the hash used by the client to sign the handshake |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | // ClientAuthType declares the policy the server will follow for |
| 200 | // TLS Client Authentication. |
| 201 | type ClientAuthType int |
| 202 | |
| 203 | const ( |
| 204 | NoClientCert ClientAuthType = iota |
| 205 | RequestClientCert |
| 206 | RequireAnyClientCert |
| 207 | VerifyClientCertIfGiven |
| 208 | RequireAndVerifyClientCert |
| 209 | ) |
| 210 | |
| 211 | // ClientSessionState contains the state needed by clients to resume TLS |
| 212 | // sessions. |
| 213 | type ClientSessionState struct { |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 214 | sessionId []uint8 // Session ID supplied by the server. nil if the session has a ticket. |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 215 | sessionTicket []uint8 // Encrypted ticket used for session resumption with server |
| 216 | vers uint16 // SSL/TLS version negotiated for the session |
| 217 | cipherSuite uint16 // Ciphersuite negotiated for the session |
| 218 | masterSecret []byte // MasterSecret generated by client on a full handshake |
| 219 | handshakeHash []byte // Handshake hash for Channel ID purposes. |
| 220 | serverCertificates []*x509.Certificate // Certificate chain presented by the server |
| 221 | extendedMasterSecret bool // Whether an extended master secret was used to generate the session |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 222 | sctList []byte |
| 223 | ocspResponse []byte |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | // ClientSessionCache is a cache of ClientSessionState objects that can be used |
| 227 | // by a client to resume a TLS session with a given server. ClientSessionCache |
| 228 | // implementations should expect to be called concurrently from different |
| 229 | // goroutines. |
| 230 | type ClientSessionCache interface { |
| 231 | // Get searches for a ClientSessionState associated with the given key. |
| 232 | // On return, ok is true if one was found. |
| 233 | Get(sessionKey string) (session *ClientSessionState, ok bool) |
| 234 | |
| 235 | // Put adds the ClientSessionState to the cache with the given key. |
| 236 | Put(sessionKey string, cs *ClientSessionState) |
| 237 | } |
| 238 | |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 239 | // ServerSessionCache is a cache of sessionState objects that can be used by a |
| 240 | // client to resume a TLS session with a given server. ServerSessionCache |
| 241 | // implementations should expect to be called concurrently from different |
| 242 | // goroutines. |
| 243 | type ServerSessionCache interface { |
| 244 | // Get searches for a sessionState associated with the given session |
| 245 | // ID. On return, ok is true if one was found. |
| 246 | Get(sessionId string) (session *sessionState, ok bool) |
| 247 | |
| 248 | // Put adds the sessionState to the cache with the given session ID. |
| 249 | Put(sessionId string, session *sessionState) |
| 250 | } |
| 251 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 252 | // A Config structure is used to configure a TLS client or server. |
| 253 | // After one has been passed to a TLS function it must not be |
| 254 | // modified. A Config may be reused; the tls package will also not |
| 255 | // modify it. |
| 256 | type Config struct { |
| 257 | // Rand provides the source of entropy for nonces and RSA blinding. |
| 258 | // If Rand is nil, TLS uses the cryptographic random reader in package |
| 259 | // crypto/rand. |
| 260 | // The Reader must be safe for use by multiple goroutines. |
| 261 | Rand io.Reader |
| 262 | |
| 263 | // Time returns the current time as the number of seconds since the epoch. |
| 264 | // If Time is nil, TLS uses time.Now. |
| 265 | Time func() time.Time |
| 266 | |
| 267 | // Certificates contains one or more certificate chains |
| 268 | // to present to the other side of the connection. |
| 269 | // Server configurations must include at least one certificate. |
| 270 | Certificates []Certificate |
| 271 | |
| 272 | // NameToCertificate maps from a certificate name to an element of |
| 273 | // Certificates. Note that a certificate name can be of the form |
| 274 | // '*.example.com' and so doesn't have to be a domain name as such. |
| 275 | // See Config.BuildNameToCertificate |
| 276 | // The nil value causes the first element of Certificates to be used |
| 277 | // for all connections. |
| 278 | NameToCertificate map[string]*Certificate |
| 279 | |
| 280 | // RootCAs defines the set of root certificate authorities |
| 281 | // that clients use when verifying server certificates. |
| 282 | // If RootCAs is nil, TLS uses the host's root CA set. |
| 283 | RootCAs *x509.CertPool |
| 284 | |
| 285 | // NextProtos is a list of supported, application level protocols. |
| 286 | NextProtos []string |
| 287 | |
| 288 | // ServerName is used to verify the hostname on the returned |
| 289 | // certificates unless InsecureSkipVerify is given. It is also included |
| 290 | // in the client's handshake to support virtual hosting. |
| 291 | ServerName string |
| 292 | |
| 293 | // ClientAuth determines the server's policy for |
| 294 | // TLS Client Authentication. The default is NoClientCert. |
| 295 | ClientAuth ClientAuthType |
| 296 | |
| 297 | // ClientCAs defines the set of root certificate authorities |
| 298 | // that servers use if required to verify a client certificate |
| 299 | // by the policy in ClientAuth. |
| 300 | ClientCAs *x509.CertPool |
| 301 | |
David Benjamin | 7b03051 | 2014-07-08 17:30:11 -0400 | [diff] [blame] | 302 | // ClientCertificateTypes defines the set of allowed client certificate |
| 303 | // types. The default is CertTypeRSASign and CertTypeECDSASign. |
| 304 | ClientCertificateTypes []byte |
| 305 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 306 | // InsecureSkipVerify controls whether a client verifies the |
| 307 | // server's certificate chain and host name. |
| 308 | // If InsecureSkipVerify is true, TLS accepts any certificate |
| 309 | // presented by the server and any host name in that certificate. |
| 310 | // In this mode, TLS is susceptible to man-in-the-middle attacks. |
| 311 | // This should be used only for testing. |
| 312 | InsecureSkipVerify bool |
| 313 | |
| 314 | // CipherSuites is a list of supported cipher suites. If CipherSuites |
| 315 | // is nil, TLS uses a list of suites supported by the implementation. |
| 316 | CipherSuites []uint16 |
| 317 | |
| 318 | // PreferServerCipherSuites controls whether the server selects the |
| 319 | // client's most preferred ciphersuite, or the server's most preferred |
| 320 | // ciphersuite. If true then the server's preference, as expressed in |
| 321 | // the order of elements in CipherSuites, is used. |
| 322 | PreferServerCipherSuites bool |
| 323 | |
| 324 | // SessionTicketsDisabled may be set to true to disable session ticket |
| 325 | // (resumption) support. |
| 326 | SessionTicketsDisabled bool |
| 327 | |
| 328 | // SessionTicketKey is used by TLS servers to provide session |
| 329 | // resumption. See RFC 5077. If zero, it will be filled with |
| 330 | // random data before the first server handshake. |
| 331 | // |
| 332 | // If multiple servers are terminating connections for the same host |
| 333 | // they should all have the same SessionTicketKey. If the |
| 334 | // SessionTicketKey leaks, previously recorded and future TLS |
| 335 | // connections using that key are compromised. |
| 336 | SessionTicketKey [32]byte |
| 337 | |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 338 | // ClientSessionCache is a cache of ClientSessionState entries |
| 339 | // for TLS session resumption. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 340 | ClientSessionCache ClientSessionCache |
| 341 | |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 342 | // ServerSessionCache is a cache of sessionState entries for TLS session |
| 343 | // resumption. |
| 344 | ServerSessionCache ServerSessionCache |
| 345 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 346 | // MinVersion contains the minimum SSL/TLS version that is acceptable. |
| 347 | // If zero, then SSLv3 is taken as the minimum. |
| 348 | MinVersion uint16 |
| 349 | |
| 350 | // MaxVersion contains the maximum SSL/TLS version that is acceptable. |
| 351 | // If zero, then the maximum version supported by this package is used, |
| 352 | // which is currently TLS 1.2. |
| 353 | MaxVersion uint16 |
| 354 | |
| 355 | // CurvePreferences contains the elliptic curves that will be used in |
| 356 | // an ECDHE handshake, in preference order. If empty, the default will |
| 357 | // be used. |
| 358 | CurvePreferences []CurveID |
| 359 | |
David Benjamin | d30a990 | 2014-08-24 01:44:23 -0400 | [diff] [blame] | 360 | // ChannelID contains the ECDSA key for the client to use as |
| 361 | // its TLS Channel ID. |
| 362 | ChannelID *ecdsa.PrivateKey |
| 363 | |
| 364 | // RequestChannelID controls whether the server requests a TLS |
| 365 | // Channel ID. If negotiated, the client's public key is |
| 366 | // returned in the ConnectionState. |
| 367 | RequestChannelID bool |
| 368 | |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 369 | // PreSharedKey, if not nil, is the pre-shared key to use with |
| 370 | // the PSK cipher suites. |
| 371 | PreSharedKey []byte |
| 372 | |
| 373 | // PreSharedKeyIdentity, if not empty, is the identity to use |
| 374 | // with the PSK cipher suites. |
| 375 | PreSharedKeyIdentity string |
| 376 | |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 377 | // SRTPProtectionProfiles, if not nil, is the list of SRTP |
| 378 | // protection profiles to offer in DTLS-SRTP. |
| 379 | SRTPProtectionProfiles []uint16 |
| 380 | |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 381 | // SignatureAndHashes, if not nil, overrides the default set of |
| 382 | // supported signature and hash algorithms to advertise in |
| 383 | // CertificateRequest. |
| 384 | SignatureAndHashes []signatureAndHash |
| 385 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 386 | // Bugs specifies optional misbehaviour to be used for testing other |
| 387 | // implementations. |
| 388 | Bugs ProtocolBugs |
| 389 | |
| 390 | serverInitOnce sync.Once // guards calling (*Config).serverInit |
| 391 | } |
| 392 | |
| 393 | type BadValue int |
| 394 | |
| 395 | const ( |
| 396 | BadValueNone BadValue = iota |
| 397 | BadValueNegative |
| 398 | BadValueZero |
| 399 | BadValueLimit |
| 400 | BadValueLarge |
| 401 | NumBadValues |
| 402 | ) |
| 403 | |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 404 | type RSABadValue int |
| 405 | |
| 406 | const ( |
| 407 | RSABadValueNone RSABadValue = iota |
| 408 | RSABadValueCorrupt |
| 409 | RSABadValueTooLong |
| 410 | RSABadValueTooShort |
| 411 | RSABadValueWrongVersion |
| 412 | NumRSABadValues |
| 413 | ) |
| 414 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 415 | type ProtocolBugs struct { |
| 416 | // InvalidSKXSignature specifies that the signature in a |
| 417 | // ServerKeyExchange message should be invalid. |
| 418 | InvalidSKXSignature bool |
| 419 | |
David Benjamin | 6de0e53 | 2015-07-28 22:43:19 -0400 | [diff] [blame] | 420 | // InvalidCertVerifySignature specifies that the signature in a |
| 421 | // CertificateVerify message should be invalid. |
| 422 | InvalidCertVerifySignature bool |
| 423 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 424 | // InvalidSKXCurve causes the curve ID in the ServerKeyExchange message |
| 425 | // to be wrong. |
| 426 | InvalidSKXCurve bool |
| 427 | |
David Benjamin | 2b07fa4 | 2016-03-02 00:23:57 -0500 | [diff] [blame] | 428 | // InvalidECDHPoint, if true, causes the ECC points in |
| 429 | // ServerKeyExchange or ClientKeyExchange messages to be invalid. |
| 430 | InvalidECDHPoint bool |
| 431 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 432 | // BadECDSAR controls ways in which the 'r' value of an ECDSA signature |
| 433 | // can be invalid. |
| 434 | BadECDSAR BadValue |
| 435 | BadECDSAS BadValue |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 436 | |
| 437 | // MaxPadding causes CBC records to have the maximum possible padding. |
| 438 | MaxPadding bool |
| 439 | // PaddingFirstByteBad causes the first byte of the padding to be |
| 440 | // incorrect. |
| 441 | PaddingFirstByteBad bool |
| 442 | // PaddingFirstByteBadIf255 causes the first byte of padding to be |
| 443 | // incorrect if there's a maximum amount of padding (i.e. 255 bytes). |
| 444 | PaddingFirstByteBadIf255 bool |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 445 | |
| 446 | // FailIfNotFallbackSCSV causes a server handshake to fail if the |
| 447 | // client doesn't send the fallback SCSV value. |
| 448 | FailIfNotFallbackSCSV bool |
David Benjamin | 35a7a44 | 2014-07-05 00:23:20 -0400 | [diff] [blame] | 449 | |
| 450 | // DuplicateExtension causes an extra empty extension of bogus type to |
| 451 | // be emitted in either the ClientHello or the ServerHello. |
| 452 | DuplicateExtension bool |
David Benjamin | 1c375dd | 2014-07-12 00:48:23 -0400 | [diff] [blame] | 453 | |
| 454 | // UnauthenticatedECDH causes the server to pretend ECDHE_RSA |
| 455 | // and ECDHE_ECDSA cipher suites are actually ECDH_anon. No |
| 456 | // Certificate message is sent and no signature is added to |
| 457 | // ServerKeyExchange. |
| 458 | UnauthenticatedECDH bool |
David Benjamin | 9c651c9 | 2014-07-12 13:27:45 -0400 | [diff] [blame] | 459 | |
David Benjamin | b80168e | 2015-02-08 18:30:14 -0500 | [diff] [blame] | 460 | // SkipHelloVerifyRequest causes a DTLS server to skip the |
| 461 | // HelloVerifyRequest message. |
| 462 | SkipHelloVerifyRequest bool |
| 463 | |
David Benjamin | dcd979f | 2015-04-20 18:26:52 -0400 | [diff] [blame] | 464 | // SkipCertificateStatus, if true, causes the server to skip the |
| 465 | // CertificateStatus message. This is legal because CertificateStatus is |
| 466 | // optional, even with a status_request in ServerHello. |
| 467 | SkipCertificateStatus bool |
| 468 | |
David Benjamin | 9c651c9 | 2014-07-12 13:27:45 -0400 | [diff] [blame] | 469 | // SkipServerKeyExchange causes the server to skip sending |
| 470 | // ServerKeyExchange messages. |
| 471 | SkipServerKeyExchange bool |
David Benjamin | a0e5223 | 2014-07-19 17:39:58 -0400 | [diff] [blame] | 472 | |
David Benjamin | b80168e | 2015-02-08 18:30:14 -0500 | [diff] [blame] | 473 | // SkipNewSessionTicket causes the server to skip sending the |
| 474 | // NewSessionTicket message despite promising to in ServerHello. |
| 475 | SkipNewSessionTicket bool |
| 476 | |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 477 | // SkipClientCertificate causes the client to skip the Certificate |
| 478 | // message. |
| 479 | SkipClientCertificate bool |
| 480 | |
David Benjamin | a0e5223 | 2014-07-19 17:39:58 -0400 | [diff] [blame] | 481 | // SkipChangeCipherSpec causes the implementation to skip |
| 482 | // sending the ChangeCipherSpec message (and adjusting cipher |
| 483 | // state accordingly for the Finished message). |
| 484 | SkipChangeCipherSpec bool |
David Benjamin | f3ec83d | 2014-07-21 22:42:34 -0400 | [diff] [blame] | 485 | |
David Benjamin | b80168e | 2015-02-08 18:30:14 -0500 | [diff] [blame] | 486 | // SkipFinished causes the implementation to skip sending the Finished |
| 487 | // message. |
| 488 | SkipFinished bool |
| 489 | |
David Benjamin | f3ec83d | 2014-07-21 22:42:34 -0400 | [diff] [blame] | 490 | // EarlyChangeCipherSpec causes the client to send an early |
| 491 | // ChangeCipherSpec message before the ClientKeyExchange. A value of |
| 492 | // zero disables this behavior. One and two configure variants for 0.9.8 |
| 493 | // and 1.0.1 modes, respectively. |
| 494 | EarlyChangeCipherSpec int |
David Benjamin | d23f412 | 2014-07-23 15:09:48 -0400 | [diff] [blame] | 495 | |
David Benjamin | 86271ee | 2014-07-21 16:14:03 -0400 | [diff] [blame] | 496 | // FragmentAcrossChangeCipherSpec causes the implementation to fragment |
| 497 | // the Finished (or NextProto) message around the ChangeCipherSpec |
| 498 | // messages. |
| 499 | FragmentAcrossChangeCipherSpec bool |
| 500 | |
David Benjamin | d86c767 | 2014-08-02 04:07:12 -0400 | [diff] [blame] | 501 | // SendV2ClientHello causes the client to send a V2ClientHello |
| 502 | // instead of a normal ClientHello. |
| 503 | SendV2ClientHello bool |
David Benjamin | bef270a | 2014-08-02 04:22:02 -0400 | [diff] [blame] | 504 | |
| 505 | // SendFallbackSCSV causes the client to include |
| 506 | // TLS_FALLBACK_SCSV in the ClientHello. |
| 507 | SendFallbackSCSV bool |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 508 | |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 509 | // SendRenegotiationSCSV causes the client to include the renegotiation |
| 510 | // SCSV in the ClientHello. |
| 511 | SendRenegotiationSCSV bool |
| 512 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 513 | // MaxHandshakeRecordLength, if non-zero, is the maximum size of a |
David Benjamin | 9821454 | 2014-08-07 18:02:39 -0400 | [diff] [blame] | 514 | // handshake record. Handshake messages will be split into multiple |
| 515 | // records at the specified size, except that the client_version will |
David Benjamin | bd15a8e | 2015-05-29 18:48:16 -0400 | [diff] [blame] | 516 | // never be fragmented. For DTLS, it is the maximum handshake fragment |
| 517 | // size, not record size; DTLS allows multiple handshake fragments in a |
| 518 | // single handshake record. See |PackHandshakeFragments|. |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 519 | MaxHandshakeRecordLength int |
David Benjamin | a8e3e0e | 2014-08-06 22:11:10 -0400 | [diff] [blame] | 520 | |
David Benjamin | 9821454 | 2014-08-07 18:02:39 -0400 | [diff] [blame] | 521 | // FragmentClientVersion will allow MaxHandshakeRecordLength to apply to |
| 522 | // the first 6 bytes of the ClientHello. |
| 523 | FragmentClientVersion bool |
| 524 | |
Alex Chernyakhovsky | 4cd8c43 | 2014-11-01 19:39:08 -0400 | [diff] [blame] | 525 | // FragmentAlert will cause all alerts to be fragmented across |
| 526 | // two records. |
| 527 | FragmentAlert bool |
| 528 | |
David Benjamin | 0d3a8c6 | 2016-03-11 22:25:18 -0500 | [diff] [blame] | 529 | // DoubleAlert will cause all alerts to be sent as two copies packed |
| 530 | // within one record. |
| 531 | DoubleAlert bool |
| 532 | |
David Benjamin | 3fd1fbd | 2015-02-03 16:07:32 -0500 | [diff] [blame] | 533 | // SendSpuriousAlert, if non-zero, will cause an spurious, unwanted |
| 534 | // alert to be sent. |
| 535 | SendSpuriousAlert alert |
Alex Chernyakhovsky | 4cd8c43 | 2014-11-01 19:39:08 -0400 | [diff] [blame] | 536 | |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 537 | // BadRSAClientKeyExchange causes the client to send a corrupted RSA |
| 538 | // ClientKeyExchange which would not pass padding checks. |
| 539 | BadRSAClientKeyExchange RSABadValue |
David Benjamin | bed9aae | 2014-08-07 19:13:38 -0400 | [diff] [blame] | 540 | |
| 541 | // RenewTicketOnResume causes the server to renew the session ticket and |
| 542 | // send a NewSessionTicket message during an abbreviated handshake. |
| 543 | RenewTicketOnResume bool |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 544 | |
| 545 | // SendClientVersion, if non-zero, causes the client to send a different |
| 546 | // TLS version in the ClientHello than the maximum supported version. |
| 547 | SendClientVersion uint16 |
David Benjamin | 83c0bc9 | 2014-08-04 01:23:53 -0400 | [diff] [blame] | 548 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 549 | // ExpectFalseStart causes the server to, on full handshakes, |
| 550 | // expect the peer to False Start; the server Finished message |
| 551 | // isn't sent until we receive an application data record |
| 552 | // from the peer. |
| 553 | ExpectFalseStart bool |
David Benjamin | 5c24a1d | 2014-08-31 00:59:27 -0400 | [diff] [blame] | 554 | |
David Benjamin | 1c63315 | 2015-04-02 20:19:11 -0400 | [diff] [blame] | 555 | // AlertBeforeFalseStartTest, if non-zero, causes the server to, on full |
| 556 | // handshakes, send an alert just before reading the application data |
| 557 | // record to test False Start. This can be used in a negative False |
| 558 | // Start test to determine whether the peer processed the alert (and |
| 559 | // closed the connection) before or after sending app data. |
| 560 | AlertBeforeFalseStartTest alert |
| 561 | |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 562 | // ExpectServerName, if not empty, is the hostname the client |
| 563 | // must specify in the server_name extension. |
| 564 | ExpectServerName string |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 565 | |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 566 | // SwapNPNAndALPN switches the relative order between NPN and ALPN in |
| 567 | // both ClientHello and ServerHello. |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 568 | SwapNPNAndALPN bool |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 569 | |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 570 | // ALPNProtocol, if not nil, sets the ALPN protocol that a server will |
| 571 | // return. |
| 572 | ALPNProtocol *string |
| 573 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 574 | // AllowSessionVersionMismatch causes the server to resume sessions |
| 575 | // regardless of the version associated with the session. |
| 576 | AllowSessionVersionMismatch bool |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 577 | |
| 578 | // CorruptTicket causes a client to corrupt a session ticket before |
| 579 | // sending it in a resume handshake. |
| 580 | CorruptTicket bool |
| 581 | |
| 582 | // OversizedSessionId causes the session id that is sent with a ticket |
| 583 | // resumption attempt to be too large (33 bytes). |
| 584 | OversizedSessionId bool |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 585 | |
| 586 | // RequireExtendedMasterSecret, if true, requires that the peer support |
| 587 | // the extended master secret option. |
| 588 | RequireExtendedMasterSecret bool |
| 589 | |
David Benjamin | ca6554b | 2014-11-08 12:31:52 -0500 | [diff] [blame] | 590 | // NoExtendedMasterSecret causes the client and server to behave as if |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 591 | // they didn't support an extended master secret. |
| 592 | NoExtendedMasterSecret bool |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 593 | |
| 594 | // EmptyRenegotiationInfo causes the renegotiation extension to be |
| 595 | // empty in a renegotiation handshake. |
| 596 | EmptyRenegotiationInfo bool |
| 597 | |
| 598 | // BadRenegotiationInfo causes the renegotiation extension value in a |
| 599 | // renegotiation handshake to be incorrect. |
| 600 | BadRenegotiationInfo bool |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 601 | |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 602 | // NoRenegotiationInfo disables renegotiation info support in all |
| 603 | // handshakes. |
David Benjamin | ca6554b | 2014-11-08 12:31:52 -0500 | [diff] [blame] | 604 | NoRenegotiationInfo bool |
| 605 | |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 606 | // NoRenegotiationInfoInInitial disables renegotiation info support in |
| 607 | // the initial handshake. |
| 608 | NoRenegotiationInfoInInitial bool |
| 609 | |
| 610 | // NoRenegotiationInfoAfterInitial disables renegotiation info support |
| 611 | // in renegotiation handshakes. |
| 612 | NoRenegotiationInfoAfterInitial bool |
| 613 | |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 614 | // RequireRenegotiationInfo, if true, causes the client to return an |
| 615 | // error if the server doesn't reply with the renegotiation extension. |
| 616 | RequireRenegotiationInfo bool |
| 617 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 618 | // SequenceNumberMapping, if non-nil, is the mapping function to apply |
| 619 | // to the sequence number of outgoing packets. For both TLS and DTLS, |
| 620 | // the two most-significant bytes in the resulting sequence number are |
| 621 | // ignored so that the DTLS epoch cannot be changed. |
| 622 | SequenceNumberMapping func(uint64) uint64 |
David Benjamin | 9114fae | 2014-11-08 11:41:14 -0500 | [diff] [blame] | 623 | |
David Benjamin | a3e8949 | 2015-02-26 15:16:22 -0500 | [diff] [blame] | 624 | // RSAEphemeralKey, if true, causes the server to send a |
| 625 | // ServerKeyExchange message containing an ephemeral key (as in |
| 626 | // RSA_EXPORT) in the plain RSA key exchange. |
| 627 | RSAEphemeralKey bool |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 628 | |
| 629 | // SRTPMasterKeyIdentifer, if not empty, is the SRTP MKI value that the |
| 630 | // client offers when negotiating SRTP. MKI support is still missing so |
| 631 | // the peer must still send none. |
| 632 | SRTPMasterKeyIdentifer string |
| 633 | |
| 634 | // SendSRTPProtectionProfile, if non-zero, is the SRTP profile that the |
| 635 | // server sends in the ServerHello instead of the negotiated one. |
| 636 | SendSRTPProtectionProfile uint16 |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 637 | |
| 638 | // NoSignatureAndHashes, if true, causes the client to omit the |
| 639 | // signature and hashes extension. |
| 640 | // |
| 641 | // For a server, it will cause an empty list to be sent in the |
| 642 | // CertificateRequest message. None the less, the configured set will |
| 643 | // still be enforced. |
| 644 | NoSignatureAndHashes bool |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 645 | |
David Benjamin | 55a4364 | 2015-04-20 14:45:55 -0400 | [diff] [blame] | 646 | // NoSupportedCurves, if true, causes the client to omit the |
| 647 | // supported_curves extension. |
| 648 | NoSupportedCurves bool |
| 649 | |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 650 | // RequireSameRenegoClientVersion, if true, causes the server |
| 651 | // to require that all ClientHellos match in offered version |
| 652 | // across a renego. |
| 653 | RequireSameRenegoClientVersion bool |
Feng Lu | 41aa325 | 2014-11-21 22:47:56 -0800 | [diff] [blame] | 654 | |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 655 | // ExpectInitialRecordVersion, if non-zero, is the expected |
| 656 | // version of the records before the version is determined. |
| 657 | ExpectInitialRecordVersion uint16 |
David Benjamin | 13be1de | 2015-01-11 16:29:36 -0500 | [diff] [blame] | 658 | |
| 659 | // MaxPacketLength, if non-zero, is the maximum acceptable size for a |
| 660 | // packet. |
| 661 | MaxPacketLength int |
David Benjamin | 6095de8 | 2014-12-27 01:50:38 -0500 | [diff] [blame] | 662 | |
| 663 | // SendCipherSuite, if non-zero, is the cipher suite value that the |
| 664 | // server will send in the ServerHello. This does not affect the cipher |
| 665 | // the server believes it has actually negotiated. |
| 666 | SendCipherSuite uint16 |
David Benjamin | 4189bd9 | 2015-01-25 23:52:39 -0500 | [diff] [blame] | 667 | |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 668 | // AppDataBeforeHandshake, if not nil, causes application data to be |
| 669 | // sent immediately before the first handshake message. |
| 670 | AppDataBeforeHandshake []byte |
| 671 | |
| 672 | // AppDataAfterChangeCipherSpec, if not nil, causes application data to |
David Benjamin | 4189bd9 | 2015-01-25 23:52:39 -0500 | [diff] [blame] | 673 | // be sent immediately after ChangeCipherSpec. |
| 674 | AppDataAfterChangeCipherSpec []byte |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 675 | |
David Benjamin | dc3da93 | 2015-03-12 15:09:02 -0400 | [diff] [blame] | 676 | // AlertAfterChangeCipherSpec, if non-zero, causes an alert to be sent |
| 677 | // immediately after ChangeCipherSpec. |
| 678 | AlertAfterChangeCipherSpec alert |
| 679 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 680 | // TimeoutSchedule is the schedule of packet drops and simulated |
| 681 | // timeouts for before each handshake leg from the peer. |
| 682 | TimeoutSchedule []time.Duration |
| 683 | |
| 684 | // PacketAdaptor is the packetAdaptor to use to simulate timeouts. |
| 685 | PacketAdaptor *packetAdaptor |
David Benjamin | b3774b9 | 2015-01-31 17:16:01 -0500 | [diff] [blame] | 686 | |
| 687 | // ReorderHandshakeFragments, if true, causes handshake fragments in |
| 688 | // DTLS to overlap and be sent in the wrong order. It also causes |
| 689 | // pre-CCS flights to be sent twice. (Post-CCS flights consist of |
| 690 | // Finished and will trigger a spurious retransmit.) |
| 691 | ReorderHandshakeFragments bool |
David Benjamin | ddb9f15 | 2015-02-03 15:44:39 -0500 | [diff] [blame] | 692 | |
David Benjamin | 7538122 | 2015-03-02 19:30:30 -0500 | [diff] [blame] | 693 | // MixCompleteMessageWithFragments, if true, causes handshake |
| 694 | // messages in DTLS to redundantly both fragment the message |
| 695 | // and include a copy of the full one. |
| 696 | MixCompleteMessageWithFragments bool |
| 697 | |
David Benjamin | ddb9f15 | 2015-02-03 15:44:39 -0500 | [diff] [blame] | 698 | // SendInvalidRecordType, if true, causes a record with an invalid |
| 699 | // content type to be sent immediately following the handshake. |
| 700 | SendInvalidRecordType bool |
David Benjamin | bcb2d91 | 2015-02-24 23:45:43 -0500 | [diff] [blame] | 701 | |
| 702 | // WrongCertificateMessageType, if true, causes Certificate message to |
| 703 | // be sent with the wrong message type. |
| 704 | WrongCertificateMessageType bool |
David Benjamin | 7538122 | 2015-03-02 19:30:30 -0500 | [diff] [blame] | 705 | |
| 706 | // FragmentMessageTypeMismatch, if true, causes all non-initial |
| 707 | // handshake fragments in DTLS to have the wrong message type. |
| 708 | FragmentMessageTypeMismatch bool |
| 709 | |
| 710 | // FragmentMessageLengthMismatch, if true, causes all non-initial |
| 711 | // handshake fragments in DTLS to have the wrong message length. |
| 712 | FragmentMessageLengthMismatch bool |
| 713 | |
David Benjamin | 11fc66a | 2015-06-16 11:40:24 -0400 | [diff] [blame] | 714 | // SplitFragments, if non-zero, causes the handshake fragments in DTLS |
| 715 | // to be split across two records. The value of |SplitFragments| is the |
| 716 | // number of bytes in the first fragment. |
| 717 | SplitFragments int |
David Benjamin | 7538122 | 2015-03-02 19:30:30 -0500 | [diff] [blame] | 718 | |
| 719 | // SendEmptyFragments, if true, causes handshakes to include empty |
| 720 | // fragments in DTLS. |
| 721 | SendEmptyFragments bool |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 722 | |
David Benjamin | 9a41d1b | 2015-05-16 01:30:09 -0400 | [diff] [blame] | 723 | // SendSplitAlert, if true, causes an alert to be sent with the header |
| 724 | // and record body split across multiple packets. The peer should |
| 725 | // discard these packets rather than process it. |
| 726 | SendSplitAlert bool |
| 727 | |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 728 | // FailIfResumeOnRenego, if true, causes renegotiations to fail if the |
| 729 | // client offers a resumption or the server accepts one. |
| 730 | FailIfResumeOnRenego bool |
David Benjamin | 3c9746a | 2015-03-19 15:00:10 -0400 | [diff] [blame] | 731 | |
David Benjamin | 67d1fb5 | 2015-03-16 15:16:23 -0400 | [diff] [blame] | 732 | // IgnorePeerCipherPreferences, if true, causes the peer's cipher |
| 733 | // preferences to be ignored. |
| 734 | IgnorePeerCipherPreferences bool |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 735 | |
| 736 | // IgnorePeerSignatureAlgorithmPreferences, if true, causes the peer's |
| 737 | // signature algorithm preferences to be ignored. |
| 738 | IgnorePeerSignatureAlgorithmPreferences bool |
David Benjamin | 340d5ed | 2015-03-21 02:21:37 -0400 | [diff] [blame] | 739 | |
David Benjamin | c574f41 | 2015-04-20 11:13:01 -0400 | [diff] [blame] | 740 | // IgnorePeerCurvePreferences, if true, causes the peer's curve |
| 741 | // preferences to be ignored. |
| 742 | IgnorePeerCurvePreferences bool |
| 743 | |
David Benjamin | 513f0ea | 2015-04-02 19:33:31 -0400 | [diff] [blame] | 744 | // BadFinished, if true, causes the Finished hash to be broken. |
| 745 | BadFinished bool |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 746 | |
| 747 | // DHGroupPrime, if not nil, is used to define the (finite field) |
| 748 | // Diffie-Hellman group. The generator used is always two. |
| 749 | DHGroupPrime *big.Int |
David Benjamin | bd15a8e | 2015-05-29 18:48:16 -0400 | [diff] [blame] | 750 | |
| 751 | // PackHandshakeFragments, if true, causes handshake fragments to be |
| 752 | // packed into individual handshake records, up to the specified record |
| 753 | // size. |
| 754 | PackHandshakeFragments int |
| 755 | |
| 756 | // PackHandshakeRecords, if true, causes handshake records to be packed |
| 757 | // into individual packets, up to the specified packet size. |
| 758 | PackHandshakeRecords int |
David Benjamin | 0fa4012 | 2015-05-30 17:13:12 -0400 | [diff] [blame] | 759 | |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 760 | // EnableAllCiphers, if true, causes all configured ciphers to be |
| 761 | // enabled. |
| 762 | EnableAllCiphers bool |
David Benjamin | 8923c0b | 2015-06-07 11:42:34 -0400 | [diff] [blame] | 763 | |
| 764 | // EmptyCertificateList, if true, causes the server to send an empty |
| 765 | // certificate list in the Certificate message. |
| 766 | EmptyCertificateList bool |
David Benjamin | d98452d | 2015-06-16 14:16:23 -0400 | [diff] [blame] | 767 | |
| 768 | // ExpectNewTicket, if true, causes the client to abort if it does not |
| 769 | // receive a new ticket. |
| 770 | ExpectNewTicket bool |
Adam Langley | 33ad2b5 | 2015-07-20 17:43:53 -0700 | [diff] [blame] | 771 | |
| 772 | // RequireClientHelloSize, if not zero, is the required length in bytes |
| 773 | // of the ClientHello /record/. This is checked by the server. |
| 774 | RequireClientHelloSize int |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 775 | |
| 776 | // CustomExtension, if not empty, contains the contents of an extension |
| 777 | // that will be added to client/server hellos. |
| 778 | CustomExtension string |
| 779 | |
| 780 | // ExpectedCustomExtension, if not nil, contains the expected contents |
| 781 | // of a custom extension. |
| 782 | ExpectedCustomExtension *string |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 783 | |
| 784 | // NoCloseNotify, if true, causes the close_notify alert to be skipped |
| 785 | // on connection shutdown. |
| 786 | NoCloseNotify bool |
| 787 | |
David Benjamin | fa214e4 | 2016-05-10 17:03:10 -0400 | [diff] [blame] | 788 | // SendAlertOnShutdown, if non-zero, is the alert to send instead of |
| 789 | // close_notify on shutdown. |
| 790 | SendAlertOnShutdown alert |
| 791 | |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 792 | // ExpectCloseNotify, if true, requires a close_notify from the peer on |
| 793 | // shutdown. Records from the peer received after close_notify is sent |
| 794 | // are not discard. |
| 795 | ExpectCloseNotify bool |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 796 | |
| 797 | // SendLargeRecords, if true, allows outgoing records to be sent |
| 798 | // arbitrarily large. |
| 799 | SendLargeRecords bool |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 800 | |
| 801 | // NegotiateALPNAndNPN, if true, causes the server to negotiate both |
| 802 | // ALPN and NPN in the same connetion. |
| 803 | NegotiateALPNAndNPN bool |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 804 | |
| 805 | // SendEmptySessionTicket, if true, causes the server to send an empty |
| 806 | // session ticket. |
| 807 | SendEmptySessionTicket bool |
| 808 | |
| 809 | // FailIfSessionOffered, if true, causes the server to fail any |
| 810 | // connections where the client offers a non-empty session ID or session |
| 811 | // ticket. |
| 812 | FailIfSessionOffered bool |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 813 | |
| 814 | // SendHelloRequestBeforeEveryAppDataRecord, if true, causes a |
| 815 | // HelloRequest handshake message to be sent before each application |
| 816 | // data record. This only makes sense for a server. |
| 817 | SendHelloRequestBeforeEveryAppDataRecord bool |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 818 | |
| 819 | // RequireDHPublicValueLen causes a fatal error if the length (in |
| 820 | // bytes) of the server's Diffie-Hellman public value is not equal to |
| 821 | // this. |
| 822 | RequireDHPublicValueLen int |
David Benjamin | 8411b24 | 2015-11-26 12:07:28 -0500 | [diff] [blame] | 823 | |
| 824 | // BadChangeCipherSpec, if not nil, is the body to be sent in |
| 825 | // ChangeCipherSpec records instead of {1}. |
| 826 | BadChangeCipherSpec []byte |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 827 | |
| 828 | // BadHelloRequest, if not nil, is what to send instead of a |
| 829 | // HelloRequest. |
| 830 | BadHelloRequest []byte |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 831 | |
| 832 | // RequireSessionTickets, if true, causes the client to require new |
| 833 | // sessions use session tickets instead of session IDs. |
| 834 | RequireSessionTickets bool |
David Benjamin | f2b8363 | 2016-03-01 22:57:46 -0500 | [diff] [blame] | 835 | |
| 836 | // NullAllCiphers, if true, causes every cipher to behave like the null |
| 837 | // cipher. |
| 838 | NullAllCiphers bool |
David Benjamin | 80d1b35 | 2016-05-04 19:19:06 -0400 | [diff] [blame] | 839 | |
| 840 | // SendSCTListOnResume, if not nil, causes the server to send the |
| 841 | // supplied SCT list in resumption handshakes. |
| 842 | SendSCTListOnResume []byte |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 843 | |
| 844 | // CECPQ1BadX25519Part corrupts the X25519 part of a CECPQ1 key exchange, as |
| 845 | // a trivial proof that it is actually used. |
| 846 | CECPQ1BadX25519Part bool |
| 847 | |
| 848 | // CECPQ1BadNewhopePart corrupts the Newhope part of a CECPQ1 key exchange, |
| 849 | // as a trivial proof that it is actually used. |
| 850 | CECPQ1BadNewhopePart bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | func (c *Config) serverInit() { |
| 854 | if c.SessionTicketsDisabled { |
| 855 | return |
| 856 | } |
| 857 | |
| 858 | // If the key has already been set then we have nothing to do. |
| 859 | for _, b := range c.SessionTicketKey { |
| 860 | if b != 0 { |
| 861 | return |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | if _, err := io.ReadFull(c.rand(), c.SessionTicketKey[:]); err != nil { |
| 866 | c.SessionTicketsDisabled = true |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | func (c *Config) rand() io.Reader { |
| 871 | r := c.Rand |
| 872 | if r == nil { |
| 873 | return rand.Reader |
| 874 | } |
| 875 | return r |
| 876 | } |
| 877 | |
| 878 | func (c *Config) time() time.Time { |
| 879 | t := c.Time |
| 880 | if t == nil { |
| 881 | t = time.Now |
| 882 | } |
| 883 | return t() |
| 884 | } |
| 885 | |
| 886 | func (c *Config) cipherSuites() []uint16 { |
| 887 | s := c.CipherSuites |
| 888 | if s == nil { |
| 889 | s = defaultCipherSuites() |
| 890 | } |
| 891 | return s |
| 892 | } |
| 893 | |
| 894 | func (c *Config) minVersion() uint16 { |
| 895 | if c == nil || c.MinVersion == 0 { |
| 896 | return minVersion |
| 897 | } |
| 898 | return c.MinVersion |
| 899 | } |
| 900 | |
| 901 | func (c *Config) maxVersion() uint16 { |
| 902 | if c == nil || c.MaxVersion == 0 { |
| 903 | return maxVersion |
| 904 | } |
| 905 | return c.MaxVersion |
| 906 | } |
| 907 | |
David Benjamin | cba2b62 | 2015-12-18 22:13:41 -0500 | [diff] [blame] | 908 | var defaultCurvePreferences = []CurveID{CurveX25519, CurveP256, CurveP384, CurveP521} |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 909 | |
| 910 | func (c *Config) curvePreferences() []CurveID { |
| 911 | if c == nil || len(c.CurvePreferences) == 0 { |
| 912 | return defaultCurvePreferences |
| 913 | } |
| 914 | return c.CurvePreferences |
| 915 | } |
| 916 | |
| 917 | // mutualVersion returns the protocol version to use given the advertised |
| 918 | // version of the peer. |
| 919 | func (c *Config) mutualVersion(vers uint16) (uint16, bool) { |
| 920 | minVersion := c.minVersion() |
| 921 | maxVersion := c.maxVersion() |
| 922 | |
| 923 | if vers < minVersion { |
| 924 | return 0, false |
| 925 | } |
| 926 | if vers > maxVersion { |
| 927 | vers = maxVersion |
| 928 | } |
| 929 | return vers, true |
| 930 | } |
| 931 | |
| 932 | // getCertificateForName returns the best certificate for the given name, |
| 933 | // defaulting to the first element of c.Certificates if there are no good |
| 934 | // options. |
| 935 | func (c *Config) getCertificateForName(name string) *Certificate { |
| 936 | if len(c.Certificates) == 1 || c.NameToCertificate == nil { |
| 937 | // There's only one choice, so no point doing any work. |
| 938 | return &c.Certificates[0] |
| 939 | } |
| 940 | |
| 941 | name = strings.ToLower(name) |
| 942 | for len(name) > 0 && name[len(name)-1] == '.' { |
| 943 | name = name[:len(name)-1] |
| 944 | } |
| 945 | |
| 946 | if cert, ok := c.NameToCertificate[name]; ok { |
| 947 | return cert |
| 948 | } |
| 949 | |
| 950 | // try replacing labels in the name with wildcards until we get a |
| 951 | // match. |
| 952 | labels := strings.Split(name, ".") |
| 953 | for i := range labels { |
| 954 | labels[i] = "*" |
| 955 | candidate := strings.Join(labels, ".") |
| 956 | if cert, ok := c.NameToCertificate[candidate]; ok { |
| 957 | return cert |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | // If nothing matches, return the first certificate. |
| 962 | return &c.Certificates[0] |
| 963 | } |
| 964 | |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 965 | func (c *Config) signatureAndHashesForServer() []signatureAndHash { |
| 966 | if c != nil && c.SignatureAndHashes != nil { |
| 967 | return c.SignatureAndHashes |
| 968 | } |
| 969 | return supportedClientCertSignatureAlgorithms |
| 970 | } |
| 971 | |
| 972 | func (c *Config) signatureAndHashesForClient() []signatureAndHash { |
| 973 | if c != nil && c.SignatureAndHashes != nil { |
| 974 | return c.SignatureAndHashes |
| 975 | } |
| 976 | return supportedSKXSignatureAlgorithms |
| 977 | } |
| 978 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 979 | // BuildNameToCertificate parses c.Certificates and builds c.NameToCertificate |
| 980 | // from the CommonName and SubjectAlternateName fields of each of the leaf |
| 981 | // certificates. |
| 982 | func (c *Config) BuildNameToCertificate() { |
| 983 | c.NameToCertificate = make(map[string]*Certificate) |
| 984 | for i := range c.Certificates { |
| 985 | cert := &c.Certificates[i] |
| 986 | x509Cert, err := x509.ParseCertificate(cert.Certificate[0]) |
| 987 | if err != nil { |
| 988 | continue |
| 989 | } |
| 990 | if len(x509Cert.Subject.CommonName) > 0 { |
| 991 | c.NameToCertificate[x509Cert.Subject.CommonName] = cert |
| 992 | } |
| 993 | for _, san := range x509Cert.DNSNames { |
| 994 | c.NameToCertificate[san] = cert |
| 995 | } |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | // A Certificate is a chain of one or more certificates, leaf first. |
| 1000 | type Certificate struct { |
| 1001 | Certificate [][]byte |
| 1002 | PrivateKey crypto.PrivateKey // supported types: *rsa.PrivateKey, *ecdsa.PrivateKey |
| 1003 | // OCSPStaple contains an optional OCSP response which will be served |
| 1004 | // to clients that request it. |
| 1005 | OCSPStaple []byte |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 1006 | // SignedCertificateTimestampList contains an optional encoded |
| 1007 | // SignedCertificateTimestampList structure which will be |
| 1008 | // served to clients that request it. |
| 1009 | SignedCertificateTimestampList []byte |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1010 | // Leaf is the parsed form of the leaf certificate, which may be |
| 1011 | // initialized using x509.ParseCertificate to reduce per-handshake |
| 1012 | // processing for TLS clients doing client authentication. If nil, the |
| 1013 | // leaf certificate will be parsed as needed. |
| 1014 | Leaf *x509.Certificate |
| 1015 | } |
| 1016 | |
| 1017 | // A TLS record. |
| 1018 | type record struct { |
| 1019 | contentType recordType |
| 1020 | major, minor uint8 |
| 1021 | payload []byte |
| 1022 | } |
| 1023 | |
| 1024 | type handshakeMessage interface { |
| 1025 | marshal() []byte |
| 1026 | unmarshal([]byte) bool |
| 1027 | } |
| 1028 | |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 1029 | // lruSessionCache is a client or server session cache implementation |
| 1030 | // that uses an LRU caching strategy. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1031 | type lruSessionCache struct { |
| 1032 | sync.Mutex |
| 1033 | |
| 1034 | m map[string]*list.Element |
| 1035 | q *list.List |
| 1036 | capacity int |
| 1037 | } |
| 1038 | |
| 1039 | type lruSessionCacheEntry struct { |
| 1040 | sessionKey string |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 1041 | state interface{} |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | // Put adds the provided (sessionKey, cs) pair to the cache. |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 1045 | func (c *lruSessionCache) Put(sessionKey string, cs interface{}) { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1046 | c.Lock() |
| 1047 | defer c.Unlock() |
| 1048 | |
| 1049 | if elem, ok := c.m[sessionKey]; ok { |
| 1050 | entry := elem.Value.(*lruSessionCacheEntry) |
| 1051 | entry.state = cs |
| 1052 | c.q.MoveToFront(elem) |
| 1053 | return |
| 1054 | } |
| 1055 | |
| 1056 | if c.q.Len() < c.capacity { |
| 1057 | entry := &lruSessionCacheEntry{sessionKey, cs} |
| 1058 | c.m[sessionKey] = c.q.PushFront(entry) |
| 1059 | return |
| 1060 | } |
| 1061 | |
| 1062 | elem := c.q.Back() |
| 1063 | entry := elem.Value.(*lruSessionCacheEntry) |
| 1064 | delete(c.m, entry.sessionKey) |
| 1065 | entry.sessionKey = sessionKey |
| 1066 | entry.state = cs |
| 1067 | c.q.MoveToFront(elem) |
| 1068 | c.m[sessionKey] = elem |
| 1069 | } |
| 1070 | |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 1071 | // Get returns the value associated with a given key. It returns (nil, |
| 1072 | // false) if no value is found. |
| 1073 | func (c *lruSessionCache) Get(sessionKey string) (interface{}, bool) { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1074 | c.Lock() |
| 1075 | defer c.Unlock() |
| 1076 | |
| 1077 | if elem, ok := c.m[sessionKey]; ok { |
| 1078 | c.q.MoveToFront(elem) |
| 1079 | return elem.Value.(*lruSessionCacheEntry).state, true |
| 1080 | } |
| 1081 | return nil, false |
| 1082 | } |
| 1083 | |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 1084 | // lruClientSessionCache is a ClientSessionCache implementation that |
| 1085 | // uses an LRU caching strategy. |
| 1086 | type lruClientSessionCache struct { |
| 1087 | lruSessionCache |
| 1088 | } |
| 1089 | |
| 1090 | func (c *lruClientSessionCache) Put(sessionKey string, cs *ClientSessionState) { |
| 1091 | c.lruSessionCache.Put(sessionKey, cs) |
| 1092 | } |
| 1093 | |
| 1094 | func (c *lruClientSessionCache) Get(sessionKey string) (*ClientSessionState, bool) { |
| 1095 | cs, ok := c.lruSessionCache.Get(sessionKey) |
| 1096 | if !ok { |
| 1097 | return nil, false |
| 1098 | } |
| 1099 | return cs.(*ClientSessionState), true |
| 1100 | } |
| 1101 | |
| 1102 | // lruServerSessionCache is a ServerSessionCache implementation that |
| 1103 | // uses an LRU caching strategy. |
| 1104 | type lruServerSessionCache struct { |
| 1105 | lruSessionCache |
| 1106 | } |
| 1107 | |
| 1108 | func (c *lruServerSessionCache) Put(sessionId string, session *sessionState) { |
| 1109 | c.lruSessionCache.Put(sessionId, session) |
| 1110 | } |
| 1111 | |
| 1112 | func (c *lruServerSessionCache) Get(sessionId string) (*sessionState, bool) { |
| 1113 | cs, ok := c.lruSessionCache.Get(sessionId) |
| 1114 | if !ok { |
| 1115 | return nil, false |
| 1116 | } |
| 1117 | return cs.(*sessionState), true |
| 1118 | } |
| 1119 | |
| 1120 | // NewLRUClientSessionCache returns a ClientSessionCache with the given |
| 1121 | // capacity that uses an LRU strategy. If capacity is < 1, a default capacity |
| 1122 | // is used instead. |
| 1123 | func NewLRUClientSessionCache(capacity int) ClientSessionCache { |
| 1124 | const defaultSessionCacheCapacity = 64 |
| 1125 | |
| 1126 | if capacity < 1 { |
| 1127 | capacity = defaultSessionCacheCapacity |
| 1128 | } |
| 1129 | return &lruClientSessionCache{ |
| 1130 | lruSessionCache{ |
| 1131 | m: make(map[string]*list.Element), |
| 1132 | q: list.New(), |
| 1133 | capacity: capacity, |
| 1134 | }, |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | // NewLRUServerSessionCache returns a ServerSessionCache with the given |
| 1139 | // capacity that uses an LRU strategy. If capacity is < 1, a default capacity |
| 1140 | // is used instead. |
| 1141 | func NewLRUServerSessionCache(capacity int) ServerSessionCache { |
| 1142 | const defaultSessionCacheCapacity = 64 |
| 1143 | |
| 1144 | if capacity < 1 { |
| 1145 | capacity = defaultSessionCacheCapacity |
| 1146 | } |
| 1147 | return &lruServerSessionCache{ |
| 1148 | lruSessionCache{ |
| 1149 | m: make(map[string]*list.Element), |
| 1150 | q: list.New(), |
| 1151 | capacity: capacity, |
| 1152 | }, |
| 1153 | } |
| 1154 | } |
| 1155 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1156 | // TODO(jsing): Make these available to both crypto/x509 and crypto/tls. |
| 1157 | type dsaSignature struct { |
| 1158 | R, S *big.Int |
| 1159 | } |
| 1160 | |
| 1161 | type ecdsaSignature dsaSignature |
| 1162 | |
| 1163 | var emptyConfig Config |
| 1164 | |
| 1165 | func defaultConfig() *Config { |
| 1166 | return &emptyConfig |
| 1167 | } |
| 1168 | |
| 1169 | var ( |
| 1170 | once sync.Once |
| 1171 | varDefaultCipherSuites []uint16 |
| 1172 | ) |
| 1173 | |
| 1174 | func defaultCipherSuites() []uint16 { |
| 1175 | once.Do(initDefaultCipherSuites) |
| 1176 | return varDefaultCipherSuites |
| 1177 | } |
| 1178 | |
| 1179 | func initDefaultCipherSuites() { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1180 | for _, suite := range cipherSuites { |
| 1181 | if suite.flags&suitePSK == 0 { |
| 1182 | varDefaultCipherSuites = append(varDefaultCipherSuites, suite.id) |
| 1183 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | func unexpectedMessageError(wanted, got interface{}) error { |
| 1188 | return fmt.Errorf("tls: received unexpected handshake message of type %T when waiting for %T", got, wanted) |
| 1189 | } |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 1190 | |
| 1191 | func isSupportedSignatureAndHash(sigHash signatureAndHash, sigHashes []signatureAndHash) bool { |
| 1192 | for _, s := range sigHashes { |
| 1193 | if s == sigHash { |
| 1194 | return true |
| 1195 | } |
| 1196 | } |
| 1197 | return false |
| 1198 | } |