-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflow_test.go
232 lines (195 loc) · 8 KB
/
flow_test.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package gotra
import (
"time"
"github.com/coyim/gotrax"
. "gopkg.in/check.v1"
)
func (s *GotraSuite) Test_basicFlow_onlineWithQueryMessage(c *C) {
// TODO: we'll have to add assertions of everything here later
rand := gotrax.FixtureRand()
alice := &conversation{r: rand, state: stateStart{}}
bob := &conversation{r: rand, state: stateStart{}}
cp1 := alice.getValidClientProfile()
cp1.Expiration = time.Date(2028, 11, 5, 13, 46, 00, 13, time.UTC)
cp1.Sig = gotrax.CreateEddsaSignature(cp1.GenerateSignature(alice.getKeypair()))
cp2 := bob.getValidClientProfile()
cp2.Expiration = time.Date(2028, 12, 5, 13, 46, 00, 13, time.UTC)
cp2.Sig = gotrax.CreateEddsaSignature(cp1.GenerateSignature(bob.getKeypair()))
c.Assert(alice.state, FitsTypeOf, stateStart{})
c.Assert(bob.state, FitsTypeOf, stateStart{})
aliceQuery := alice.QueryMessage()
c.Assert(aliceQuery, Not(IsNil))
bobPlain1, bobIdentity, bobErr1 := bob.Receive(aliceQuery)
c.Assert(bobPlain1, IsNil)
c.Assert(bobErr1, IsNil)
c.Assert(bobIdentity, HasLen, 1)
c.Assert(msgDecode(bobIdentity[0]), DeepEquals, []byte{
// version
0x0, 0x4,
// message type
0x35,
// sender (bob) instance tag
0x1, 0x2, 0x3, 0x4,
// receiver (alice) instance tag
0x0, 0x0, 0x0, 0x0,
// client profile
// number of fields
0x0, 0x0, 0x0, 0x4,
// instance tag
0x0, 0x1,
0x1, 0x2, 0x3, 0x4,
// public key
0x0, 0x2,
0x0, 0x10,
0x32, 0x20, 0x3f, 0xb5, 0x6e, 0x4, 0xc9, 0x64,
0x86, 0x5b, 0xa5, 0x80, 0xac, 0x9d, 0x53, 0xef,
0x21, 0x6, 0x27, 0xda, 0xc3, 0x9f, 0xb5, 0xe,
0xe7, 0x97, 0x2e, 0xc5, 0x4b, 0xd5, 0x1e, 0x75,
0x5b, 0x60, 0x3f, 0x9d, 0x67, 0xb6, 0xf4, 0x16,
0xca, 0x9a, 0xc5, 0xde, 0x4e, 0x61, 0x14, 0xbd,
0xdf, 0x61, 0xf5, 0x34, 0x93, 0x49, 0x9f, 0x79,
0x80,
// versions
0x0, 0x4,
0x0, 0x0, 0x0, 0x1,
0x4,
// expiry
0x0, 0x5,
0x0, 0x0, 0x0, 0x0, 0x6e, 0xd7, 0xce, 0x18,
// signature
0x5f, 0x8b, 0x29, 0x76, 0xa5, 0x2d, 0x42, 0xd3,
0x01, 0x16, 0xf9, 0x62, 0x82, 0xfe, 0xc5, 0xae,
0x26, 0xe7, 0x7a, 0x7f, 0xa5, 0x63, 0xb5, 0x71,
0x52, 0x69, 0x83, 0x95, 0x86, 0xf2, 0xab, 0xf4,
0xb8, 0x74, 0x94, 0xa0, 0x22, 0x04, 0x9a, 0x7c,
0xcc, 0x7a, 0x67, 0xbb, 0x97, 0x7c, 0x5d, 0x55,
0x87, 0x36, 0x3f, 0x37, 0x1b, 0x79, 0x82, 0xf9,
0x00, 0x11, 0xa4, 0x75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0x1e, 0x12, 0x0e,
0x03, 0x56, 0xda, 0x20, 0x34, 0xc0, 0xfb, 0x0d,
0x8c, 0x43, 0xec, 0xe0, 0x60, 0x1b, 0xc9, 0x9e,
0x1e, 0xe5, 0xa0, 0xa0, 0x8e, 0xa5, 0xe0, 0x5c,
0xcd, 0xd7, 0xb0, 0xe9, 0x9c, 0x5e, 0xbc, 0x90,
0x2a, 0x40, 0x4c, 0x75, 0x9a, 0xc7, 0x6d, 0xe4,
0x8, 0x90, 0x7c, 0x64, 0xb2, 0xb6, 0x21, 0x81,
0x5f, 0x87, 0x58, 0xf1, 0x4b, 0x1, 0xc6, 0xb7,
0x6d, 0x30, 0x4, 0x19, 0xf6, 0x6e, 0x84, 0xd2,
0xeb, 0x3f, 0x4d, 0xa3, 0x70, 0x9e, 0xf9, 0x23,
0xa6, 0x30, 0x7f, 0x7b, 0xc5, 0xea, 0x25, 0x3e,
0xd8, 0xdc, 0x7, 0x40, 0x82, 0xf2, 0x44, 0xb4,
0x69, 0xa8, 0x13, 0xcf, 0xa4, 0x3a, 0xc9, 0x9b,
0x7c, 0xe8, 0xb8, 0xc, 0x1f, 0xb1, 0x7a, 0xe5,
0xa1, 0x1c, 0xa, 0x59, 0xd3, 0xe3, 0xa0, 0xb,
0xdc, 0x90, 0xf3, 0xde, 0x1d, 0x37, 0x3, 0x39,
0x1d, 0xce, 0x43, 0xd1, 0x94, 0x59, 0xb, 0xa8,
})
c.Assert(bob.state, FitsTypeOf, stateWaitingAuthR{})
// TODO: continue here, check internals of bob conversation
alicePlain1, aliceAuthR, aliceErr1 := alice.Receive(bobIdentity[0])
c.Assert(alicePlain1, IsNil)
c.Assert(aliceErr1, IsNil)
c.Assert(aliceAuthR, HasLen, 1)
c.Assert(alice.state, FitsTypeOf, stateWaitingAuthI{})
bobPlain2, bobAuthI, bobErr2 := bob.Receive(aliceAuthR[0])
c.Assert(bobPlain2, IsNil)
c.Assert(bobErr2, IsNil)
c.Assert(bobAuthI, HasLen, 1)
c.Assert(bob.state, FitsTypeOf, stateWaitingDakeDataMessage{})
alicePlain2, aliceDakeData, aliceErr2 := alice.Receive(bobAuthI[0])
c.Assert(alicePlain2, IsNil)
c.Assert(aliceErr2, IsNil)
c.Assert(aliceDakeData, HasLen, 1)
c.Assert(alice.state, FitsTypeOf, stateEncrypted{})
bobPlain3, bobToSend1, bobErr3 := bob.Receive(aliceDakeData[0])
c.Assert(bobPlain3, HasLen, 0)
c.Assert(bobErr3, IsNil)
c.Assert(bobToSend1, HasLen, 0)
c.Assert(bob.state, FitsTypeOf, stateEncrypted{})
// We are now ready to do stuff
aliceToSend1, aliceErr3 := alice.Send(MessagePlaintext("hello there, Bob - how's life?"))
c.Assert(aliceErr3, IsNil)
c.Assert(aliceToSend1, HasLen, 1)
aliceToSend2, aliceErr4 := alice.Send(MessagePlaintext("wanted to say something"))
c.Assert(aliceErr4, IsNil)
c.Assert(aliceToSend2, HasLen, 1)
bobPlain4, bobToSend2, bobErr4 := bob.Receive(aliceToSend1[0])
c.Assert(bobPlain4, DeepEquals, MessagePlaintext("hello there, Bob - how's life?"))
c.Assert(bobErr4, IsNil)
c.Assert(bobToSend2, HasLen, 0)
bobPlain5, bobToSend3, bobErr5 := bob.Receive(aliceToSend2[0])
c.Assert(bobPlain5, DeepEquals, MessagePlaintext("wanted to say something"))
c.Assert(bobErr5, IsNil)
c.Assert(bobToSend3, HasLen, 0)
bobToSend4, bobErr4 := bob.Send(MessagePlaintext("oh yeah, what's that?"))
c.Assert(bobErr4, IsNil)
c.Assert(bobToSend4, HasLen, 1)
alicePlain3, aliceToSend3, aliceErr5 := alice.Receive(bobToSend4[0])
c.Assert(alicePlain3, DeepEquals, MessagePlaintext("oh yeah, what's that?"))
c.Assert(aliceErr5, IsNil)
c.Assert(aliceToSend3, HasLen, 0)
aliceToSend4, aliceErr6 := alice.Send(MessagePlaintext("I wanted to say hello"))
c.Assert(aliceErr6, IsNil)
c.Assert(aliceToSend4, HasLen, 1)
aliceToSend5, aliceErr7 := alice.End()
c.Assert(aliceErr7, IsNil)
c.Assert(aliceToSend5, HasLen, 1)
c.Assert(alice.state, FitsTypeOf, stateStart{})
bobPlain6, bobToSend5, bobErr6 := bob.Receive(aliceToSend4[0])
c.Assert(bobPlain6, DeepEquals, MessagePlaintext("I wanted to say hello"))
c.Assert(bobErr6, IsNil)
c.Assert(bobToSend5, HasLen, 0)
bobPlain7, bobToSend6, bobErr7 := bob.Receive(aliceToSend5[0])
c.Assert(bobPlain7, HasLen, 0)
c.Assert(bobErr7, IsNil)
c.Assert(bobToSend6, HasLen, 0)
c.Assert(bob.state, FitsTypeOf, stateFinished{})
}