-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnoxV3.sapic
More file actions
457 lines (349 loc) · 16.4 KB
/
KnoxV3.sapic
File metadata and controls
457 lines (349 loc) · 16.4 KB
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
/*******************************************************************************
Remote attestation Framework
Protocol : Knox Attestation V2
Status : Working
* Processes
AppCode : an honest app's logic
HonestAppInstallation : Allows installation of an honest app
ArbitraryAppCode : An arbitrary app's logic
ArbitraryAppInstallation : Allows installation of an arbitrary app
Device : A mobile device process, it sets up a secure world and allows installing apps.
AttestationAgent : A trusted attestation agent installed in a secure world to create a measurement report.
AtServer : An attestation server that verifies measurement reports.
DevServer : The developer server of the honest apps.
RelayAttacker1 : An attacker process to retrieve a nonce from the developer server via a secure channel
RelayAttacker2 : An attacker process to send the `hid` to the developer server via a secure channel
* Channels
SecureWorld_Ch_In : A secure channel from an app to a trusted agent to send app information
SecureWorld_Ch_Out : A secure channel from a trusted agent to an app that sends the `hid`.
Nonce_TLS_Ch : A secure channel from the developer server to send a nonce.
HID_TLS_Ch: A secure channel from a client (an attacker or an app) to the developer server that sends the `hid`.
HID_TLS_Ch_Out : A secure channel from the `AttestationAgent` to the attestation server that sends the `blob`.
HID_TLS_Ch_In : A secure channel from the attestation server to the `AttestationAgent` that sends the `hid`.
*******************************************************************************/
theory Framework_KnoxV3
begin
builtins: signing, asymmetric-encryption, locations-report
heuristic: S
functions:
equal/2, and/2
predicates:
Report(x,y) <=> not (fst(y)= 'loc')
equations:
equal(x,x)=true,
and(true,true)= true
/***************************************** Generic *****************************************/
let AppCode =
[Nonce_TLS_Ch(devId,nonce)]--[]-> [];
event NonceReceivedAtApp(nonce);
//attestation_agent send app data to secure world to start an attestation
new ~sessionID;
[]--[]-> [SecureWorld_Ch_In(~sessionID,~deviceId,swId,nonce,'App1PackageName','App1Content',sign(<'App1PackageName','App1Content',pk(advk)>,advk))];
[ SecureWorld_Ch_Out(~sessionID,hid) ]--[]-> [];
[]--[]-> [HID_TLS_Ch(hid)];
event Checked('HonestAppFinished');
0
let HonestAppInstallation =
event Checked('HonestAppInstallation');
//install an application
[!App_Published(devId,<'App1PackageName','App1Content',pk(advk),
sign( <'App1PackageName','App1Content',pk(advk)>, advk)>)]--[]-> [];
event Application_Installed(~deviceId,'App1PackageName',sign(<'App1PackageName','App1Content',pk(advk)>, advk));
!AppCode //App code separate from installation
let ArbitraryAppCode =
in(nonce);
event NonceReceivedAtArbApp(nonce);
//attestation_agent send app data to secure world to start an attestation
new ~sessionID;
[]--[]-> [SecureWorld_Ch_In(~sessionID,~deviceId,swId,nonce,packagename,~content,appSignature)];
[ SecureWorld_Ch_Out(~sessionID,hid) ]--[]-> [];
out(hid);
event Checked('ArbitraryAppFinished');
0
let ArbitraryAppInstallation =
event Checked('ArbitraryAppInstallation');
//install an application
in(<packagename, devKey>); //Attacker can pick the app name and the dev key.
new ~content; //contents are different from any honest app, so we model as a free name
let appSignature = sign(<packagename,~content,pk(devKey)>, devKey) in
let app = <packagename,~content,pk(devKey),appSignature> in
out(app);
event Arbitrary_App_Created(packagename,appSignature);
event Application_Installed(~deviceId,packagename,appSignature);
!ArbitraryAppCode
let Device =
//Create device reference
new ~deviceId;
//send the device reference , allows an adversary to tamper the device
out(~deviceId);
//setup a secureWorld
[]--[]-> [SetUPSW(~deviceId)];
[FinishSetUPSW(~deviceId,swId)]--[]->[];
event Checked('SettingUpDeviceFinished');
(!HonestAppInstallation | !ArbitraryAppInstallation)
let RelayAttacker1 =
[Nonce_TLS_Ch(devId,nonce)]--[]-> [];
out(nonce);
0
let RelayAttacker2 =
in(hid);
[]--[]-> [HID_TLS_Ch(hid)];
0
/***************************************** Knox V3 *****************************************/
let AtServerKV3 =
!(
//Retrive blob
[HID_TLS_Ch_Out(tsid,<atId,nonce,hardwareMeasurement,packagename,appSignature,report,reportSignature>)]--[]-> [];
//refernce blob to an hid
new ~hid;
//Send hid for the TZ
[]--[]-> [HID_TLS_Ch_In(tsid,~hid)];
//Retrive hid from the developer server and verfiy it
[Attestation_Server_Ch_In(sid,~hid)]--[]-> [];
//checking the blob location
let locationCheck = equal(<atId,nonce,hardwareMeasurement,packagename,appSignature> , check_rep(report,<'loc',pk(~skAT)>)) in
//checking the signature of the blob
let signatureCheck = equal(verify(reportSignature, report,pk(~skAT)), true) in
//check if both true
let result = and(locationCheck, signatureCheck) in
//create a verdict and send it to the developer server
if result = true then
//create a verdict and send it to the developer server
let verdict = 'valid' in
[]--[]-> [Attestation_Server_Ch_Out(sid,<verdict,atId,nonce,hardwareMeasurement,packagename,appSignature>)];
event Checked('AttestationServerFinished_valid');
0
else
//create a verdict and send it to the developer server
let verdict = 'invalid' in
[]--[]-> [Attestation_Server_Ch_Out(sid,<verdict,atId,nonce,hardwareMeasurement,packagename,appSignature>)];
event Checked('AttestationServerFinished_invalid');
0
)
let KnoxV3TA =
(
new ~swId; // We have different secure world and device ID, because it's possible to make different devices have the same ID, therefore
//setup a SecureWorld
[SetUPSW(deviceId)]--[]->[FinishSetUPSW(deviceId,~swId)];
//attempt to unlock bootloader
in(attempt);
!(
//attestation_agent send app data to secure world, start an attestation
[SecureWorld_Ch_In(sessionID, deviceId,~swId,nonce,packagename,content,appSignature)]--[]->[];
new ~tsid; // attestation server hid session id
new ~atId; // attestation id
event Attestating_App(~atId,packagename,appSignature,deviceId);
if attempt = 'unlockBootloader' then
let hardwareMeasurement = 'invalid' in
// Software measurment not used in Knox
//in(customSoftwareMeasurement);
//let softwareMeasurement = customSoftwareMeasurement in
in(<fnonce,fpackagename,fappSignature>); // adversary's custom softeware-based values
let report = report(<~atId,fnonce,hardwareMeasurement,fpackagename,fappSignature>) in
let blob = <~atId, fnonce, hardwareMeasurement,fpackagename,fappSignature, report,sign(report,~skAT)> in ///send attestation report to the attestation server
[]--[]-> [HID_TLS_Ch_Out(~tsid,blob)];
[HID_TLS_Ch_In(~tsid,hid)]--[]-> [];
event BlobCreated(hid);
out(hid);
///return attestation report to the app
event DeviceStatus(~atId,deviceId,hardwareMeasurement);
event Attestating_App_Device(~atId,deviceId,packagename,appSignature,hardwareMeasurement);
[]--[]->[ SecureWorld_Ch_Out(sessionID,hid) ];
event Checked('SecureWorldAppFinished_rooted_device');
0
else
let hardwareMeasurement = 'valid' in
let report = report(<~atId,nonce,hardwareMeasurement,packagename,appSignature>) in
let blob = <~atId,nonce,hardwareMeasurement,packagename,appSignature,report,sign(report,~skAT)> in ///send attestation report to the attestation server
[]--[]-> [HID_TLS_Ch_Out(~tsid,blob)];
[HID_TLS_Ch_In(~tsid,hid)]--[]-> [];
///return attestation report to the app
event DeviceStatus(~atId,deviceId,hardwareMeasurement);
event Attestating_App_Device(~atId,deviceId,packagename,appSignature,hardwareMeasurement);
event BlobCreated(hid);
[]--[]->[ SecureWorld_Ch_Out(sessionID,hid) ];
event Checked('SecureWorldAppFinished_locked_device');
0
)
)@<'loc',pk(~skAT)>
let DevServerProtocolCode =
// create a nonce
new ~nonce;
event NonceGenerated(~nonce);
new ~requestID;
event BlobRequested(~requestID);
[]--[]-> [Nonce_TLS_Ch(~devId,~nonce)];
//retrive hid from clients
[HID_TLS_Ch(hid)]--[]->[];
//create developer-attestation server session id, to keep track or pair of request-response message
new ~sid;
//send blob to the attestation server
[]--[]-> [Attestation_Server_Ch_In(~sid,hid)];
//retrieve the verfied report the attestation server, pattern matching is used for checking the status
[Attestation_Server_Ch_Out(~sid,<verdict,atId,~nonce,hardwareMeasurement,fpackagename,fappSignature>)]--[]-> [];
event NonceReceived(~nonce);
//checking app information
let appSignatureCheck = equal(appSignature, fappSignature) in
let packagenameCheck = equal(packagename, fpackagename) in
let result = and(appSignatureCheck, packagenameCheck) in
//attestation finished
if result = true then
event Verdict_app(atId,hid,verdict,hardwareMeasurement,'valid');
event Checked('DeveloperServerfinished_valid');
if verdict = 'valid' then
event BlobAccepted(hid);
event RequestedBlobAccepted(~requestID,hid)
else
0
else
event Verdict_app(atId,hid,verdict,hardwareMeasurement,'invalid');
event Checked('DeveloperServerfinished_invalid')
let DevServerKV3 =
//creating and publishing the application
new ~advk; // Dev server signing
new ~devId;
let packagename = 'App1PackageName' in
let appSignature = sign(<packagename,'App1Content',pk(~advk)>,~advk) in
let app = <packagename,'App1Content',pk(~advk),appSignature> in
out(app);
event App_Created(packagename,appSignature);
[]--[]-> [!App_Published(~devId,app)];
!DevServerProtocolCode
/*************************************** Generic code *************************************************/
// Main process starts here
/***************************************** choose a platform ***************************************************
* platform | SafetyNet | KnoxV2 | KnoxV3 | Key Attestation
* --------------------------------------------------------------------------------------------------------------
* AttestationAgent : GooglePlay | SafetyNetTA | KnoxV2TA | KnoxV3TA | KeyMasterTA
* AtServer : AtServerSN | AtServerKV2 | AtServerKV3 | AtServerKA
* DevServer : DevServerSN | DevServerKV2 | DevServerKV3 | DevServerKA
***************************************************************************************************************/
let AttestationAgent =
KnoxV3TA
let AtServer =
AtServerKV3
let DevServer =
DevServerKV3
//create pair attestation keys to be used by secureWorld for signing, and attestation server for verification
new ~skAT;
(!Device || !DevServer || AtServer || !AttestationAgent || !RelayAttacker1 || !RelayAttacker2)
//for all valid verdict => honest apps must created, installed, attested in a valid device and KU does know its attestation report
lemma DeviceAndAppIntegrity:
"(All atId hid #i. Verdict_app(atId,hid,'valid','valid','valid') @ i ==>
(
(Ex deviceId packagename appSignature #a #b #c.
App_Created(packagename,appSignature) @ a
& Application_Installed(deviceId,packagename,appSignature) @ b
& Attestating_App_Device(atId,deviceId,packagename,appSignature,'valid')@ c
& a < b & b < c & c < i
)
))"
//for all valid verdict => Ku should not know its attestation report by any mean
lemma AttestationReportSecrecy:
"(All atId hid #i. Verdict_app(atId,hid,'valid','valid','valid') @ i ==>
( not( Ex #k. KU(hid) @ k & k<i ) )
)"
// Check if nonce are unique
// lemma UniqueNonce:
// "All n #i #j. NonceReceived(n) @i & NonceReceived(n) @j ==> #i=#j"
// Check if accepted blobs are unique
lemma UniqueBlob:
"All n #i #j. BlobAccepted(n) @i & BlobAccepted(n) @j ==> #i=#j"
// Check if the blob generated recently
lemma BlobRecentness:
"All requestID blob #i. RequestedBlobAccepted(requestID,blob) @i ==>
Ex #j. BlobRequested(requestID)@j & Ex #k. BlobCreated (blob)@k & #j < #k & #k < #i"
//for all failed application integrity check only => (device must be valid and there an app created, an app attested and either the hash is different or packagename).
lemma RepackedAppIntegrity:
"(All atId hid #i. Verdict_app(atId,hid,'valid','valid','invalid') @ i ==>
(
(Ex deviceId #j. DeviceStatus(atId,deviceId,'valid') @ j & j < i)
& (Ex deviceId packagename fpackagename appSignature fappSignature #j #k.
App_Created(packagename,appSignature) @ j
& Attestating_App(atId,fpackagename,fappSignature,deviceId)@ k
& (
(not(appSignature = fappSignature))
| (not(packagename = fpackagename))
)
)
))"
//Sanity check: Will the dev server ever accept a blob
lemma Correctness_AcceptBlob:
exists-trace
"Ex n #i. BlobAccepted(n)@i"
//Sanity check: Attestation finished with valid device integirty and application integirty.
lemma Correctness_Valid_Attestation:
exists-trace
"Ex atId blob #i. Verdict_app(atId,blob,'valid','valid','valid') @ i"
//Sanity check: Attestation finished with at least failed device integirty
lemma Correctness_Rooting_Device:
exists-trace
"Ex atId blob any #i. Verdict_app(atId,blob,'valid','invalid',any) @ i"
//Sanity check: Setting up a device's secure world
lemma Correctness_Setting_Up_Device:
exists-trace
"Ex #i. Checked('SettingUpDeviceFinished') @ i"
//Sanity check: Creation of an honest application
lemma Correctness_Honest_App:
exists-trace
"Ex #i. Checked('HonestAppInstallation') @ i"
//Sanity check: Creation of an arbitrary application
lemma Correctness_Arbitrary_App:
exists-trace
"Ex #i. Checked('ArbitraryAppInstallation') @ i"
//Sanity check: An honest application can finish
lemma Correctness_Honest_App_Finished:
exists-trace
"Ex #i. Checked('HonestAppFinished') @ i"
//Sanity check: An arbitrary application can finish
lemma Correctness_Arbitrary_App_Finished:
exists-trace
"Ex #i. Checked('ArbitraryAppFinished') @ i"
//Sanity check: Secure world app can finish in a rooted device
lemma Correctness_Secure_World_Finished_ROOTED:
exists-trace
"Ex #i. Checked('SecureWorldAppFinished_rooted_device') @ i"
//Sanity check: Secure world app can finish in a locked device
lemma Correctness_Secure_World_Finished_LOCKED:
exists-trace
"Ex #i. Checked('SecureWorldAppFinished_locked_device') @ i"
//Sanity check: Attestation Server can finish with a verfied report
lemma Correctness_Attestation_Server_Finished_VALID:
exists-trace
"Ex #i. Checked('AttestationServerFinished_valid') @ i"
//Sanity check: Attestation Server can finish with an invalid report
lemma Correctness_Attestation_Server_Finished_INVALID:
exists-trace
"Ex #i. Checked('AttestationServerFinished_invalid') @ i"
//Sanity check: Developer server can finish with report from an honest app
lemma Correctness_Developer_Server_Finished_VALID:
exists-trace
"Ex #i. Checked('DeveloperServerfinished_valid') @ i"
//Sanity check: Developer server can finish with report from an arbitrary app
lemma Correctness_Developer_Server_Finished_INVALID:
exists-trace
"Ex #i. Checked('DeveloperServerfinished_invalid') @ i"
end
==============================================================================
summary of summaries:
analyzed: KnoxV3.sapic
DeviceAndAppIntegrity (all-traces): verified (5 steps)
AttestationReportSecrecy (all-traces): verified (5 steps)
UniqueBlob (all-traces): verified (24 steps)
BlobRecentness (all-traces): verified (14 steps)
RepackedAppIntegrity (all-traces): verified (8 steps)
Correctness_AcceptBlob (exists-trace): verified (3 steps)
Correctness_Valid_Attestation (exists-trace): verified (4 steps)
Correctness_Rooting_Device (exists-trace): verified (6 steps)
Correctness_Setting_Up_Device (exists-trace): verified (4 steps)
Correctness_Honest_App (exists-trace): verified (4 steps)
Correctness_Arbitrary_App (exists-trace): verified (4 steps)
Correctness_Honest_App_Finished (exists-trace): verified (4 steps)
Correctness_Arbitrary_App_Finished (exists-trace): verified (4 steps)
Correctness_Secure_World_Finished_ROOTED (exists-trace): verified (4 steps)
Correctness_Secure_World_Finished_LOCKED (exists-trace): verified (4 steps)
Correctness_Attestation_Server_Finished_VALID (exists-trace): verified (4 steps)
Correctness_Attestation_Server_Finished_INVALID (exists-trace): falsified - no trace found (3 steps) //<<-- because the valid ones stored by the attestation server and the advasery cannot craft hid that has invalid measurement.
Correctness_Developer_Server_Finished_VALID (exists-trace): verified (4 steps)
Correctness_Developer_Server_Finished_INVALID (exists-trace): verified (6 steps)
==============================================================================