-
Notifications
You must be signed in to change notification settings - Fork 14
/
debug.go
171 lines (137 loc) · 3.71 KB
/
debug.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package otr3
import (
"bufio"
"fmt"
"io"
"os"
)
const debugString = "?OTR!"
const debugPrefix = "[DEBUG] "
var standardErrorOutput io.Writer = os.Stderr
// SetDebug sets the debug mode for this conversation.
// If debug mode is enabled, calls to Send with a message equals to "?OTR!"
// will dump debug information about the current conversation state to stderr
func (c *Conversation) SetDebug(d bool) {
c.debug = d
}
func (c *Conversation) otrOffer() string {
switch c.whitespaceState {
case whitespaceNotSent:
return "NOT"
case whitespaceSent:
if c.msgState == encrypted {
return "ACCEPTED"
}
return "SENT"
case whitespaceRejected:
return "REJECTED"
default:
return "INVALID"
}
}
func (c *Conversation) dump(w *bufio.Writer) {
_, _ = w.WriteString("Context:\n\n")
_, _ = w.WriteString(fmt.Sprintf(" Our instance: %08X\n", c.ourInstanceTag))
_, _ = w.WriteString(fmt.Sprintf(" Their instance: %08X\n\n", c.theirInstanceTag))
_, _ = w.WriteString(fmt.Sprintf(" Msgstate: %d (%s)\n\n", c.msgState, c.msgState.identityString()))
_, _ = w.WriteString(fmt.Sprintf(" Protocol version: %d\n", c.version.protocolVersion()))
_, _ = w.WriteString(fmt.Sprintf(" OTR offer: %s\n\n", c.otrOffer()))
if c.ake == nil {
_, _ = w.WriteString(" Auth info: NULL\n")
} else {
c.dumpAKE(w)
}
_, _ = w.WriteString("\n")
c.dumpSMP(w)
_ = w.Flush()
}
// Will only be called if AKE is valid
func (c *Conversation) dumpAKE(w *bufio.Writer) {
_, _ = w.WriteString(" Auth info:\n")
if c.ake != nil {
_, _ = w.WriteString(fmt.Sprintf(" State: %d (%s)\n", c.ake.state.identity(), c.ake.state.identityString()))
}
_, _ = w.WriteString(fmt.Sprintf(" Our keyid: %d\n", c.keys.ourKeyID))
_, _ = w.WriteString(fmt.Sprintf(" Their keyid: %d\n", c.keys.theirKeyID))
_, _ = w.WriteString(fmt.Sprintf(" Their fingerprint: %X\n", c.theirKey.Fingerprint()))
_, _ = w.WriteString(fmt.Sprintf(" Proto version = %d\n", c.version.protocolVersion()))
_ = w.Flush()
}
func (c *Conversation) dumpSMP(w *bufio.Writer) {
_, _ = w.WriteString(" SM state:\n")
if c.smp.state != nil {
_, _ = w.WriteString(fmt.Sprintf(" Next expected: %d (%s)\n", c.smp.state.identity(), c.smp.state.identityString()))
}
receivedQ := 0
if c.smp.question != nil {
receivedQ = 1
}
_, _ = w.WriteString(fmt.Sprintf(" Received_Q: %d\n", receivedQ))
_ = w.Flush()
}
func (smpStateExpect1) identity() int {
return 0
}
func (smpStateExpect2) identity() int {
return 2
}
func (smpStateExpect3) identity() int {
return 3
}
func (smpStateExpect4) identity() int {
return 4
}
func (smpStateWaitingForSecret) identity() int {
return 1
}
func (smpStateExpect1) identityString() string {
return "EXPECT1"
}
func (smpStateExpect2) identityString() string {
return "EXPECT2"
}
func (smpStateExpect3) identityString() string {
return "EXPECT3"
}
func (smpStateExpect4) identityString() string {
return "EXPECT4"
}
func (smpStateWaitingForSecret) identityString() string {
return "EXPECT1_WQ"
}
func (authStateNone) identity() int {
return 0
}
func (authStateAwaitingDHKey) identity() int {
return 1
}
func (authStateAwaitingRevealSig) identity() int {
return 2
}
func (authStateAwaitingSig) identity() int {
return 3
}
func (authStateNone) identityString() string {
return "NONE"
}
func (authStateAwaitingDHKey) identityString() string {
return "AWAITING_DHKEY"
}
func (authStateAwaitingRevealSig) identityString() string {
return "AWAITING_REVEALSIG"
}
func (authStateAwaitingSig) identityString() string {
return "AWAITING_SIG"
}
func (m msgState) identityString() string {
switch m {
case plainText:
return "PLAINTEXT"
case encrypted:
return "ENCRYPTED"
case finished:
return "FINISHED"
default:
return "INVALID"
}
}