-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathhandshake_client.go
52 lines (44 loc) · 1.17 KB
/
handshake_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package dtls
import (
"io"
)
func (c *DTLSConn) clientHandshake() (err error) {
if c.config == nil {
c.config = defaultConfig()
}
// Client Hello
hello := &clientHelloMsg{
vers: c.config.maxVersion(),
random: make([]byte, 32),
compressionMethods: []uint8{compressionNone},
}
possibleCipherSuites := c.config.cipherSuites()
hello.cipherSuites = make([]uint16, 0, len(possibleCipherSuites))
NextCipherSuite:
for _, suiteId := range possibleCipherSuites {
for _, suite := range cipherSuites {
if suite.id != suiteId {
continue
}
// Don't advertise TLS 1.2-only cipher suites unless
// we're attempting TLS 1.2.
if hello.vers < VersionDTLS12 && suite.flags&suiteTLS12 != 0 {
continue
}
hello.cipherSuites = append(hello.cipherSuites, suiteId)
continue NextCipherSuite
}
}
t := uint32(c.config.time().Unix())
hello.random[0] = byte(t >> 24)
hello.random[1] = byte(t >> 16)
hello.random[2] = byte(t >> 8)
hello.random[3] = byte(t)
_, err = io.ReadFull(c.config.rand(), hello.random[4:])
if err != nil {
c.sendAlert(alertInternalError)
return
}
c.writeRecord(recordTypeHandshake, hello.marshal())
return
}