-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUAF.pvl
594 lines (550 loc) · 21.6 KB
/
UAF.pvl
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
(**************************************************************************************)
set displayDerivation = false.
(*set reconstructTrace = false.*)
(*set verboseRules = none.*)
set verboseClauses = none.
(********************************************************************)
(* Messages Type declaration *)
(********************************************************************)
type msg.
type Atype.
type Ltype.
type Scene.
type Uname.
type Appid.
type Facetid.
type Callerid.
type SData.
type Chlg.
type Fchlg.
type Tr.
type Token.
type AAID.
type CNTR.
type Nonce.
type KeyID.
(********************************************************************)
(* Symmetric encryption *)
(********************************************************************)
type key.
type Senc_alg.
const WeakSenc:Senc_alg[private].
fun senc(bitstring,key):KeyID.
reduc forall m: bitstring, k:key; sdec(senc(m,k),k) = m.
fun senc_msg(msg,key):msg.
reduc forall m: msg, k:key; sdec_msg(senc_msg(m,k),k) = m.
(********************************************************************)
(* Signature function *)
(********************************************************************)
type spkey.
type sskey.
fun spk(sskey):spkey.
fun sign(bitstring, sskey): bitstring.
reduc forall m: bitstring, ssk: sskey; checksign(sign(m,ssk),spk(ssk)) = m.
reduc forall m: bitstring, ssk: sskey; getmess(sign(m,ssk)) = m.
(********************************************************************)
(* Hash Functions. *)
(********************************************************************)
fun hash(bitstring): bitstring.
fun hash_a(Appid):bitstring.
fun hash_tr(Tr): Tr.
(********************************************************************)
(* Final Challenge Params function to compute a FCP params *)
(********************************************************************)
fun FCParams(Appid,Facetid,Chlg,bitstring):bitstring[data].
(********************************************************************)
(* Get TLSDATA from channel *)
(********************************************************************)
fun GetTLSdata(channel):bitstring.
(********************************************************************)
(* Increasing counter value *)
(********************************************************************)
fun Incr(CNTR):CNTR.
reduc forall cntr:CNTR; ReIncr(Incr(cntr)) = cntr.
(********************************************************************)
(* Get KHAccess token from a random ASMtoken *)
(********************************************************************)
fun To_12b_token(Appid,bitstring,Callerid):Token.
fun To_12r_token(Appid):Token.
fun f1(Token,Appid):Token.
(********************************************************************)
(* Get final challenge hash from the random hash value of the final challenge *)
(********************************************************************)
fun ToFc(bitstring):Fchlg.
(********************************************************************)
(* table for database *)
(********************************************************************)
table AppList(Appid,Facetid).
table AuthAppList(Appid,Facetid).
table ASMDB(Appid,KeyID,KeyID).
table TrustCallerid(Callerid).
table AutrDB(Appid,KeyID,KeyID).
(********************************************************************)
(* channel declarations *)
(********************************************************************)
free c:channel.
(********************************************************************)
(* const declarations *)
(********************************************************************)
const autr_1b:Atype.
const autr_2b:Atype.
const autr_1r:Atype.
const autr_2r:Atype.
const empty:Ltype.
const stepup:Ltype.
const software:Scene.
const hardware:Scene.
const debug:bitstring[private].
const reg_cntr:CNTR[private].
const auth_cntr:CNTR[private].
(********************************************************************)
(* Event *)
(********************************************************************)
event RP_success_reg(Uname,Appid,AAID,KeyID).
event UA_init_reg(Uname,Appid).
event Autr_verify_reg(Uname,Appid,AAID,KeyID).
(********************************************************************)
(* Registration message format *)
(********************************************************************)
fun InputUandP(Uname, bitstring):msg[data].
fun RegRPreq(Uname,Appid,SData,Chlg):msg[data].
fun RegRPresp(SData,AAID,Fchlg,KeyID,CNTR,spkey,spkey,bitstring,bitstring):msg[data].
fun RegCUreq(Uname,Appid,SData,Chlg,bitstring):msg[data].
fun RegCUresp(SData,AAID,Fchlg,KeyID,CNTR,spkey,spkey,bitstring,bitstring):msg[data].
fun RegMCreq(Uname,Appid,bitstring):msg[data].
fun RegMCresp(AAID,Fchlg,KeyID,CNTR,spkey,spkey,bitstring):msg[data].
fun RegAMreq(Uname,Appid,Token,Fchlg):msg[data].
fun RegAMresp_12b(AAID,Fchlg,KeyID,CNTR,spkey,spkey,KeyID,bitstring):msg[data].
fun RegAMresp_12r(AAID,Fchlg,KeyID,CNTR,spkey,spkey,bitstring):msg[data].
(********************************************************************)
(* FIDO Server *)
(* 1. RegServer to registration *)
(* 2. AuthServer to authentication *)
(********************************************************************)
let RegRP(https:channel, uname:Uname, appid:Appid, password:bitstring) =
(
in(https,up:msg);
let InputUandP(=uname, =password) = up in
new sdata:SData;
new chlg:Chlg;
let tlsdata = GetTLSdata(https) in
out(https, RegRPreq(uname,appid,sdata,chlg));
in(https,m:msg);
let RegRPresp(xsdata,aaid,fc,kid,cntr,pkAT,pkAU,fcp,s) = m in
let FCParams(=appid,facetid,=chlg,=tlsdata) = fcp in
get AppList(=appid,=facetid) in
if xsdata = sdata && fc = ToFc(hash(fcp)) then
if (aaid,fc,kid,cntr,pkAU) = checksign(s,pkAT) then
(
event RP_success_reg(uname,appid,aaid,kid);
out(c,debug)
)
).
(********************************************************************)
(* User Agent *)
(* 1. only represent a honest user agent *)
(* 2. it can visit a fake website *)
(********************************************************************)
let RegUA(https:channel,UC:channel,uname:Uname,appid:Appid,password:bitstring) =
(
event UA_init_reg(uname,appid);
out(https,InputUandP(uname,password));
in(https, m:msg);
let RegRPreq(xuname,appid2,sdata,chlg) = m in
(
let tlsdata = GetTLSdata(https) in
out(UC,RegCUreq(xuname,appid2,sdata,chlg,tlsdata));
in(UC, mm:msg);
let RegCUresp(xsdata,aaid,fc,kid,cntr,pkAT,pkAU,fcp,s) = mm in
out(https,RegRPresp(xsdata,aaid,fc,kid,cntr,pkAT,pkAU,fcp,s))
)
).
(********************************************************************)
(* FIDO Client *)
(* 1. FIDO UAF client *)
(********************************************************************)
let RegUC(CU:channel,CM:channel,facetid:Facetid) =
(
in(CU,m:msg);
let RegCUreq(uname,appid,sdata,chlg,tlsdata) = m in
get AppList(=appid, =facetid) in
let fcp = FCParams(appid,facetid,chlg,tlsdata) in
out(CM,RegMCreq(uname,appid,fcp));
in(CM,mm:msg);
let RegMCresp(aaid,fc,kid,cntr,pkAT,pkAU,s) = mm in
out(CU,RegCUresp(sdata,aaid,fc,kid,cntr,pkAT,pkAU,fcp,s))
).
(********************************************************************)
(* ASM *)
(********************************************************************)
let RegASM(MC:channel, MA:channel, token:bitstring, callerid:Callerid, atype:Atype) =
(
in(MC, m:msg);
let RegMCreq(uname,appid,fcp) = m in
let fc = ToFc(hash(fcp)) in
if atype = autr_1b || atype = autr_2b then
(
(* bound authenticator send keyhandle and store it into the ASM *)
let ak = To_12b_token(appid,token,callerid) in
let testak = ak in
out(MA,RegAMreq(uname,appid,ak,fc));
in(MA,mm:msg);
let RegAMresp_12b(aaid,fc2,kid,cntr,pkAT,pkAU,kh,s) = mm in
out(MC,RegMCresp(aaid,fc2,kid,cntr,pkAT,pkAU,s))
)
else
(
let ak = To_12r_token(appid) in
let testak = ak in
(* roaming authenticators don't send the keyhandle *)
out(MA,RegAMreq(uname,appid,ak,fc));
in(MA,mm:msg);
let RegAMresp_12r(aaid,fc2,kid,cntr,pkAT,pkAU,s) = mm in
out(MC,RegMCresp(aaid,fc2,kid,cntr,pkAT,pkAU,s))
)
).
(********************************************************************)
(* Authenticator *)
(* 1. RegServer to registration *)
(* 2. AuthServer to authentication *)
(* Both of them use the same channel *)
(********************************************************************)
let RegAutr(AM:channel,aaid:AAID,skAT:sskey,wrapkey:key,atype:Atype) =
(
in(AM,m:msg);
let RegAMreq(uname,appid,ak,fc) = m in
new skAU:sskey;
new cntr:CNTR;
let testskAU = skAU in
let testcntr = cntr in
let pkAT = spk(skAT) in
let pkAU = spk(skAU) in
if atype = autr_1b then
(
new kid:KeyID;
let testkid = kid in
let kh = senc((skAU,ak,uname,kid),wrapkey) in
let s = sign((aaid,fc,kid,cntr,pkAU),skAT) in
event Autr_verify_reg(uname,appid,aaid,kid);
out(AM,RegAMresp_12b(aaid,fc,kid,cntr,pkAT,pkAU,kh,s))
)
else if atype = autr_2b then
(
new kid:KeyID;
let testkid = kid in
let kh = senc((skAU,ak,kid),wrapkey) in
let s = sign((aaid,fc,kid,cntr,pkAU),skAT) in
event Autr_verify_reg(uname,appid,aaid,kid);
out(AM,RegAMresp_12b(aaid,fc,kid,cntr,pkAT,pkAU,kh,s))
)
else if atype = autr_1r then
(
new kid:KeyID;
let testkid = kid in
let kh = senc((skAU,ak,uname,kid),wrapkey) in
let s = sign((aaid,fc,kid,cntr,pkAU),skAT) in
event Autr_verify_reg(uname,appid,aaid,kid);
out(AM,RegAMresp_12r(aaid,fc,kid,cntr,pkAT,pkAU,s))
)
else if atype = autr_2r then
(
let kh = senc((skAU,ak),wrapkey) in
let kid = kh in
let testkid = kid in
let s = sign((aaid,fc,kid,cntr,pkAU),skAT) in
event Autr_verify_reg(uname,appid,aaid,kid);
out(AM,RegAMresp_12r(aaid,fc,kid,cntr,pkAT,pkAU,s))
)
).
(**************************message format 2*******************************)
fun AuthRPreq_em(Appid,SData,Chlg):msg[data].
fun AuthRPresp_em(SData,AAID,Nonce,Fchlg,KeyID,CNTR,bitstring,bitstring):msg[data].
fun AuthRPreq_st(Appid,KeyID,SData,Chlg,Tr):msg[data].
fun AuthRPresp_st(SData,AAID,Nonce,Fchlg,Tr,KeyID,CNTR,bitstring,bitstring):msg[data].
fun AuthCUreq_em(Appid,SData,Chlg,bitstring):msg[data].
fun AuthCUresp_em(SData,AAID,Nonce,Fchlg,KeyID,CNTR,bitstring,bitstring):msg[data].
fun AuthCUreq_st(Appid,KeyID,SData,Chlg,Tr,bitstring):msg[data].
fun AuthCUresp_st(SData,AAID,Nonce,Fchlg,Tr,KeyID,CNTR,bitstring,bitstring):msg[data].
fun AuthCMreq_em(Appid,bitstring):msg[data].
fun AuthCMresp_em(AAID,Nonce,Fchlg,KeyID,CNTR,bitstring):msg[data].
fun AuthCMreq_st(Appid,bitstring,KeyID,Tr):msg[data].
fun AuthCMresp_st(AAID,Nonce,Fchlg,Tr,KeyID,CNTR,bitstring):msg[data].
fun AuthAMreq_1bem(Token,Fchlg,Appid,KeyID):msg[data].
fun AuthAMreq_1bst(Token,Fchlg,Appid,KeyID,Tr):msg[data].
fun AuthAMreq_2bst(Token,Fchlg,Appid,KeyID,Tr):msg[data].
fun AuthAMreq_1rem(Token,Fchlg,Appid):msg[data].
fun AuthAMreq_1rst(Token,Fchlg,Appid,KeyID,Tr):msg[data].
fun AuthAMreq_2rst(Token,Fchlg,Appid,KeyID,Tr):msg[data].
fun AuthAMresp_em(AAID,Nonce,Fchlg,KeyID,CNTR,bitstring):msg[data].
fun AuthAMresp_st(AAID,Nonce,Fchlg,Tr,KeyID,CNTR,bitstring):msg[data].
(********************************************************************)
(* Event *)
(********************************************************************)
event RP_success_auth(Uname,Appid,AAID,KeyID).
event RP_success_tr(Tr).
event UA_launch_auth(Uname,Appid).
event UA_launch_auth_tr(Tr).
event Autr_verify_auth_1br(Uname,Appid,AAID,KeyID).
event Autr_verify_auth_2br(Appid,AAID,KeyID).
event Autr_verify_tr(Tr).
(********************************************************************)
(**************************main process*******************************)
(********************************************************************)
let AuthRP(https:channel,uname:Uname,appid:Appid,aaid:AAID,kid:KeyID,pkAU:spkey,cntr:CNTR,tr:Tr,ltype:Ltype) =
(
new sdata:SData;
new chlg:Chlg;
let tlsdata = GetTLSdata(https) in
if ltype = empty then
(
out(https,AuthRPreq_em(appid,sdata,chlg));
in(https,m:msg);
let AuthRPresp_em(=sdata,=aaid,nonce,fc,=kid,xcntr,fcp,s) = m in
let FCParams(=appid,facetid,=chlg,=tlsdata) = fcp in
get AuthAppList(=appid,=facetid) in
if fc = ToFc(hash(fcp)) then
if (aaid,nonce,fc,kid,xcntr) = checksign(s,pkAU) then
if xcntr = cntr then
event RP_success_auth(uname,appid,aaid,kid);
out(c,debug)
)
else
(
out(https,AuthRPreq_st(appid,kid,sdata,chlg,tr));
in(https,m:msg);
let AuthRPresp_st(=sdata,=aaid,nonce,fc,htr,=kid,xcntr,fcp,s) = m in
let FCParams(=appid,facetid,=chlg,=tlsdata) = fcp in
get AuthAppList(=appid,=facetid) in
if fc = ToFc(hash(fcp)) then
if htr = hash_tr(tr) then
if (aaid,nonce,fc,htr,kid,xcntr) = checksign(s,pkAU) then
if xcntr = cntr then
event RP_success_auth(uname,appid,aaid,kid);
event RP_success_tr(tr);
out(c,debug)
)
).
let AuthUA(https:channel,UC:channel,uname:Uname,ltype:Ltype) =
(
in(https,m:msg);
if ltype = empty then
(
let AuthRPreq_em(appid,sdata,chlg) = m in
event UA_launch_auth(uname,appid);
let tlsdata = GetTLSdata(https) in
out(UC,AuthCUreq_em(appid,sdata,chlg,tlsdata));
in(UC,mm:msg);
let AuthCUresp_em(xsdata,aaid,nonce,fc,kid,xcntr,fcp,s) = mm in
out(https,AuthRPresp_em(xsdata,aaid,nonce,fc,kid,xcntr,fcp,s))
)
else
(
let AuthRPreq_st(appid,kid,sdata,chlg,tr2) = m in
event UA_launch_auth(uname,appid);
event UA_launch_auth_tr(tr2);
let tlsdata = GetTLSdata(https) in
out(UC,AuthCUreq_st(appid,kid,sdata,chlg,tr2,tlsdata));
in(UC,mm:msg);
let AuthCUresp_st(xsdata,aaid,nonce,fc,htr,xkid,xcntr,fcp,s) = mm in
out(https,AuthRPresp_st(xsdata,aaid,nonce,fc,htr,xkid,xcntr,fcp,s))
)
).
let AuthUC(CU:channel,CM:channel,facetid:Facetid,ltype:Ltype) =
(
in(CU,m:msg);
if ltype = empty then
(
let AuthCUreq_em(appid,sdata,chlg,tlsdata) = m in
get AuthAppList(=appid,=facetid) in
let fcp = FCParams(appid,facetid,chlg,tlsdata) in
out(CM,AuthCMreq_em(appid,fcp));
in(CM,mm:msg);
let AuthCMresp_em(aaid,nonce,fc,kid,xcntr,s) = mm in
out(CU,AuthCUresp_em(sdata,aaid,nonce,fc,kid,xcntr,fcp,s))
)
else
(
let AuthCUreq_st(appid,kid,sdata,chlg,tr,tlsdata) = m in
get AuthAppList(=appid,=facetid) in
let fcp = FCParams(appid,facetid,chlg,tlsdata) in
out(CM,AuthCMreq_st(appid,fcp,kid,tr));
in(CM,mm:msg);
let AuthCMresp_st(aaid,nonce,fc,htr,xkid,xcntr,s) = mm in
out(CU,AuthCUresp_st(sdata,aaid,nonce,fc,htr,xkid,xcntr,fcp,s))
)
).
let AuthASM(MC:channel,MA:channel,token:bitstring,callerid:Callerid,atype:Atype,ltype:Ltype) =
(
in(MC,m:msg);
if atype = autr_1b && ltype = empty then
(
let AuthCMreq_em(appid,fcp) = m in
get ASMDB(=appid,kid,kh) in
get TrustCallerid(=callerid) in
let fc = ToFc(hash(fcp)) in
let ak = To_12b_token(appid,token,callerid) in
let testak = ak in
out(MA,AuthAMreq_1bem(ak,fc,appid,kh));
in(MA,mm:msg);
let AuthAMresp_em(aaid,nonce,xfc,xkid,xcntr,s) = mm in
out(MC,AuthCMresp_em(aaid,nonce,xfc,xkid,xcntr,s))
)
else if atype = autr_1b && ltype = stepup then
(
let AuthCMreq_st(appid,fcp,kid,tr) = m in
get ASMDB(appid2,=kid,kh) in
get TrustCallerid(=callerid) in
let fc = ToFc(hash(fcp)) in
let ak = To_12b_token(appid,token,callerid) in
let testak = ak in
out(MA,AuthAMreq_1bst(ak,fc,appid,kh,tr));
in(MA,mm:msg);
let AuthAMresp_st(aaid,nonce,xfc,htr,xkid,xcntr,s) = mm in
out(MC,AuthCMresp_st(aaid,nonce,xfc,htr,xkid,xcntr,s))
)
else if atype = autr_2b then
(
let AuthCMreq_st(appid,fcp,kid,tr) = m in
get ASMDB(=appid,=kid,kh) in
get TrustCallerid(=callerid) in
let fc = ToFc(hash(fcp)) in
let ak = To_12b_token(appid,token,callerid) in
let testak = ak in
out(MA,AuthAMreq_2bst(ak,fc,appid,kh,tr));
in(MA,mm:msg);
let AuthAMresp_st(aaid,nonce,xfc,htr,xkid,xcntr,s) = mm in
out(MC,AuthCMresp_st(aaid,nonce,xfc,htr,xkid,xcntr,s))
)
else if atype = autr_1r && ltype = empty then
(
let AuthCMreq_em(appid,fcp) = m in
let fc = ToFc(hash(fcp)) in
let ak = To_12r_token(appid) in
let testak = ak in
out(MA,AuthAMreq_1rem(ak,fc,appid));
in(MA,mm:msg);
let AuthAMresp_em(aaid,nonce,xfc,kid,xcntr,s) = mm in
out(MC,AuthCMresp_em(aaid,nonce,xfc,kid,xcntr,s))
)
else if atype = autr_1r && ltype = stepup then
(
let AuthCMreq_st(appid,fcp,kid,tr) = m in
let fc = ToFc(hash(fcp)) in
let ak = To_12r_token(appid) in
let testak = ak in
out(MA,AuthAMreq_1rst(ak,fc,appid,kid,tr));
in(MA,mm:msg);
let AuthAMresp_st(aaid,nonce,xfc,htr,xkid,xcntr,s) = mm in
out(MC,AuthCMresp_st(aaid,nonce,xfc,htr,xkid,xcntr,s))
)
else
(
let AuthCMreq_st(appid,fcp,kid,tr) = m in
let fc = ToFc(hash(fcp)) in
let ak = To_12r_token(appid) in
let testak = ak in
out(MA,AuthAMreq_2rst(ak,fc,appid,kid,tr));
in(MA,mm:msg);
let AuthAMresp_st(aaid,nonce,xfc,htr,xkid,xcntr,s) = mm in
out(MC,AuthCMresp_st(aaid,nonce,xfc,htr,xkid,xcntr,s))
)
).
let AuthAutr(AM:channel,aaid:AAID,wrapkey:key,cntr:CNTR,tr:Tr,atype:Atype,ltype:Ltype) =
(
let testcntr = cntr in
in(AM,m:msg);
if atype = autr_1b && ltype = empty then
(
let AuthAMreq_1bem(ak,fc,appid,kh) = m in
let (skAU:sskey,aka:Token,uname:Uname,kid:KeyID) = sdec(kh,wrapkey) in
if f1(ak,appid) = aka then
let pkAU = spk(skAU) in
new nonce:Nonce;
let s = sign((aaid,nonce,fc,kid,cntr),skAU) in
event Autr_verify_auth_1br(uname,appid,aaid,kid);
out(AM,AuthAMresp_em(aaid,nonce,fc,kid,cntr,s))
)
else if atype = autr_1b && ltype = stepup then
(
let AuthAMreq_1bst(ak,fc,appid,kh,=tr) = m in
let (skAU:sskey,aka:Token,uname:Uname,kid:KeyID) = sdec(kh,wrapkey) in
if f1(ak,appid) = aka then
let pkAU = spk(skAU) in
let htr = hash_tr(tr) in
new nonce:Nonce;
let s = sign((aaid,nonce,fc,htr,kid,cntr),skAU) in
event Autr_verify_auth_1br(uname,appid,aaid,kid);
event Autr_verify_tr(tr);
out(AM,AuthAMresp_st(aaid,nonce,fc,htr,kid,cntr,s))
)
else if atype = autr_2b then
(
let AuthAMreq_2bst(ak,fc,appid,kh,=tr) = m in
let (skAU:sskey,aka:Token,kid:KeyID) = sdec(kh,wrapkey) in
if f1(ak,appid) = aka then
let pkAU = spk(skAU) in
let htr = hash_tr(tr) in
new nonce:Nonce;
let s = sign((aaid,nonce,fc,htr,kid,cntr),skAU) in
event Autr_verify_auth_2br(appid,aaid,kid);
event Autr_verify_tr(tr);
out(AM,AuthAMresp_st(aaid,nonce,fc,htr,kid,cntr,s))
)
else if atype = autr_1r && ltype = empty then
(
let AuthAMreq_1rem(ak,fc,appid) = m in
get AutrDB(=appid,xkid,kh) in
let (skAU:sskey,aka:Token,uname:Uname,kid:KeyID) = sdec(kh,wrapkey) in
if f1(ak,appid) = aka then
let pkAU = spk(skAU) in
new nonce:Nonce;
let s = sign((aaid,nonce,fc,kid,cntr),skAU) in
event Autr_verify_auth_1br(uname,appid,aaid,kid);
out(AM,AuthAMresp_em(aaid,nonce,fc,kid,cntr,s))
)
else if atype = autr_1r && ltype = stepup then
(
let AuthAMreq_1rst(ak,fc,appid,kid,=tr) = m in
get AutrDB(=appid,=kid,kh) in
let (skAU:sskey,aka:Token,uname:Uname,xkid:KeyID) = sdec(kh,wrapkey) in
if f1(ak,appid) = aka then
let pkAU = spk(skAU) in
let htr = hash_tr(tr) in
new nonce:Nonce;
let s = sign((aaid,nonce,fc,htr,kid,cntr),skAU) in
event Autr_verify_auth_1br(uname,appid,aaid,kid);
event Autr_verify_tr(tr);
out(AM,AuthAMresp_st(aaid,nonce,fc,htr,kid,cntr,s))
)
else
(
let AuthAMreq_2rst(ak,fc,appid,kid,=tr) = m in
let (skAU:sskey,aka:Token) = sdec(kid,wrapkey) in
if f1(ak,appid) = aka then
let pkAU = spk(skAU) in
let htr = hash_tr(tr) in
new nonce:Nonce;
let s = sign((aaid,nonce,fc,htr,kid,cntr),skAU) in
event Autr_verify_auth_2br(appid,aaid,kid);
event Autr_verify_tr(tr);
out(AM,AuthAMresp_st(aaid,nonce,fc,htr,kid,cntr,s))
)
).
letfun get_ak(atype:Atype,appid:Appid,token:bitstring,callerid:Callerid) =
(
if atype = autr_1b || atype = autr_2b then To_12b_token(appid,token,callerid)
else To_12r_token(appid)
).
letfun get_kh(atype:Atype,uname:Uname,appid:Appid,callerid:Callerid,token:bitstring,keyid:KeyID,wrapkey:key,skAU:sskey) =
(
let ak = get_ak(atype,appid,token,callerid) in
let aka = f1(ak,appid) in
if atype = autr_1b || atype = autr_1r then senc((skAU,aka,uname,keyid),wrapkey)
else if atype = autr_2b then senc((skAU,aka,keyid),wrapkey)
else senc((skAU,aka),wrapkey)
).
letfun get_kid(atype:Atype,kh:KeyID,keyid:KeyID) =
(
if atype = autr_2r then kh
else keyid
).