blob: ed60a3b3badecbec4e091c3fbc7d84b5569b159b [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
5package main
6
7import (
8 "container/list"
9 "crypto"
10 "crypto/rand"
11 "crypto/x509"
12 "fmt"
13 "io"
14 "math/big"
15 "strings"
16 "sync"
17 "time"
18)
19
20const (
21 VersionSSL30 = 0x0300
22 VersionTLS10 = 0x0301
23 VersionTLS11 = 0x0302
24 VersionTLS12 = 0x0303
25)
26
27const (
28 maxPlaintext = 16384 // maximum plaintext payload length
29 maxCiphertext = 16384 + 2048 // maximum ciphertext payload length
30 recordHeaderLen = 5 // record header length
31 maxHandshake = 65536 // maximum handshake we support (protocol max is 16 MB)
32
33 minVersion = VersionSSL30
34 maxVersion = VersionTLS12
35)
36
37// TLS record types.
38type recordType uint8
39
40const (
41 recordTypeChangeCipherSpec recordType = 20
42 recordTypeAlert recordType = 21
43 recordTypeHandshake recordType = 22
44 recordTypeApplicationData recordType = 23
45)
46
47// TLS handshake message types.
48const (
49 typeClientHello uint8 = 1
50 typeServerHello uint8 = 2
51 typeNewSessionTicket uint8 = 4
52 typeCertificate uint8 = 11
53 typeServerKeyExchange uint8 = 12
54 typeCertificateRequest uint8 = 13
55 typeServerHelloDone uint8 = 14
56 typeCertificateVerify uint8 = 15
57 typeClientKeyExchange uint8 = 16
58 typeFinished uint8 = 20
59 typeCertificateStatus uint8 = 22
60 typeNextProtocol uint8 = 67 // Not IANA assigned
61)
62
63// TLS compression types.
64const (
65 compressionNone uint8 = 0
66)
67
68// TLS extension numbers
69const (
70 extensionServerName uint16 = 0
71 extensionStatusRequest uint16 = 5
72 extensionSupportedCurves uint16 = 10
73 extensionSupportedPoints uint16 = 11
74 extensionSignatureAlgorithms uint16 = 13
75 extensionSessionTicket uint16 = 35
76 extensionNextProtoNeg uint16 = 13172 // not IANA assigned
77 extensionRenegotiationInfo uint16 = 0xff01
78)
79
80// TLS signaling cipher suite values
81const (
82 scsvRenegotiation uint16 = 0x00ff
83)
84
85// CurveID is the type of a TLS identifier for an elliptic curve. See
86// http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-8
87type CurveID uint16
88
89const (
90 CurveP256 CurveID = 23
91 CurveP384 CurveID = 24
92 CurveP521 CurveID = 25
93)
94
95// TLS Elliptic Curve Point Formats
96// http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-9
97const (
98 pointFormatUncompressed uint8 = 0
99)
100
101// TLS CertificateStatusType (RFC 3546)
102const (
103 statusTypeOCSP uint8 = 1
104)
105
106// Certificate types (for certificateRequestMsg)
107const (
David Benjamin7b030512014-07-08 17:30:11 -0400108 CertTypeRSASign = 1 // A certificate containing an RSA key
109 CertTypeDSSSign = 2 // A certificate containing a DSA key
110 CertTypeRSAFixedDH = 3 // A certificate containing a static DH key
111 CertTypeDSSFixedDH = 4 // A certificate containing a static DH key
Adam Langley95c29f32014-06-20 12:00:00 -0700112
113 // See RFC4492 sections 3 and 5.5.
David Benjamin7b030512014-07-08 17:30:11 -0400114 CertTypeECDSASign = 64 // A certificate containing an ECDSA-capable public key, signed with ECDSA.
115 CertTypeRSAFixedECDH = 65 // A certificate containing an ECDH-capable public key, signed with RSA.
116 CertTypeECDSAFixedECDH = 66 // A certificate containing an ECDH-capable public key, signed with ECDSA.
Adam Langley95c29f32014-06-20 12:00:00 -0700117
118 // Rest of these are reserved by the TLS spec
119)
120
121// Hash functions for TLS 1.2 (See RFC 5246, section A.4.1)
122const (
123 hashSHA1 uint8 = 2
124 hashSHA256 uint8 = 4
125)
126
127// Signature algorithms for TLS 1.2 (See RFC 5246, section A.4.1)
128const (
129 signatureRSA uint8 = 1
130 signatureECDSA uint8 = 3
131)
132
133// signatureAndHash mirrors the TLS 1.2, SignatureAndHashAlgorithm struct. See
134// RFC 5246, section A.4.1.
135type signatureAndHash struct {
136 hash, signature uint8
137}
138
139// supportedSKXSignatureAlgorithms contains the signature and hash algorithms
140// that the code advertises as supported in a TLS 1.2 ClientHello.
141var supportedSKXSignatureAlgorithms = []signatureAndHash{
142 {hashSHA256, signatureRSA},
143 {hashSHA256, signatureECDSA},
144 {hashSHA1, signatureRSA},
145 {hashSHA1, signatureECDSA},
146}
147
148// supportedClientCertSignatureAlgorithms contains the signature and hash
149// algorithms that the code advertises as supported in a TLS 1.2
150// CertificateRequest.
151var supportedClientCertSignatureAlgorithms = []signatureAndHash{
152 {hashSHA256, signatureRSA},
153 {hashSHA256, signatureECDSA},
154}
155
156// ConnectionState records basic TLS details about the connection.
157type ConnectionState struct {
158 Version uint16 // TLS version used by the connection (e.g. VersionTLS12)
159 HandshakeComplete bool // TLS handshake is complete
160 DidResume bool // connection resumes a previous TLS connection
161 CipherSuite uint16 // cipher suite in use (TLS_RSA_WITH_RC4_128_SHA, ...)
162 NegotiatedProtocol string // negotiated next protocol (from Config.NextProtos)
163 NegotiatedProtocolIsMutual bool // negotiated protocol was advertised by server
164 ServerName string // server name requested by client, if any (server side only)
165 PeerCertificates []*x509.Certificate // certificate chain presented by remote peer
166 VerifiedChains [][]*x509.Certificate // verified chains built from PeerCertificates
167}
168
169// ClientAuthType declares the policy the server will follow for
170// TLS Client Authentication.
171type ClientAuthType int
172
173const (
174 NoClientCert ClientAuthType = iota
175 RequestClientCert
176 RequireAnyClientCert
177 VerifyClientCertIfGiven
178 RequireAndVerifyClientCert
179)
180
181// ClientSessionState contains the state needed by clients to resume TLS
182// sessions.
183type ClientSessionState struct {
184 sessionTicket []uint8 // Encrypted ticket used for session resumption with server
185 vers uint16 // SSL/TLS version negotiated for the session
186 cipherSuite uint16 // Ciphersuite negotiated for the session
187 masterSecret []byte // MasterSecret generated by client on a full handshake
188 serverCertificates []*x509.Certificate // Certificate chain presented by the server
189}
190
191// ClientSessionCache is a cache of ClientSessionState objects that can be used
192// by a client to resume a TLS session with a given server. ClientSessionCache
193// implementations should expect to be called concurrently from different
194// goroutines.
195type ClientSessionCache interface {
196 // Get searches for a ClientSessionState associated with the given key.
197 // On return, ok is true if one was found.
198 Get(sessionKey string) (session *ClientSessionState, ok bool)
199
200 // Put adds the ClientSessionState to the cache with the given key.
201 Put(sessionKey string, cs *ClientSessionState)
202}
203
204// A Config structure is used to configure a TLS client or server.
205// After one has been passed to a TLS function it must not be
206// modified. A Config may be reused; the tls package will also not
207// modify it.
208type Config struct {
209 // Rand provides the source of entropy for nonces and RSA blinding.
210 // If Rand is nil, TLS uses the cryptographic random reader in package
211 // crypto/rand.
212 // The Reader must be safe for use by multiple goroutines.
213 Rand io.Reader
214
215 // Time returns the current time as the number of seconds since the epoch.
216 // If Time is nil, TLS uses time.Now.
217 Time func() time.Time
218
219 // Certificates contains one or more certificate chains
220 // to present to the other side of the connection.
221 // Server configurations must include at least one certificate.
222 Certificates []Certificate
223
224 // NameToCertificate maps from a certificate name to an element of
225 // Certificates. Note that a certificate name can be of the form
226 // '*.example.com' and so doesn't have to be a domain name as such.
227 // See Config.BuildNameToCertificate
228 // The nil value causes the first element of Certificates to be used
229 // for all connections.
230 NameToCertificate map[string]*Certificate
231
232 // RootCAs defines the set of root certificate authorities
233 // that clients use when verifying server certificates.
234 // If RootCAs is nil, TLS uses the host's root CA set.
235 RootCAs *x509.CertPool
236
237 // NextProtos is a list of supported, application level protocols.
238 NextProtos []string
239
240 // ServerName is used to verify the hostname on the returned
241 // certificates unless InsecureSkipVerify is given. It is also included
242 // in the client's handshake to support virtual hosting.
243 ServerName string
244
245 // ClientAuth determines the server's policy for
246 // TLS Client Authentication. The default is NoClientCert.
247 ClientAuth ClientAuthType
248
249 // ClientCAs defines the set of root certificate authorities
250 // that servers use if required to verify a client certificate
251 // by the policy in ClientAuth.
252 ClientCAs *x509.CertPool
253
David Benjamin7b030512014-07-08 17:30:11 -0400254 // ClientCertificateTypes defines the set of allowed client certificate
255 // types. The default is CertTypeRSASign and CertTypeECDSASign.
256 ClientCertificateTypes []byte
257
Adam Langley95c29f32014-06-20 12:00:00 -0700258 // InsecureSkipVerify controls whether a client verifies the
259 // server's certificate chain and host name.
260 // If InsecureSkipVerify is true, TLS accepts any certificate
261 // presented by the server and any host name in that certificate.
262 // In this mode, TLS is susceptible to man-in-the-middle attacks.
263 // This should be used only for testing.
264 InsecureSkipVerify bool
265
266 // CipherSuites is a list of supported cipher suites. If CipherSuites
267 // is nil, TLS uses a list of suites supported by the implementation.
268 CipherSuites []uint16
269
270 // PreferServerCipherSuites controls whether the server selects the
271 // client's most preferred ciphersuite, or the server's most preferred
272 // ciphersuite. If true then the server's preference, as expressed in
273 // the order of elements in CipherSuites, is used.
274 PreferServerCipherSuites bool
275
276 // SessionTicketsDisabled may be set to true to disable session ticket
277 // (resumption) support.
278 SessionTicketsDisabled bool
279
280 // SessionTicketKey is used by TLS servers to provide session
281 // resumption. See RFC 5077. If zero, it will be filled with
282 // random data before the first server handshake.
283 //
284 // If multiple servers are terminating connections for the same host
285 // they should all have the same SessionTicketKey. If the
286 // SessionTicketKey leaks, previously recorded and future TLS
287 // connections using that key are compromised.
288 SessionTicketKey [32]byte
289
290 // SessionCache is a cache of ClientSessionState entries for TLS session
291 // resumption.
292 ClientSessionCache ClientSessionCache
293
294 // MinVersion contains the minimum SSL/TLS version that is acceptable.
295 // If zero, then SSLv3 is taken as the minimum.
296 MinVersion uint16
297
298 // MaxVersion contains the maximum SSL/TLS version that is acceptable.
299 // If zero, then the maximum version supported by this package is used,
300 // which is currently TLS 1.2.
301 MaxVersion uint16
302
303 // CurvePreferences contains the elliptic curves that will be used in
304 // an ECDHE handshake, in preference order. If empty, the default will
305 // be used.
306 CurvePreferences []CurveID
307
308 // Bugs specifies optional misbehaviour to be used for testing other
309 // implementations.
310 Bugs ProtocolBugs
311
312 serverInitOnce sync.Once // guards calling (*Config).serverInit
313}
314
315type BadValue int
316
317const (
318 BadValueNone BadValue = iota
319 BadValueNegative
320 BadValueZero
321 BadValueLimit
322 BadValueLarge
323 NumBadValues
324)
325
326type ProtocolBugs struct {
327 // InvalidSKXSignature specifies that the signature in a
328 // ServerKeyExchange message should be invalid.
329 InvalidSKXSignature bool
330
331 // InvalidSKXCurve causes the curve ID in the ServerKeyExchange message
332 // to be wrong.
333 InvalidSKXCurve bool
334
335 // BadECDSAR controls ways in which the 'r' value of an ECDSA signature
336 // can be invalid.
337 BadECDSAR BadValue
338 BadECDSAS BadValue
Adam Langley80842bd2014-06-20 12:00:00 -0700339
340 // MaxPadding causes CBC records to have the maximum possible padding.
341 MaxPadding bool
342 // PaddingFirstByteBad causes the first byte of the padding to be
343 // incorrect.
344 PaddingFirstByteBad bool
345 // PaddingFirstByteBadIf255 causes the first byte of padding to be
346 // incorrect if there's a maximum amount of padding (i.e. 255 bytes).
347 PaddingFirstByteBadIf255 bool
Adam Langleyac61fa32014-06-23 12:03:11 -0700348
349 // FailIfNotFallbackSCSV causes a server handshake to fail if the
350 // client doesn't send the fallback SCSV value.
351 FailIfNotFallbackSCSV bool
David Benjamin35a7a442014-07-05 00:23:20 -0400352
353 // DuplicateExtension causes an extra empty extension of bogus type to
354 // be emitted in either the ClientHello or the ServerHello.
355 DuplicateExtension bool
David Benjamin1c375dd2014-07-12 00:48:23 -0400356
357 // UnauthenticatedECDH causes the server to pretend ECDHE_RSA
358 // and ECDHE_ECDSA cipher suites are actually ECDH_anon. No
359 // Certificate message is sent and no signature is added to
360 // ServerKeyExchange.
361 UnauthenticatedECDH bool
David Benjamin9c651c92014-07-12 13:27:45 -0400362
363 // SkipServerKeyExchange causes the server to skip sending
364 // ServerKeyExchange messages.
365 SkipServerKeyExchange bool
David Benjamina0e52232014-07-19 17:39:58 -0400366
367 // SkipChangeCipherSpec causes the implementation to skip
368 // sending the ChangeCipherSpec message (and adjusting cipher
369 // state accordingly for the Finished message).
370 SkipChangeCipherSpec bool
David Benjaminf3ec83d2014-07-21 22:42:34 -0400371
372 // EarlyChangeCipherSpec causes the client to send an early
373 // ChangeCipherSpec message before the ClientKeyExchange. A value of
374 // zero disables this behavior. One and two configure variants for 0.9.8
375 // and 1.0.1 modes, respectively.
376 EarlyChangeCipherSpec int
David Benjamind23f4122014-07-23 15:09:48 -0400377
David Benjamin86271ee2014-07-21 16:14:03 -0400378 // FragmentAcrossChangeCipherSpec causes the implementation to fragment
379 // the Finished (or NextProto) message around the ChangeCipherSpec
380 // messages.
381 FragmentAcrossChangeCipherSpec bool
382
David Benjamind23f4122014-07-23 15:09:48 -0400383 // SkipNewSessionTicket causes the server to skip sending the
384 // NewSessionTicket message despite promising to in ServerHello.
385 SkipNewSessionTicket bool
David Benjamind86c7672014-08-02 04:07:12 -0400386
387 // SendV2ClientHello causes the client to send a V2ClientHello
388 // instead of a normal ClientHello.
389 SendV2ClientHello bool
David Benjaminbef270a2014-08-02 04:22:02 -0400390
391 // SendFallbackSCSV causes the client to include
392 // TLS_FALLBACK_SCSV in the ClientHello.
393 SendFallbackSCSV bool
David Benjamin43ec06f2014-08-05 02:28:57 -0400394
395 // MaxHandshakeRecordLength, if non-zero, is the maximum size of a
David Benjamin98214542014-08-07 18:02:39 -0400396 // handshake record. Handshake messages will be split into multiple
397 // records at the specified size, except that the client_version will
398 // never be fragmented.
David Benjamin43ec06f2014-08-05 02:28:57 -0400399 MaxHandshakeRecordLength int
David Benjamina8e3e0e2014-08-06 22:11:10 -0400400
David Benjamin98214542014-08-07 18:02:39 -0400401 // FragmentClientVersion will allow MaxHandshakeRecordLength to apply to
402 // the first 6 bytes of the ClientHello.
403 FragmentClientVersion bool
404
David Benjamina8e3e0e2014-08-06 22:11:10 -0400405 // RsaClientKeyExchangeVersion, if non-zero, causes the client to send a
406 // ClientKeyExchange with the specified version rather than the
407 // client_version when performing the RSA key exchange.
408 RsaClientKeyExchangeVersion uint16
David Benjaminbed9aae2014-08-07 19:13:38 -0400409
410 // RenewTicketOnResume causes the server to renew the session ticket and
411 // send a NewSessionTicket message during an abbreviated handshake.
412 RenewTicketOnResume bool
David Benjamin98e882e2014-08-08 13:24:34 -0400413
414 // SendClientVersion, if non-zero, causes the client to send a different
415 // TLS version in the ClientHello than the maximum supported version.
416 SendClientVersion uint16
Adam Langley95c29f32014-06-20 12:00:00 -0700417}
418
419func (c *Config) serverInit() {
420 if c.SessionTicketsDisabled {
421 return
422 }
423
424 // If the key has already been set then we have nothing to do.
425 for _, b := range c.SessionTicketKey {
426 if b != 0 {
427 return
428 }
429 }
430
431 if _, err := io.ReadFull(c.rand(), c.SessionTicketKey[:]); err != nil {
432 c.SessionTicketsDisabled = true
433 }
434}
435
436func (c *Config) rand() io.Reader {
437 r := c.Rand
438 if r == nil {
439 return rand.Reader
440 }
441 return r
442}
443
444func (c *Config) time() time.Time {
445 t := c.Time
446 if t == nil {
447 t = time.Now
448 }
449 return t()
450}
451
452func (c *Config) cipherSuites() []uint16 {
453 s := c.CipherSuites
454 if s == nil {
455 s = defaultCipherSuites()
456 }
457 return s
458}
459
460func (c *Config) minVersion() uint16 {
461 if c == nil || c.MinVersion == 0 {
462 return minVersion
463 }
464 return c.MinVersion
465}
466
467func (c *Config) maxVersion() uint16 {
468 if c == nil || c.MaxVersion == 0 {
469 return maxVersion
470 }
471 return c.MaxVersion
472}
473
474var defaultCurvePreferences = []CurveID{CurveP256, CurveP384, CurveP521}
475
476func (c *Config) curvePreferences() []CurveID {
477 if c == nil || len(c.CurvePreferences) == 0 {
478 return defaultCurvePreferences
479 }
480 return c.CurvePreferences
481}
482
483// mutualVersion returns the protocol version to use given the advertised
484// version of the peer.
485func (c *Config) mutualVersion(vers uint16) (uint16, bool) {
486 minVersion := c.minVersion()
487 maxVersion := c.maxVersion()
488
489 if vers < minVersion {
490 return 0, false
491 }
492 if vers > maxVersion {
493 vers = maxVersion
494 }
495 return vers, true
496}
497
498// getCertificateForName returns the best certificate for the given name,
499// defaulting to the first element of c.Certificates if there are no good
500// options.
501func (c *Config) getCertificateForName(name string) *Certificate {
502 if len(c.Certificates) == 1 || c.NameToCertificate == nil {
503 // There's only one choice, so no point doing any work.
504 return &c.Certificates[0]
505 }
506
507 name = strings.ToLower(name)
508 for len(name) > 0 && name[len(name)-1] == '.' {
509 name = name[:len(name)-1]
510 }
511
512 if cert, ok := c.NameToCertificate[name]; ok {
513 return cert
514 }
515
516 // try replacing labels in the name with wildcards until we get a
517 // match.
518 labels := strings.Split(name, ".")
519 for i := range labels {
520 labels[i] = "*"
521 candidate := strings.Join(labels, ".")
522 if cert, ok := c.NameToCertificate[candidate]; ok {
523 return cert
524 }
525 }
526
527 // If nothing matches, return the first certificate.
528 return &c.Certificates[0]
529}
530
531// BuildNameToCertificate parses c.Certificates and builds c.NameToCertificate
532// from the CommonName and SubjectAlternateName fields of each of the leaf
533// certificates.
534func (c *Config) BuildNameToCertificate() {
535 c.NameToCertificate = make(map[string]*Certificate)
536 for i := range c.Certificates {
537 cert := &c.Certificates[i]
538 x509Cert, err := x509.ParseCertificate(cert.Certificate[0])
539 if err != nil {
540 continue
541 }
542 if len(x509Cert.Subject.CommonName) > 0 {
543 c.NameToCertificate[x509Cert.Subject.CommonName] = cert
544 }
545 for _, san := range x509Cert.DNSNames {
546 c.NameToCertificate[san] = cert
547 }
548 }
549}
550
551// A Certificate is a chain of one or more certificates, leaf first.
552type Certificate struct {
553 Certificate [][]byte
554 PrivateKey crypto.PrivateKey // supported types: *rsa.PrivateKey, *ecdsa.PrivateKey
555 // OCSPStaple contains an optional OCSP response which will be served
556 // to clients that request it.
557 OCSPStaple []byte
558 // Leaf is the parsed form of the leaf certificate, which may be
559 // initialized using x509.ParseCertificate to reduce per-handshake
560 // processing for TLS clients doing client authentication. If nil, the
561 // leaf certificate will be parsed as needed.
562 Leaf *x509.Certificate
563}
564
565// A TLS record.
566type record struct {
567 contentType recordType
568 major, minor uint8
569 payload []byte
570}
571
572type handshakeMessage interface {
573 marshal() []byte
574 unmarshal([]byte) bool
575}
576
577// lruSessionCache is a ClientSessionCache implementation that uses an LRU
578// caching strategy.
579type lruSessionCache struct {
580 sync.Mutex
581
582 m map[string]*list.Element
583 q *list.List
584 capacity int
585}
586
587type lruSessionCacheEntry struct {
588 sessionKey string
589 state *ClientSessionState
590}
591
592// NewLRUClientSessionCache returns a ClientSessionCache with the given
593// capacity that uses an LRU strategy. If capacity is < 1, a default capacity
594// is used instead.
595func NewLRUClientSessionCache(capacity int) ClientSessionCache {
596 const defaultSessionCacheCapacity = 64
597
598 if capacity < 1 {
599 capacity = defaultSessionCacheCapacity
600 }
601 return &lruSessionCache{
602 m: make(map[string]*list.Element),
603 q: list.New(),
604 capacity: capacity,
605 }
606}
607
608// Put adds the provided (sessionKey, cs) pair to the cache.
609func (c *lruSessionCache) Put(sessionKey string, cs *ClientSessionState) {
610 c.Lock()
611 defer c.Unlock()
612
613 if elem, ok := c.m[sessionKey]; ok {
614 entry := elem.Value.(*lruSessionCacheEntry)
615 entry.state = cs
616 c.q.MoveToFront(elem)
617 return
618 }
619
620 if c.q.Len() < c.capacity {
621 entry := &lruSessionCacheEntry{sessionKey, cs}
622 c.m[sessionKey] = c.q.PushFront(entry)
623 return
624 }
625
626 elem := c.q.Back()
627 entry := elem.Value.(*lruSessionCacheEntry)
628 delete(c.m, entry.sessionKey)
629 entry.sessionKey = sessionKey
630 entry.state = cs
631 c.q.MoveToFront(elem)
632 c.m[sessionKey] = elem
633}
634
635// Get returns the ClientSessionState value associated with a given key. It
636// returns (nil, false) if no value is found.
637func (c *lruSessionCache) Get(sessionKey string) (*ClientSessionState, bool) {
638 c.Lock()
639 defer c.Unlock()
640
641 if elem, ok := c.m[sessionKey]; ok {
642 c.q.MoveToFront(elem)
643 return elem.Value.(*lruSessionCacheEntry).state, true
644 }
645 return nil, false
646}
647
648// TODO(jsing): Make these available to both crypto/x509 and crypto/tls.
649type dsaSignature struct {
650 R, S *big.Int
651}
652
653type ecdsaSignature dsaSignature
654
655var emptyConfig Config
656
657func defaultConfig() *Config {
658 return &emptyConfig
659}
660
661var (
662 once sync.Once
663 varDefaultCipherSuites []uint16
664)
665
666func defaultCipherSuites() []uint16 {
667 once.Do(initDefaultCipherSuites)
668 return varDefaultCipherSuites
669}
670
671func initDefaultCipherSuites() {
672 varDefaultCipherSuites = make([]uint16, len(cipherSuites))
673 for i, suite := range cipherSuites {
674 varDefaultCipherSuites[i] = suite.id
675 }
676}
677
678func unexpectedMessageError(wanted, got interface{}) error {
679 return fmt.Errorf("tls: received unexpected handshake message of type %T when waiting for %T", got, wanted)
680}