-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtls_state.go
78 lines (62 loc) · 1.93 KB
/
tls_state.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package packemon
import "bytes"
type TLSv12State int
const (
TLSv12_STATE_INIT TLSv12State = iota
TLSv12_STATE_PASSIVE_SERVER_HELLO
TLSv12_STATE_SEND_APPLICATION_DATA
)
type TLSv12Connection struct {
currentState TLSv12State
established bool
TLSClientHello *TLSClientHello
TLSServerHello *TLSServerHello
TLSClientKeyExchange *TLSClientKeyExchange
TLSClientFinished []byte
KeyBlock *KeyBlock
ClientSequence int
Master []byte
}
func NewTLSv12Connection() *TLSv12Connection {
return &TLSv12Connection{
currentState: TLSv12_STATE_INIT,
TLSClientHello: NewTLSClientHello(),
}
}
// TODO: ServerHello 以外も拾っちゃってるからちゃんと判定したい
func (t *TLSv12Connection) IsPassiveServerHello(tcp *TCP) bool {
if t.currentState != TLSv12_STATE_INIT {
return false
}
tlsHandshakeType := []byte{tcp.Data[5]}
tlsContentType := []byte{tcp.Data[0]}
return bytes.Equal(tlsHandshakeType, []byte{0x02}) && bytes.Equal(tlsContentType, []byte{TLS_CONTENT_TYPE_HANDSHAKE})
}
func (t *TLSv12Connection) IsPassiveChangeCipherSpecAndFinished(tcp *TCP) bool {
tlsContentType := []byte{tcp.Data[0]}
return bytes.Equal(tlsContentType, []byte{TLS_CONTENT_TYPE_CHANGE_CIPHER_SPEC})
}
func (t *TLSv12Connection) VerifingData() *ForVerifing {
return &ForVerifing{
Master: t.Master,
ClientHello: t.TLSClientHello,
ServerHello: t.TLSServerHello,
ClientKeyExchange: t.TLSClientKeyExchange.ClientKeyExchange,
ClientFinished: t.TLSClientFinished,
}
}
func (t *TLSv12Connection) SetState(s TLSv12State) {
t.currentState = s
}
func (t *TLSv12Connection) EstablishedConnection() {
t.established = true
}
func (t *TLSv12Connection) IsEstablished() bool {
return t.established
}
func (t *TLSv12Connection) IsSendApplicationData() bool {
return t.currentState == TLSv12_STATE_SEND_APPLICATION_DATA
}
func (t *TLSv12Connection) Close() {
t.established = false
}