forked from tls13tamarin/TLS13Tamarin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_basic.m4i
373 lines (310 loc) · 8.59 KB
/
client_basic.m4i
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
dnl(
/*
Client rules for standard (vanilla) handshake.
From the specification 2. Protocol overview
Client Server
Key ^ ClientHello
Exch | + key_share*
v + pre_shared_key* -------->
ServerHello ^ Key
+ key_share* | Exch
+ pre_shared_key* v
{EncryptedExtensions} ^ Server
{CertificateRequest*} v Params
{Certificate*} ^
{CertificateVerify*} | Auth
{Finished} v
<-------- [Application Data*]
^ {Certificate*}
Auth | {CertificateVerify*}
v {Finished} -------->
*/)
dnl Extensions definitions for basic ClientHello
define(<!ClientHelloExtensions!>, <!<SupportedVersions, NamedGroupList, SignatureSchemeList, KeyShareCH >!>)
rule client_hello:
let
// Initialise state variables to zero.
init_state()
// Abstract client identity - does not currently correspond to
// anything concrete
C = $C
// Server identity - can be interpreted as the hostname
S = $S
// Client nonce
nc = ~nc
// We reuse the client nonce to be a thread identifier
tid = nc
// Group, DH exponent, key share
g1 = $g1
g2 = $g2
sg = <g1, g2>
client_sg = <g1, g2>
g = g1
x = ~x
gx = g^x
messages = <messages, ClientHello>
es = EarlySecret
in
[ Fr(nc),
Fr(x)
]
--[ C0(tid),
Start(tid, C, 'client'),
running_client(Identity, C),
Neq(g1, g2),
DH(tid, C, x),
HonestUse(~x),
HonestUse(gx)
]->
[
State(C1, tid, C, S, ClientState),
DHExp(x, tid, C),
// Write the ClientHelloMsg onto the wire *presumably* with destination S
Out(ClientHello)
]
define(<!HelloRetryRequestExtensions!>, <!<KeyShareHRR>!>)
rule recv_hello_retry_request:
let
g1 = $g1
g2 = $g2
prev_sg = <g1, g2>
prev_g = g1
prev_hrr = '0'
set_state()
hrr = 'hrr'
new_g = g2
g = g2
client_sg = <g1, g2>
C = $C
S = $S
new_x = ~new_x
x = new_x
gx = g^x
// PSK after HRR has its own rule (see recv_hello_retry_request_psk)
psk_ke_mode = 'na'
auth_status = <'0', '0'>
messages = <messages, HelloRetryRequest>
messages = <messages, ClientHello>
es = EarlySecret
in
[ State(C1, tid, C, S, PrevClientState),
Fr(new_x),
In(HelloRetryRequest),
DHExp(prev_x, tid, C)
]
--[ C1_retry(tid),
Neq(g1, g2),
Instance(tid, C, 'client'),
DeleteDH(tid, C, prev_x),
DH(tid, C, x)
]->
[ Out(ClientHello),
DHExp(x, tid, C),
State(C1, tid, C, S, ClientState)
]
dnl Extensions definitions for basic ServerHello
define(<!ServerHelloExtensions!>, <!<SignatureSchemeList, KeyShareSH>!>)
rule recv_server_hello:
let
prev_g = $g
prev_x = ~x
set_state()
ns = new_ns
gy = new_gy
C = $C
S = $S
// equivalent to checking gy in <$g>
gy = g^new_y
// Derive the shared secret
gxy = gy^x
// Received a basic server hello - abandon PSK mode (if attempted)
psk_ke_mode = 'na'
auth_status = <'0', '0'>
messages = <messages, ServerHello>
in
[ State(C1, tid, C, S, PrevClientState),
In(ServerHello)
]
--[ C1(tid),
Instance(tid, C, 'client'),
Neq(gy, g),
Neq(gxy, g),
DHChal(g, x, new_y, gx, gy, gxy),
running_client(Nonces, nc, ns)
]->
[
State(C2a, tid, C, S, ClientState)
]
rule client_gen_keys:
let
set_state()
C = $C
S = $S
hs = HandshakeSecret
ms = MasterSecret
hs_keyc = keygen(handshake_traffic_secret(client), hs_key_label())
hs_keys = keygen(handshake_traffic_secret(server), hs_key_label())
in
[ State(C2a, tid, C, S, PrevClientState),
DHExp(x, tid, C)
]
--[ C2a(tid),
Instance(tid, C, 'client'),
running_client(MS, ms),
running_client(HS, hs),
DeleteDH(tid, C, x)
]->
[
State(C2b, tid, C, S, ClientState)
]
rule recv_encrypted_extensions:
let
set_state()
S = $S
C = $C
messages = <messages, EncryptedExtensions>
in
[ State(C2b, tid, C, S, PrevClientState),
In(senc{EncryptedExtensions}hs_keys)
]
--[ C2b(tid),
Instance(tid, C, 'client')
]->
[ State(C2c, tid, C, S, ClientState)
]
rule recv_certificate_request:
let
prev_psk_ke_mode ='na'
set_state()
S = $S
C = $C
certificate_request_context = '0'
cert_req = '1'
messages = <messages, CertificateRequest>
in
[ State(C2c, tid, C, S, PrevClientState),
In(senc{CertificateRequest}hs_keys)
]
--[ C2c_req(tid),
Instance(tid, C, 'client')
]->
[ State(C2d, tid, C, S, ClientState)
]
rule skip_recv_certificate_request:
let
set_state()
S = $S
C = $C
cert_req = '0'
in
[ State(C2c, tid, C, S, PrevClientState)
]
--[ C2c(tid),
Instance(tid, C, 'client')
]->
[ State(C2d, tid, C, S, ClientState)
]
rule recv_server_auth:
let
prev_psk_ke_mode = 'na'
set_state()
S = $S
C = $C
certificate_request_context = '0'
certificate = pk(~ltkS)
messages = <messages, Certificate>
sig_messages = signature_input(server)
messages = <messages, CertificateVerify>
exp_verify_data = compute_finished(server)
messages = <messages, Finished>
cats = application_traffic_secret_0(client)
sats = application_traffic_secret_0(server)
app_keys = keygen(sats, app_key_label())
ems = exporter_master_secret()
// auth_status = <cas, sas>
auth_status = <'0', 'auth'>
in
[ State(C2d, tid, C, S, PrevClientState),
!Pk(S, pk(~ltkS)),
In(senc{Certificate, CertificateVerify, Finished}hs_keys)
]
--[ C2d(tid),
Instance(tid, C, 'client'),
Eq(psk_ke_mode, 'na'),
Eq(verify(signature, sig_messages, pk(~ltkS)), true),
Eq(verify_data, exp_verify_data),
running_client(Mode, psk_ke_mode),
commit_client(Identity, <S, auth_status>),
commit_client(HS, hs),
commit_client(Transcript, messages),
commit_client(Nonces, nc, ns)
]->
[ State(C3, tid, C, S, ClientState),
RecvStream(tid, C, S, auth_status, app_keys)
]
rule client_auth:
let
// If certificate was requested, cannot ignore
prev_cert_req = '0'
set_state()
S = $S
C = $C
verify_data = compute_finished(client)
messages = <messages, Finished>
rms = resumption_master_secret()
app_keyc = keygen(cats, app_key_label())
app_keys = keygen(sats, app_key_label())
in
[ State(C3, tid, C, S, PrevClientState)
]
--[ C3(tid),
Instance(tid, C, 'client'),
running_client(Transcript, messages),
running_client(HSMS, hs, ms),
running_client(RMS, S, rms, messages),
running_client(Mode, psk_ke_mode),
SessionKey(tid, C, S, auth_status, <app_keyc, app_keys>)
]->
[ State(C4, tid, C, S, ClientState),
Out(senc{Finished}hs_keyc),
SendStream(tid, C, S, auth_status, app_keyc)
]
rule client_auth_cert:
let
prev_cert_req = '1'
prev_psk_ke_mode = 'na'
set_state()
S = $S
C = $C
certificate_request_context = '0'
certificate = pk(~ltkC)
messages = <prev_messages, Certificate>
signature = compute_signature(~ltkC, client)
messages = <messages, CertificateVerify>
verify_data = compute_finished(client)
messages = <messages, Finished>
rms = resumption_master_secret()
// zeroes cert_req after it has been used
cert_req = '0'
app_keyc = keygen(cats, app_key_label())
app_keys = keygen(sats, app_key_label())
auth_status = <'auth', 'auth'>
in
[ State(C3, tid, C, S, PrevClientState),
RecvStream(tid, C, S, prev_auth_status, app_keys),
!Ltk(C, ~ltkC)
]
--[ C3_cert(tid),
Instance(tid, C, 'client'),
UseLtk(~ltkC, signature),
running_client(HSMS, hs, ms),
running_client(Transcript, messages),
running_client(RMS, S, rms, messages),
running_client(Mode, psk_ke_mode),
SessionKey(tid, C, S, auth_status, <app_keyc, app_keys>)
]->
[ State(C4, tid, C, S, ClientState),
Out(senc{Certificate, CertificateVerify, Finished}hs_keyc),
SendStream(tid, C, S, auth_status, app_keyc),
RecvStream(tid, C, S, auth_status, app_keys)
]