MCPcopy Create free account
hub / github.com/XTLS/Go / makeClientHello

Method makeClientHello

handshake_client.go:37–143  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35}
36
37func (c *Conn) makeClientHello() (*clientHelloMsg, ecdheParameters, error) {
38 config := c.config
39 if len(config.ServerName) == 0 && !config.InsecureSkipVerify {
40 return nil, nil, errors.New("tls: either ServerName or InsecureSkipVerify must be specified in the tls.Config")
41 }
42
43 nextProtosLength := 0
44 for _, proto := range config.NextProtos {
45 if l := len(proto); l == 0 || l > 255 {
46 return nil, nil, errors.New("tls: invalid NextProtos value")
47 } else {
48 nextProtosLength += 1 + l
49 }
50 }
51 if nextProtosLength > 0xffff {
52 return nil, nil, errors.New("tls: NextProtos values too large")
53 }
54
55 supportedVersions := config.supportedVersions(roleClient)
56 if len(supportedVersions) == 0 {
57 return nil, nil, errors.New("tls: no supported versions satisfy MinVersion and MaxVersion")
58 }
59
60 clientHelloVersion := config.maxSupportedVersion(roleClient)
61 // The version at the beginning of the ClientHello was capped at TLS 1.2
62 // for compatibility reasons. The supported_versions extension is used
63 // to negotiate versions now. See RFC 8446, Section 4.2.1.
64 if clientHelloVersion > VersionTLS12 {
65 clientHelloVersion = VersionTLS12
66 }
67
68 hello := &clientHelloMsg{
69 vers: clientHelloVersion,
70 compressionMethods: []uint8{compressionNone},
71 random: make([]byte, 32),
72 sessionId: make([]byte, 32),
73 ocspStapling: true,
74 scts: true,
75 serverName: hostnameInSNI(config.ServerName),
76 supportedCurves: config.curvePreferences(),
77 supportedPoints: []uint8{pointFormatUncompressed},
78 secureRenegotiationSupported: true,
79 alpnProtocols: config.NextProtos,
80 supportedVersions: supportedVersions,
81 }
82
83 if c.handshakes > 0 {
84 hello.secureRenegotiation = c.clientFinished[:]
85 }
86
87 preferenceOrder := cipherSuitesPreferenceOrder
88 if !hasAESGCMHardwareSupport {
89 preferenceOrder = cipherSuitesPreferenceOrderNoAES
90 }
91 configCipherSuites := config.cipherSuites()
92 hello.cipherSuites = make([]uint16, 0, len(configCipherSuites))
93
94 for _, suiteId := range preferenceOrder {

Callers 1

clientHandshakeMethod · 0.95

Calls 11

PublicKeyMethod · 0.95
hostnameInSNIFunction · 0.85
mutualCipherSuiteFunction · 0.85
curveForCurveIDFunction · 0.85
generateECDHEParametersFunction · 0.85
supportedVersionsMethod · 0.80
maxSupportedVersionMethod · 0.80
curvePreferencesMethod · 0.80
cipherSuitesMethod · 0.80
randMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected