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
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
|
------------------------------------------------------------------------
---- Atoms -------------------------------------------------------------
------------------------------------------------------------------------
--
-- # References
--
-- - 7.6 Match evaluation
--
------------------------------------------------------------------------
import Aesop
import Std.Data.List.Basic
inductive MatchResult where
| is_match : MatchResult
| no_match : MatchResult
| indeterminate : MatchResult
deriving BEq, Repr
inductive Decision where
| permit : Decision
| deny : Decision
| indeterminate : Decision
| not_applicable : Decision
deriving BEq, Repr
-- This type is used to implement the semantics described in § 7.10 (Extended
-- Indeterminate). It is only relevant to combining algorithms.
inductive Decision' where
| permit : Decision'
| deny : Decision'
| indeterminate : Decision'
| indeterminate_d : Decision'
| indeterminate_p : Decision'
| indeterminate_dp : Decision'
| not_applicable : Decision'
deriving BEq, Repr
def Decision'.downcast : Decision' → Decision
| Decision'.permit => Decision.permit
| Decision'.deny => Decision.deny
| Decision'.indeterminate => Decision.indeterminate
| Decision'.indeterminate_d => Decision.indeterminate
| Decision'.indeterminate_p => Decision.indeterminate
| Decision'.indeterminate_dp => Decision.indeterminate
| Decision'.not_applicable => Decision.not_applicable
instance : Coe Decision' Decision where
coe := Decision'.downcast
inductive EffectType where
| permit : EffectType
| deny : EffectType
deriving BEq, Repr
namespace EffectType
def to_decision (e : EffectType) : Decision :=
match e with
| EffectType.permit => Decision.permit
| EffectType.deny => Decision.deny
def to_decision' (e : EffectType) : Decision' :=
match e with
| EffectType.permit => Decision'.permit
| EffectType.deny => Decision'.deny
end EffectType
------------------------------------------------------------------------
---- Values ------------------------------------------------------------
------------------------------------------------------------------------
--
-- From A.2 Data-types: "Although XML instances represent all data-types
-- as strings, an XACML PDP must operate on types of data that, while
-- they have string representations, are not just strings. Types such as
-- Boolean, integer, and double MUST be converted from their XML string
-- representations to values that can be compared with values in their
-- domain of discourse, such as numbers."
--
-- The standard enumerates the types that must be supported by any
-- conforming implementaiton. This is represented in `XmlType`, and
-- `Value` is the representation of a value payload with its associated
-- type.
--
------------------------------------------------------------------------
inductive XmlType
| string : XmlType
| boolean : XmlType
| integer : XmlType
| double : XmlType
| time : XmlType
| date : XmlType
| dateTime : XmlType
| anyURI : XmlType
| hexBinary : XmlType
| base64Binary : XmlType
| dayTimeDuration : XmlType
| yearMonthDuration : XmlType
| x500Name : XmlType
| rfc822Name : XmlType
| ipAddress : XmlType
| dnsName : XmlType
deriving BEq, Repr
def Primitive : Type := XmlType × String
deriving BEq, Repr
def Primitive.mk (type : XmlType) (inner : String) : Primitive := (type, inner)
notation:65 "#<" lhs:65 "," rhs:66 ">" => Primitive.mk lhs rhs
instance : Coe Bool Primitive where
coe b :=
match b with
| true => #<XmlType.boolean, "True">
| false => #<XmlType.boolean, "False">
-- Per 7.4 Expression evaluation,
--
-- "XACML defines an evaluation result of "Indeterminate", which is said
-- to be the result of an invalid expression, or an operational error
-- occurring during the evaluation of the expression."
instance : Coe (Option Primitive) Primitive where
coe b :=
match b with
| Option.none => #<XmlType.boolean, "Indeterminate">
| Option.some a => a
structure Bag where
contents: List Primitive
deriving Repr
def Bag.beq (b₁ b₂ : Bag) : Bool :=
b₁.contents.all (fun x => b₂.contents.count x == b₁.contents.count x)
instance : BEq Bag where
beq := Bag.beq
inductive Value where
| primitive (p : Primitive) : Value
| bag (b : Bag) : Value
deriving BEq, Repr
instance : Coe (Option Value) Value where
coe b :=
match b with
| Option.none => Value.primitive (#<XmlType.boolean, "Indeterminate">)
| Option.some a => a
instance : Coe (Option Value) MatchResult where
coe b :=
match b with
| Option.some (Value.primitive (XmlType.boolean, "True")) => MatchResult.is_match
| Option.some (Value.primitive (XmlType.boolean, "False")) => MatchResult.no_match
| _ => MatchResult.indeterminate
------------------------------------------------------------------------
---- Attributes---------------------------------------------------------
------------------------------------------------------------------------
--
-- # References
--
-- - 5.46 Element <Attribute>
-- - 5.42 Element <Request>
--
-- Attributes are categories into <Attributes> elements. In this
-- implementation, categories are rolled up - every attribute carries
-- the category of its enclosing <Attributes> element.
--
------------------------------------------------------------------------
structure Attribute where
category : String
identifier : String
issuer : Option String
value : Primitive
deriving BEq, Repr
-- More than one attribute with a particular (category, identifier, issuer) can
-- exist in a `Request`. Indeed, this is how poly-valued attributes are
-- represented.
def Request : Type := List Attribute
deriving Repr
---
def Identifier : Type := String
deriving BEq, Repr
inductive RuleCombinatorAlgorithm where
| deny_overrides : RuleCombinatorAlgorithm
| ordered_deny_overrides : RuleCombinatorAlgorithm
| permit_overrides : RuleCombinatorAlgorithm
| ordered_permit_overrides : RuleCombinatorAlgorithm
| deny_unless_permit : RuleCombinatorAlgorithm
| permit_unless_deny : RuleCombinatorAlgorithm
| first_applicable : RuleCombinatorAlgorithm
| legacy_deny_overrides : RuleCombinatorAlgorithm
| legacy_ordered_deny_overrides : RuleCombinatorAlgorithm
| legacy_permit_overrides : RuleCombinatorAlgorithm
| legacy_ordered_permit_overrides : RuleCombinatorAlgorithm
namespace RuleCombinatorAlgorithm
-- The output of a combining algorithm which does not track the extended set
-- of “Indeterminate” values MUST be treated as “Indeterminate{DP}” for the
-- value “Indeterminate” by a combining algorithm which tracks the extended
-- set of “Indeterminate” values. A combining algorithm which does not track
-- the extended set of “Indeterminate” values MUST treat the output of a
-- combining algorithm which tracks the extended set of “Indeterminate” values
-- as an “Indeterminate” for any of the possible values of the extended set of
-- “Indeterminate”.
def eval_deny_overrides (results : List Decision') : Decision' :=
if results.elem Decision'.deny then Decision'.deny else
if results.elem Decision'.indeterminate_dp then Decision'.indeterminate_dp else
if results.elem Decision'.indeterminate_d ∧ results.elem Decision'.indeterminate_p then Decision'.indeterminate_dp else
if results.elem Decision'.indeterminate_d then Decision'.indeterminate_d else
if results.elem Decision'.permit then Decision'.permit else
if results.elem Decision'.indeterminate_p then Decision'.indeterminate_p else
Decision'.not_applicable
def eval_ordered_deny_overrides : List Decision' -> Decision' := eval_deny_overrides
def eval_permit_overrides (results : List Decision') : Decision' :=
if results.elem Decision'.permit then Decision'.permit else
if results.elem Decision'.indeterminate_dp then Decision'.indeterminate_dp else
if results.elem Decision'.indeterminate_d ∧ results.elem Decision'.indeterminate_p then Decision'.indeterminate_dp else
if results.elem Decision'.indeterminate_p then Decision'.indeterminate_p else
if results.elem Decision'.deny then Decision'.deny else
if results.elem Decision'.indeterminate_d then Decision'.indeterminate_d else
Decision'.not_applicable
def eval_ordered_permit_overrides : List Decision' -> Decision' := eval_permit_overrides
def eval_deny_unless_permit (results : List Decision') : Decision' :=
if results.elem Decision'.permit then Decision'.permit else Decision'.deny
def eval_permit_unless_deny (results : List Decision') : Decision' :=
if results.elem Decision'.deny then Decision'.deny else Decision'.permit
-- The non-normative part of the specification asserts that "If an error
-- occurs while evaluating the target or condition of a rule, then the
-- evaluation SHALL halt, and the policy shall evaluate to "Indeterminate",
-- with the appropriate error status."
--
-- This behavior isn't spelled out in the normative part, because errors are
-- represented as an Indeterminate.
def eval_first_applicable (results : List Decision') : Decision' :=
match (results.filter (fun d => d != Decision'.not_applicable)).get? 0 with
| some a => a
| none => Decision'.not_applicable
def eval_legacy_deny_overrides (results : List Decision') : Decision' :=
-- Note that "any rule having Effect=Deny evaluates to Indeterminate"
-- corresponds to indeterminate_d, and "any rule having Effect=Permit
-- evaluates to Indeterminate" corresponds to indeterminate_p.
if results.elem Decision'.deny then Decision'.deny else
if results.elem Decision'.indeterminate_d then Decision'.indeterminate else
if results.elem Decision'.permit then Decision'.permit else
if results.elem Decision'.indeterminate_p then Decision'.indeterminate else
Decision'.not_applicable
def eval_legacy_ordered_deny_overrides : List Decision' -> Decision' := eval_legacy_deny_overrides
-- See the comment for `eval_legacy_deny_overrides_rule`.
def eval_legacy_permit_overrides (results : List Decision') : Decision' :=
if results.elem Decision'.permit then Decision'.permit else
if results.elem Decision'.indeterminate_p then Decision'.indeterminate else
if results.elem Decision'.deny then Decision'.deny else
if results.elem Decision'.indeterminate_d then Decision'.indeterminate else
Decision'.not_applicable
def eval_legacy_ordered_permit_overrides : List Decision' -> Decision' := eval_legacy_permit_overrides
end RuleCombinatorAlgorithm
inductive PolicyCombinatorAlgorithm where
| deny_overrides : PolicyCombinatorAlgorithm
| ordered_deny_overrides : PolicyCombinatorAlgorithm
| permit_overrides : PolicyCombinatorAlgorithm
| ordered_permit_overrides : PolicyCombinatorAlgorithm
| deny_unless_permit : PolicyCombinatorAlgorithm
| permit_unless_deny : PolicyCombinatorAlgorithm
| first_applicable : PolicyCombinatorAlgorithm
| only_one_applicable : PolicyCombinatorAlgorithm
| legacy_deny_overrides : PolicyCombinatorAlgorithm
| legacy_ordered_deny_overrides : PolicyCombinatorAlgorithm
| legacy_permit_overrides : PolicyCombinatorAlgorithm
| legacy_ordered_permit_overrides : PolicyCombinatorAlgorithm
namespace PolicyCombinatorAlgorithm
def eval_deny_overrides := RuleCombinatorAlgorithm.eval_deny_overrides
def eval_ordered_deny_overrides := RuleCombinatorAlgorithm.eval_ordered_deny_overrides
def eval_permit_overrides := RuleCombinatorAlgorithm.eval_permit_overrides
def eval_ordered_permit_overrides := RuleCombinatorAlgorithm.eval_ordered_permit_overrides
def eval_deny_unless_permit := RuleCombinatorAlgorithm.eval_deny_unless_permit
def eval_permit_unless_deny := RuleCombinatorAlgorithm.eval_permit_unless_deny
def eval_first_applicable := RuleCombinatorAlgorithm.eval_first_applicable
-- The non-normative part of the specification asserts that "If an error
-- occurs while evaluating the target or condition of a rule, then the
-- evaluation SHALL halt, and the policy shall evaluate to "Indeterminate",
-- with the appropriate error status."
--
-- This behavior isn't spelled out in the normative part, because errors are
-- represented as an Indeterminate.
def eval_only_one_applicable (results : List Decision') : Decision' :=
match results.filter (fun d => d != Decision'.not_applicable) with
| [] => Decision'.not_applicable
| [a] => a
| _ => Decision'.indeterminate
def eval_legacy_deny_overrides (results : List Decision') : Decision' :=
if results.elem Decision'.deny then Decision'.deny else
if results.elem Decision'.indeterminate then Decision'.deny else
if results.elem Decision'.permit then Decision'.permit else
Decision'.not_applicable
def eval_legacy_ordered_deny_overrides : List Decision' -> Decision' := eval_legacy_deny_overrides
-- See the comment for `eval_legacy_deny_overrides`.
def eval_legacy_permit_overrides (results : List Decision') : Decision' :=
if results.elem Decision'.permit then Decision'.permit else
if results.elem Decision'.deny then Decision'.deny else
if results.elem Decision'.indeterminate then Decision'.indeterminate else
Decision'.not_applicable
def eval_legacy_ordered_permit_overrides : List Decision' -> Decision' := eval_legacy_permit_overrides
end PolicyCombinatorAlgorithm
inductive StatusCode
| ok : StatusCode
| missing_attribute : StatusCode
| syntax_error : StatusCode
| processing_error : StatusCode
deriving BEq, Repr
structure AttributeDesignator where
category : String
identifier : String
type : XmlType
issuer : Option String
must_be_present : Bool
deriving BEq, Repr
namespace AttributeDesignator
def eval (designator : AttributeDesignator) (context : List Attribute) : Sum Value (List StatusCode) :=
match designator with
| AttributeDesignator.mk category identifier type issuer must_be_present =>
let found :=
-- A named attribute SHALL match an attribute if the values of
-- their respective Category, AttributeId, DataType and Issuer
-- attributes match. The attribute designator’s Category MUST
-- match, by identifier equality, the Category of the
-- <Attributes> element in which the attribute is present. The
-- attribute designator’s AttributeId MUST match, by identifier
-- equality, the AttributeId of the attribute. The attribute
-- designator’s DataType MUST match, by identifier equality, the
-- DataType of the same attribute.
--
-- If the Issuer attribute is present in the attribute
-- designator, then it MUST match, using the
-- “urn:oasis:names:tc:xacml:1.0:function:string-equal”
-- function, the Issuer of the same attribute. If the Issuer is
-- not present in the attribute designator, then the matching of
-- the attribute to the named attribute SHALL be governed by
-- AttributeId and DataType attributes alone.
context.filter (fun (attr : Attribute) =>
attr.category == category
∧ attr.identifier == identifier
∧ attr.value.fst == type
∧ (attr.issuer == Option.none ∨ attr.issuer == issuer))
let found := found.map (fun x => x.value)
if must_be_present then
match found with
| [] => Sum.inr $ [StatusCode.missing_attribute]
| _ => Sum.inl $ Value.bag (Bag.mk found)
else Sum.inl $ Value.bag (Bag.mk found)
end AttributeDesignator
def matches? (designator : AttributeDesignator) (attr : Attribute) : Prop :=
designator.category == attr.category ∧
designator.identifier == attr.identifier ∧
designator.type == attr.value.fst ∧
match (designator.issuer, attr.issuer) with
| (none, _) => True
| (some issuer₁, some issuer₂) => issuer₁ == issuer₂
| _ => False
def FunctionID : Type := String
deriving BEq, Repr
-- "The <Expression> element is not used directly in a policy. The <Expression>
-- element signifies that an element that extends the ExpressionType and is a
-- member of the <Expression> element substitution group SHALL appear in its
-- place."
--
-- We omit the `<xacml:AttributeSelector>` case because this model of XACML does
-- not include it, and we exclude the `<xacml:VariableReference>` case because
-- we erase variable references in the compiler.
inductive Expression where
-- Note well that `apply` accepts a list of Values, not a list of Expressions,
-- as its arguments. The compiler is responsible for ensuring that the
-- arguments in a function call are fully evaluated.
--
-- Lean is quite strict about recursion being bounded, which is a little hard
-- to prove in our case! Fortunately, we can punt the job of proving that to
-- the compiler.
| apply (function : FunctionID) (args: List Value) : Expression
| attribute_designator (inner : AttributeDesignator) : Expression
| attribute_value (inner : Value) : Expression
| function (function : FunctionID) : Expression
deriving BEq, Repr
namespace Expression
def apply_eval (name : FunctionID) (args : List Value) : Option Value :=
if name == "urn:oasis:names:tc:xacml:1.0:function:rfc822Name-match" then
match args with
| [Value.primitive (XmlType.string, lhs),
Value.primitive (XmlType.rfc822Name, rhs)] =>
Value.primitive (lhs == rhs)
| _ => Value.primitive (#<XmlType.boolean, "Indeterminate">)
else if name == "urn:oasis:names:tc:xacml:1.0:function:string-equal" then
match args with
| [Value.primitive (XmlType.string, lhs),
Value.primitive (XmlType.string, rhs)] =>
Value.primitive (lhs == rhs)
| _ => Value.primitive (#<XmlType.boolean, "Indeterminate">)
else Option.none
def eval (expression : Expression) (context : Request) : Option Value :=
-- The return type of `<Apply>` may be made more specific by type unification.
--
-- The evaluation result can be specified to be "Indeterminate"; we encode
-- this as `Option.none` here for ergonomics, but we do give an instance for
-- `Coe (Option Value) Value`.
--
-- § 7.6 enumerates but does not describe the semantics for:
--
-- - <xacml:AttributeValue>
-- - <xacml:AttributeDesignator>
-- - <xacml:AttributeSelector>
-- - <xacml:Apply>
-- - <xacml:Function>
-- - <xacml:VariableReference>
match expression with
| Expression.apply name args => apply_eval name args
| Expression.attribute_designator inner =>
match inner.eval context with
| Sum.inl res => res
| Sum.inr status => Option.none
| Expression.attribute_value inner => some inner
| _ => Option.none
end Expression
structure Match where
function : Identifier
designator : AttributeDesignator
value : Value
deriving BEq, Repr
def AllOf : Type := List Match
deriving BEq, Repr
def AnyOf : Type := List AllOf
deriving BEq, Repr
def Target : Type := List AnyOf
deriving BEq, Repr
namespace Match
-- The evaluation semantics for a matching element is as follows.
--
-- 1. If an operational error were to occur while evaluating the
-- <AttributeDesignator> or <AttributeSelector> element, then the
-- result of the entire expression SHALL be "Indeterminate".
--
-- 2. If the <AttributeDesignator> or <AttributeSelector> element were
-- to evaluate to an empty bag, then the result of the expression
-- SHALL be "False".
--
-- 3. Otherwise, the MatchId function SHALL be applied between the
-- <AttributeValue> and each element of the bag returned from the
-- <AttributeDesignator> or <AttributeSelector> element.
-- a. If at least one of those function applications were to evaluate
-- to "True", then the result of the entire expression SHALL be
-- "True".
-- b. Otherwise, if at least one of the function applications results
-- in "Indeterminate", then the result SHALL be "Indeterminate".
-- c. Finally, if all function applications evaluate to "False", then
-- the result of the entire expression SHALL be "False".
def eval (m : Match) (context : Request) : Option Value :=
match m with
| Match.mk fn designator value =>
match designator.eval context with
| Sum.inl result =>
let results := match result with
-- Otherwise, the MatchId function SHALL be applied between the
-- <AttributeValue> and each element of the bag returned from the
-- <AttributeDesignator> or <AttributeSelector> element.
| (Value.bag (Bag.mk attrs)) =>
attrs.map fun attr =>
let args := [value, Value.primitive attr]
(Expression.apply fn args).eval context
| (Value.primitive attr) =>
-- TODO: Prove that this case is impossible.
let args := [value, Value.primitive attr]
[(Expression.apply fn args).eval context]
let results := results.map (fun (x : Option Value) => (x : Value))
-- If at least one of those function applications were to evaluate to
-- "True", then the result of the entire expression SHALL be "True".
if results.elem (Value.primitive (#<XmlType.boolean, "True">)) then
(Value.primitive (#<XmlType.boolean, "True">))
-- Otherwise, if at least one of the function applications results in
-- "Indeterminate", then the result SHALL be "Indeterminate".
else if results.elem (Value.primitive (#<XmlType.boolean, "Indeterminate">)) then
(Value.primitive (#<XmlType.boolean, "Indeterminate">))
-- The `else` arm handles the following cases:
--
-- If the <AttributeDesignator> or <AttributeSelector> element were to
-- evaluate to an empty bag, then the result of the expression SHALL
-- be "False".
--
-- Finally, if all function applications evaluate to "False", then the
-- result of the entire expression SHALL be "False".
else
Value.primitive (#<XmlType.boolean, "False">)
-- If an operational error were to occur while evaluating the
-- <AttributeDesignator> or <AttributeSelector> element, then the result
-- of the entire expression SHALL be "Indeterminate".
| Sum.inr status => Option.none
end Match
namespace AllOf
def eval (conj : AllOf) (context : Request) : MatchResult :=
let result := conj.map (fun x => x.eval context)
let result := result.map (fun (x : Option Value) => (x : Value))
if result.all (fun x => x == Value.primitive (XmlType.boolean, "True")) then MatchResult.is_match
else if result.all (fun x => x != Value.primitive (XmlType.boolean, "False")) ∧
result.elem (Value.primitive (XmlType.boolean, "Indeterminate"))
then MatchResult.indeterminate
else MatchResult.no_match
end AllOf
namespace AnyOf
def eval (disj : AnyOf) (context : Request) : MatchResult :=
-- match disj with
-- | [] => MatchResult.is_match
-- | List.cons x xs => match x.eval context with
-- | MatchResult.is_match => MatchResult.is_match
-- | MatchResult.no_match =>
-- let rest := AnyOf.eval xs context
-- if rest == MatchResult.no_match then MatchResult.no_match else rest
-- | MatchResult.indeterminate =>
-- let rest := AnyOf.eval xs context
-- if rest == MatchResult.no_match then MatchResult.indeterminate else rest
if disj.isEmpty then MatchResult.is_match else
let result := disj.map (fun x => x.eval context)
if result.any (fun x => x == MatchResult.is_match) then MatchResult.is_match
else if result.elem MatchResult.indeterminate then MatchResult.indeterminate
else MatchResult.no_match
end AnyOf
namespace Target
def eval (target : Target) (context : Request) : MatchResult :=
match target with
-- An empty target matches any request.
| [] => MatchResult.is_match
| xs =>
let results := xs.map (fun disj => disj.eval context)
-- Otherwise the target value SHALL be "Match" if all the AnyOf
-- specified in the target match values in the request context.
if results.all (fun result => result == MatchResult.is_match) then
MatchResult.is_match
-- Otherwise, if any one of the AnyOf specified in the target is “No
-- Match”, then the target SHALL be “No Match”.
else if results.any (fun result => result == MatchResult.no_match) then
MatchResult.no_match
-- Otherwise, the target SHALL be “Indeterminate”.
else MatchResult.indeterminate
end Target
structure Obligation where
assignments : List Attribute
identifier : String
deriving BEq, Repr
structure Advice where
assignments : List Attribute
identifier : String
deriving BEq, Repr
structure AttributeAssignmentExpression where
category : String
identifier : String
issuer : Option String
expression : Expression
deriving BEq, Repr
namespace AttributeAssignmentExpression
def eval (assignment : AttributeAssignmentExpression) (context : Request) : Option Attribute :=
match assignment.expression.eval context with
| some (Value.primitive inner) =>
Attribute.mk
assignment.category
assignment.identifier
assignment.issuer
inner
| _ => none
end AttributeAssignmentExpression
structure ObligationExpression where
assignments : List AttributeAssignmentExpression
identifier : String
fulfill_on : Decision
deriving BEq, Repr
namespace ObligationExpression
def eval (obligation : ObligationExpression) (context : Request) : Option Obligation :=
let assignments := obligation.assignments.map (fun x => AttributeAssignmentExpression.eval x context)
if assignments.all Option.isSome then
Obligation.mk
(List.filterMap id assignments)
obligation.identifier
else none
end ObligationExpression
structure AdviceExpression where
assignments : List AttributeAssignmentExpression
identifier : String
applies_to : Decision
deriving BEq, Repr
namespace AdviceExpression
def eval (advice : AdviceExpression) (context : Request) : Option Advice :=
let assignments := advice.assignments.map (fun x => AttributeAssignmentExpression.eval x context)
if assignments.all Option.isSome then
Advice.mk
(List.filterMap id assignments)
advice.identifier
else none
end AdviceExpression
structure ResultAuxiliary where
status : Option (List StatusCode)
obligations : List Obligation
advice : List Advice
deriving BEq, Repr
structure ResultAuxiliary' where
status : Option (List StatusCode)
obligations : List ObligationExpression
advice : List AdviceExpression
deriving BEq, Repr
structure MissingAttributeDetail where
category : String
identifier : String
issuer : Option String
value : Option Value
type : XmlType
deriving BEq, Repr
def Result : Type := Decision' × (Option ResultAuxiliary)
def Result' : Type := Decision' × (Option ResultAuxiliary')
namespace Result'
def eval (result : Result') (context : Request) : Result :=
match result.snd with
| some aux =>
let advices := aux.advice.map (fun advice => AdviceExpression.eval advice context)
let obligations := aux.obligations.map (fun x => ObligationExpression.eval x context)
if advices.any Option.isNone || obligations.any Option.isNone then
(Decision'.indeterminate, none)
else
(
result.fst,
ResultAuxiliary.mk
aux.status
(List.filterMap id obligations)
(List.filterMap id advices)
)
| none => (result.fst, none)
end Result'
structure Rule where
target : Target
condition : Option Expression
effect : EffectType
obligations : List ObligationExpression
advice : List AdviceExpression
namespace Rule
def eval (rule : Rule) (context : Request) : Result' :=
let (decision : Decision') :=
-- The "no target" case is handled within `Target.eval`, returning
-- `MatchResult.is_match` when the target is empty.
match rule.target.eval context with
| MatchResult.is_match =>
let condition :=
match rule.condition with
| some condition =>
-- The condition value SHALL be "True" if the <Condition> element
-- evaluates to "True".
let result := condition.eval context
if result == some (Value.primitive (#<XmlType.boolean, "True">)) then result
-- Its value SHALL be "False" if the <Condition> element evaluates to
-- "False".
else if result == some (Value.primitive (#<XmlType.boolean, "False">)) then result
-- The condition value SHALL be "Indeterminate", if the expression
-- contained in the <Condition> element evaluates to "Indeterminate."
else Value.primitive (#<XmlType.boolean, "Indeterminate">)
-- The condition value SHALL be "True" if the <Condition> element is absent.
| none => Value.primitive (#<XmlType.boolean, "True">)
match condition with
| some (Value.primitive (XmlType.boolean, "False")) => Decision'.not_applicable
| some (Value.primitive (XmlType.boolean, "True")) =>
match rule.effect with
| EffectType.permit => Decision'.permit
| EffectType.deny => Decision'.deny
-- | (#<XmlType.boolean, "Indeterminate">) =>
| _ =>
if rule.effect == EffectType.permit then
Decision'.indeterminate_p else
Decision'.indeterminate_d
| MatchResult.no_match => Decision'.not_applicable
| MatchResult.indeterminate =>
if rule.effect == EffectType.permit then
Decision'.indeterminate_p else
Decision'.indeterminate_d
let advices :=
rule.advice.filter
(fun advice => advice.applies_to == (decision : Decision))
let obligations :=
rule.obligations.filter
(fun obligation => obligation.fulfill_on == (decision : Decision))
(
decision,
ResultAuxiliary'.mk
none
obligations
advices
)
end Rule
structure Policy where
combinator : RuleCombinatorAlgorithm
target : Target
obligations : List ObligationExpression
advice : List AdviceExpression
namespace Policy
def eval (policy : Policy) (child_results : List Result') (context : Request) : Result' :=
let combinator :=
match policy.combinator with
| RuleCombinatorAlgorithm.deny_overrides => RuleCombinatorAlgorithm.eval_deny_overrides
| RuleCombinatorAlgorithm.ordered_deny_overrides => RuleCombinatorAlgorithm.eval_ordered_deny_overrides
| RuleCombinatorAlgorithm.permit_overrides => RuleCombinatorAlgorithm.eval_permit_overrides
| RuleCombinatorAlgorithm.ordered_permit_overrides => RuleCombinatorAlgorithm.eval_ordered_permit_overrides
| RuleCombinatorAlgorithm.deny_unless_permit => RuleCombinatorAlgorithm.eval_deny_unless_permit
| RuleCombinatorAlgorithm.permit_unless_deny => RuleCombinatorAlgorithm.eval_permit_unless_deny
| RuleCombinatorAlgorithm.first_applicable => RuleCombinatorAlgorithm.eval_first_applicable
| RuleCombinatorAlgorithm.legacy_deny_overrides => RuleCombinatorAlgorithm.eval_legacy_deny_overrides
| RuleCombinatorAlgorithm.legacy_ordered_deny_overrides => RuleCombinatorAlgorithm.eval_legacy_ordered_deny_overrides
| RuleCombinatorAlgorithm.legacy_permit_overrides => RuleCombinatorAlgorithm.eval_legacy_permit_overrides
| RuleCombinatorAlgorithm.legacy_ordered_permit_overrides => RuleCombinatorAlgorithm.eval_legacy_ordered_permit_overrides
let (decision : Decision') := combinator (List.map Prod.fst child_results)
let (decision : Decision') :=
match policy.target.eval context with
| MatchResult.is_match => decision
| MatchResult.no_match => Decision'.not_applicable
| MatchResult.indeterminate =>
match decision with
| Decision'.not_applicable => Decision'.not_applicable
| Decision'.permit => Decision'.indeterminate_p
| Decision'.deny => Decision'.indeterminate_d
| Decision'.indeterminate => Decision'.indeterminate_dp
| Decision'.indeterminate_dp => Decision'.indeterminate_dp
| Decision'.indeterminate_p => Decision'.indeterminate_p
| Decision'.indeterminate_d => Decision'.indeterminate_d
let advices :=
policy.advice.filter
(fun advice => advice.applies_to == (decision : Decision))
++
List.join
(child_results.filterMap
(fun x => match x.snd with
| some y => y.advice
| none => none))
let obligations :=
policy.obligations.filter
(fun obligation => obligation.fulfill_on == (decision : Decision))
++
List.join
(child_results.filterMap
(fun x => match x.snd with
| some y => y.obligations
| none => none))
(
decision,
ResultAuxiliary'.mk
none
obligations
advices
)
end Policy
structure PolicySet where
combinator : PolicyCombinatorAlgorithm
target : Target
obligations : List ObligationExpression
advice : List AdviceExpression
namespace PolicySet
def eval (policyset : PolicySet) (child_results : List Result') (context : Request) : Result' :=
let combinator :=
match policyset.combinator with
| PolicyCombinatorAlgorithm.deny_overrides => PolicyCombinatorAlgorithm.eval_deny_overrides
| PolicyCombinatorAlgorithm.ordered_deny_overrides => PolicyCombinatorAlgorithm.eval_ordered_deny_overrides
| PolicyCombinatorAlgorithm.permit_overrides => PolicyCombinatorAlgorithm.eval_permit_overrides
| PolicyCombinatorAlgorithm.ordered_permit_overrides => PolicyCombinatorAlgorithm.eval_ordered_permit_overrides
| PolicyCombinatorAlgorithm.deny_unless_permit => PolicyCombinatorAlgorithm.eval_deny_unless_permit
| PolicyCombinatorAlgorithm.permit_unless_deny => PolicyCombinatorAlgorithm.eval_permit_unless_deny
| PolicyCombinatorAlgorithm.first_applicable => PolicyCombinatorAlgorithm.eval_first_applicable
| PolicyCombinatorAlgorithm.only_one_applicable => PolicyCombinatorAlgorithm.eval_only_one_applicable
| PolicyCombinatorAlgorithm.legacy_deny_overrides => PolicyCombinatorAlgorithm.eval_legacy_deny_overrides
| PolicyCombinatorAlgorithm.legacy_ordered_deny_overrides => PolicyCombinatorAlgorithm.eval_legacy_ordered_deny_overrides
| PolicyCombinatorAlgorithm.legacy_permit_overrides => PolicyCombinatorAlgorithm.eval_legacy_permit_overrides
| PolicyCombinatorAlgorithm.legacy_ordered_permit_overrides => PolicyCombinatorAlgorithm.eval_legacy_ordered_permit_overrides
let (decision : Decision') := combinator (List.map Prod.fst child_results)
let (decision : Decision') :=
match policyset.target.eval context with
| MatchResult.is_match => decision
| MatchResult.no_match => Decision'.not_applicable
| MatchResult.indeterminate =>
match decision with
| Decision'.not_applicable => Decision'.not_applicable
| Decision'.permit => Decision'.indeterminate_p
| Decision'.deny => Decision'.indeterminate_d
| Decision'.indeterminate => Decision'.indeterminate_dp
| Decision'.indeterminate_dp => Decision'.indeterminate_dp
| Decision'.indeterminate_p => Decision'.indeterminate_p
| Decision'.indeterminate_d => Decision'.indeterminate_d
let advices :=
policyset.advice.filter
(fun advice => advice.applies_to == (decision : Decision))
++
List.join
(child_results.filterMap
(fun x => match x.snd with
| some y => y.advice
| none => none))
let obligations :=
policyset.obligations.filter
(fun obligation => obligation.fulfill_on == (decision : Decision))
++
List.join
(child_results.filterMap
(fun x => match x.snd with
| some y => y.obligations
| none => none))
(
decision,
ResultAuxiliary'.mk
none
obligations
advices
)
end PolicySet
inductive PolicyElement where
| PolicySet (ps : PolicySet)
| Policy (p : Policy)
| Rule (r : Rule)
def PolicyElement.eval (context : Request) : PolicyElement -> List Result' -> Result'
| PolicySet ps, results => ps.eval results context
| Policy p, results => p.eval results context
| Rule r, _ => r.eval context
inductive ElementTree where
| Node (e : PolicyElement) (xs : List ElementTree)
def ElementTree.eval' (context : Request) : ElementTree -> List Result' -> Result'
| ElementTree.Node e [], results => PolicyElement.eval context e results
| ElementTree.Node e (x :: xs), results =>
ElementTree.eval'
context
(ElementTree.Node e xs)
((ElementTree.eval' context x []) :: results)
def ElementTree.eval (context : Request) (et : ElementTree) : Result' :=
ElementTree.eval' context et []
-- let results := policy.rules.map (fun rule => rule.eval context)
def is_indeterminate (x : Expression) : Bool :=
match x with
| Expression.attribute_value (Value.primitive (XmlType.boolean, "Indeterminate")) => true
| _ => false
def make_response
(decision : Decision)
(status : Option (List StatusCode))
(obligations : List Obligation)
(advice : List Advice)
: Decision × ResultAuxiliary :=
let obligations := obligations.map (fun expr => Obligation.mk expr.assignments expr.identifier)
let advice := advice.map (fun expr => Advice.mk expr.assignments expr.identifier)
-- If any of the attribute assignment expressions in an obligation or
-- advice expression with a matching FulfillOn or AppliesTo attribute
-- evaluates to “Indeterminate”, then the whole rule, policy, or
-- policy set SHALL be “Indeterminate”. If the FulfillOn or AppliesTo
-- attribute does not match the result of the combining algorithm or
-- the rule evaluation, then any indeterminate in an obligation or
-- advice expression has no effect.
-- if obligations.
let decision :=
-- if obligations.any
-- (fun obligation => obligation.assignments.any
-- (fun assignment => is_indeterminate assignment.expression)) ∨
-- advice.any
-- (fun advice => advice.assignments.any
-- (fun assignment => is_indeterminate assignment.expression))
-- then
-- Decision.indeterminate
-- else
decision
(
decision,
ResultAuxiliary.mk
status
(obligations.map (fun expr => Obligation.mk expr.assignments expr.identifier))
(advice.map (fun expr => Advice.mk expr.assignments expr.identifier))
)
def combine_response_aux (x y : ResultAuxiliary) : ResultAuxiliary :=
match (x, y) with
| (ResultAuxiliary.mk status₁ obligations₁ advice₁,
ResultAuxiliary.mk status₂ obligations₂ advice₂) =>
ResultAuxiliary.mk
status₁
(obligations₁ ++ obligations₂)
(advice₁ ++ advice₂)
def Choice : Type := List (Decision × ResultAuxiliary)
deriving BEq, Repr
def compiled_facassignviewgrades_metadata := ((PolicyElement.Rule (Rule.mk [[[(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" XmlType.string none True) (Value.primitive (XmlType.string, "ExternalGrades"))), (Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" XmlType.string none True) (Value.primitive (XmlType.string, "Assign")))], [(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" XmlType.string none True) (Value.primitive (XmlType.string, "InternalGrades"))), (Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" XmlType.string none True) (Value.primitive (XmlType.string, "Assign")))], [(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" XmlType.string none True) (Value.primitive (XmlType.string, "ExternalGrades"))), (Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" XmlType.string none True) (Value.primitive (XmlType.string, "View")))], [(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" XmlType.string none True) (Value.primitive (XmlType.string, "InternalGrades"))), (Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" XmlType.string none True) (Value.primitive (XmlType.string, "View")))]]] none EffectType.permit [] [])))
def compiled_fac100_metadata := ((PolicyElement.Policy (Policy.mk RuleCombinatorAlgorithm.legacy_permit_overrides [[[(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" XmlType.string none True) (Value.primitive (XmlType.string, "Faculty")))]]] [] [])))
def compiled_sturecieveextgrades_metadata := ((PolicyElement.Rule (Rule.mk [[[(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" XmlType.string none True) (Value.primitive (XmlType.string, "ExternalGrades"))), (Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" XmlType.string none True) (Value.primitive (XmlType.string, "Receive")))]]] none EffectType.permit [] [])))
def compiled_stu100_metadata := ((PolicyElement.Policy (Policy.mk RuleCombinatorAlgorithm.legacy_permit_overrides [[[(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" XmlType.string none True) (Value.primitive (XmlType.string, "Student")))]]] [] [])))
def compiled_college100_metadata := ((PolicyElement.PolicySet (PolicySet.mk PolicyCombinatorAlgorithm.legacy_permit_overrides [] [] [])))
def compiled_facassignviewgrades_element := ((ElementTree.Node compiled_facassignviewgrades_metadata []))
def compiled_fac100_element := ((ElementTree.Node compiled_fac100_metadata [compiled_facassignviewgrades_element]))
def compiled_sturecieveextgrades_element := ((ElementTree.Node compiled_sturecieveextgrades_metadata []))
def compiled_stu100_element := ((ElementTree.Node compiled_stu100_metadata [compiled_sturecieveextgrades_element]))
def compiled_college100_element := ((ElementTree.Node compiled_college100_metadata [compiled_fac100_element, compiled_stu100_element]))
theorem filter_attr (req : Request) (attr : Attribute):
req.contains attr →
AttributeDesignator.eval
{ category := attr.category, identifier := attr.identifier, type := XmlType.string, issuer := none,
must_be_present := true }
req = Sum.inl (Value.bag (Bag.mk [attr.value])) := by sorry
theorem self_eq_self (s : String) (req : Request) :
Expression.eval
(Expression.apply "urn:oasis:names:tc:xacml:1.0:function:string-equal"
[Value.primitive (XmlType.string, s), Value.primitive (XmlType.string, s)])
req = some (Value.primitive (XmlType.boolean, "True")) := by
sorry
macro "rw_local " t:term p:term : tactic => `(tactic| have hint : $t := $p <;> simp [hint] <;> clear hint)
theorem match_eval (attr : Attribute) (s : String) (req : Request) :
attr.value = (XmlType.string, s) →
req.contains attr →
Match.eval { function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := attr.category,
identifier := attr.identifier,
type := XmlType.string,
issuer := none,
must_be_present := true },
value := Value.primitive attr.value }
req = some (Value.primitive (XmlType.boolean, "True")) := by
intros h₁ h₂
simp [Match.eval]
rw_local
AttributeDesignator.eval
{ category := attr.category, identifier := attr.identifier, type := XmlType.string, issuer := none,
must_be_present := true }
req = Sum.inl (Value.bag (Bag.mk [attr.value]))
by apply filter_attr _ _ h₂
rw [h₁]
rw_local
Expression.eval
(Expression.apply "urn:oasis:names:tc:xacml:1.0:function:string-equal"
[Value.primitive (XmlType.string, s), Value.primitive (XmlType.string, s)])
req = some (Value.primitive (XmlType.boolean, "True"))
by apply self_eq_self _ _
rfl
-- Pr2: All members of Faculty can Assign both InternalGrades and ExternalGrades.
theorem pr₂_lemma₀ (req : Request) :
req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Assign"))
→ req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "InternalGrades"))
→ AllOf.eval
[{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:resource",
identifier := "resource-class", type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "InternalGrades") },
{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:action", identifier := "command",
type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "Assign") }]
req = MatchResult.is_match := by
intros h₁ h₂
simp [AllOf.eval]
rw_local
Match.eval
{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:resource",
identifier := "resource-class", type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "InternalGrades") }
req = some (Value.primitive (XmlType.boolean, "True"))
by
let attr := (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "InternalGrades"))
have hint : attr.value = (XmlType.string, "InternalGrades") := by rfl
have h₂' : req.contains attr := by apply h₂
apply match_eval attr "InternalGrades" req hint h₂'
rw_local
Match.eval
{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:action",
identifier := "command", type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "Assign") }
req = some (Value.primitive (XmlType.boolean, "True"))
by
let attr := ({ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:action", identifier := "command", issuer := none, value := (XmlType.string, "Assign") } : Attribute)
have hint : attr.value = (XmlType.string, "Assign") := by rfl
have h₁' : req.contains attr := by apply h₁
apply match_eval attr "Assign" req hint h₁'
theorem pr₂_lemma₁ (req : Request) :
req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Assign"))
→ req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "InternalGrades"))
→ Target.eval
[[[{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:resource",
identifier := "resource-class", type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "ExternalGrades") },
{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:action", identifier := "command",
type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "Assign") }],
[{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:resource",
identifier := "resource-class", type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "InternalGrades") },
{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:action", identifier := "command",
type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "Assign") }],
[{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:resource",
identifier := "resource-class", type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "ExternalGrades") },
{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:action", identifier := "command",
type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "View") }],
[{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:resource",
identifier := "resource-class", type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "InternalGrades") },
{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:action", identifier := "command",
type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "View") }]]]
req = MatchResult.is_match := by
intros h₂ h₃
simp [Target.eval, AnyOf.eval]
cases (AllOf.eval
[{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:resource",
identifier := "resource-class", type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "ExternalGrades") },
{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:action", identifier := "command",
type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "Assign") }]
req)
with
| is_match => simp
| _ =>
simp
rw_local
AllOf.eval
[{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:resource",
identifier := "resource-class", type := XmlType.string, issuer := none,
must_be_present := true },
value := Value.primitive (XmlType.string, "InternalGrades") },
{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:action",
identifier := "command", type := XmlType.string, issuer := none,
must_be_present := true },
value := Value.primitive (XmlType.string, "Assign") }]
req = MatchResult.is_match
by apply pr₂_lemma₀ req h₂ h₃
theorem pr₂_lemma₂ (req : Request) :
req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Assign"))
→ req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "InternalGrades"))
→ (ElementTree.eval' req compiled_facassignviewgrades_element []).fst = Decision'.permit := by
intros h₂ h₃
simp [compiled_facassignviewgrades_element, compiled_facassignviewgrades_metadata]
simp [ElementTree.eval,
ElementTree.eval',
PolicyElement.eval,
Rule.eval]
rw_local
Target.eval
[[[{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:resource",
identifier := "resource-class", type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "ExternalGrades") },
{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:action", identifier := "command",
type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "Assign") }],
[{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:resource",
identifier := "resource-class", type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "InternalGrades") },
{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:action", identifier := "command",
type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "Assign") }],
[{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:resource",
identifier := "resource-class", type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "ExternalGrades") },
{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:action", identifier := "command",
type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "View") }],
[{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:resource",
identifier := "resource-class", type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "InternalGrades") },
{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:action", identifier := "command",
type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "View") }]]]
req = MatchResult.is_match
by apply pr₂_lemma₁ req h₂ h₃
simp [Primitive.mk]
theorem pr₂_lemma₃ (req : Request) :
req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Faculty"))
→ AllOf.eval
[{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:subject", identifier := "role",
type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "Faculty") }]
req = MatchResult.is_match := by
intro h₁
simp [AllOf.eval]
rw_local
Match.eval
{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:subject", identifier := "role",
type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "Faculty") }
req = some (Value.primitive (XmlType.boolean, "True"))
by
let attr := (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Faculty"))
have hint : attr.value = (XmlType.string, "Faculty") := by rfl
have h₂' : req.contains attr := by apply h₁
apply match_eval attr "Faculty" req hint h₂'
theorem pr₂_lemma₄ (req : Request) :
req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Faculty"))
→ Target.eval
[[[{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:subject", identifier := "role",
type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "Faculty") }]]]
req = MatchResult.is_match := by
intros h₁
simp [Target.eval, AnyOf.eval]
rw_local
(AllOf.eval
[{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:subject", identifier := "role",
type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "Faculty") }]
req = MatchResult.is_match)
by apply pr₂_lemma₃ req h₁
theorem pr₂_lemma₅ (req : Request) :
req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Faculty"))
→ req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Assign"))
→ req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "InternalGrades"))
→ (ElementTree.eval' req compiled_fac100_element []).fst = Decision'.permit := by
intros h₁ h₂ h₃
simp [compiled_fac100_element, compiled_fac100_metadata]
simp [ElementTree.eval,
ElementTree.eval',
PolicyElement.eval]
simp [Policy.eval]
rw_local
Target.eval
[[[{ function := "urn:oasis:names:tc:xacml:1.0:function:string-equal",
designator :=
{ category := "urn:oasis:names:tc:xacml:3.0:attribute-category:subject", identifier := "role",
type := XmlType.string, issuer := none, must_be_present := true },
value := Value.primitive (XmlType.string, "Faculty") }]]]
req = MatchResult.is_match
by apply pr₂_lemma₄ req h₁
simp [RuleCombinatorAlgorithm.eval_legacy_permit_overrides]
rw_local
(ElementTree.eval' req compiled_facassignviewgrades_element []).fst = Decision'.permit
by apply pr₂_lemma₂ req h₂ h₃
theorem pr₂ (req : Request) :
req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Faculty"))
→ req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Assign"))
→ req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "InternalGrades"))
→ (ElementTree.eval req compiled_college100_element).fst == Decision'.permit := by
intros h₁ h₂ h₃
simp [compiled_college100_element,
compiled_college100_metadata,
ElementTree.eval,
ElementTree.eval',
PolicyElement.eval,
PolicySet.eval,
Target.eval,
PolicyCombinatorAlgorithm.eval_legacy_permit_overrides]
rw_local
(ElementTree.eval' req compiled_fac100_element []).fst = Decision'.permit
by apply pr₂_lemma₅ req h₁ h₂ h₃
-- Pr1: There do not exist members of Student who can Assign ExternalGrades. (This is violated, so we show a counterexample.)
def bad_req :=
[Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Student"),
Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Receive"),
Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Assign"),
Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "ExternalGrades")]
theorem pr₁ :
∃ (req : Request),
req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Student"))
∧ req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Assign"))
∧ req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "ExternalGrades"))
∧ (ElementTree.eval req compiled_college100_element).fst == Decision'.permit := by
have h₁ : bad_req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Student")) := by
{ simp }
have h₂ : bad_req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Assign")) := by
{ simp }
have h₃ : bad_req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "ExternalGrades")) := by
{ simp }
apply Exists.intro bad_req
apply And.intro
{ apply h₁ }
apply And.intro
{ apply h₂ }
apply And.intro
{ apply h₃ }
rfl
-- Pr3: No combination of roles exists such that a user with those roles can both Receive and Assign the resource ExternalGrades.
def roles (req : Request) :=
req.filter
(fun attr =>
match attr with
| { category, identifier, .. } => identifier = "role" && category = "urn:oasis:names:tc:xacml:3.0:attribute-category:subject")
def bad_req₀ :=
[Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Student"),
Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Faculty"),
Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Receive"),
Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "ExternalGrades")]
def bad_req₁ :=
[Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Student"),
Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Faculty"),
Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Assign"),
Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "ExternalGrades")]
theorem pr₃ :
∃ (user_roles : List Attribute),
((∃ (req : Request),
user_roles ⊆ roles req
∧ req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Receive"))
∧ req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "ExternalGrades"))
∧ (ElementTree.eval req compiled_college100_element).fst == Decision'.permit)
∧ (∃ (req : Request),
user_roles ⊆ roles req
∧ req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Assign"))
∧ req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "ExternalGrades"))
∧ (ElementTree.eval req compiled_college100_element).fst == Decision'.permit))
:= by
let bad_roles :=
([Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Student"),
Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Faculty")])
apply Exists.intro bad_roles
apply And.intro
{ apply Exists.intro bad_req₀
have h₁ : bad_req₀.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Student")) := by
{ simp }
have h₂ : bad_req₀.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Receive")) := by
{ simp }
have h₃ : bad_req₀.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "ExternalGrades")) := by
{ simp }
apply And.intro
{ rw_local
roles bad_req₀ = bad_roles
by rfl }
apply And.intro
{ apply h₁ }
apply And.intro
{ apply h₂ }
rfl}
{ apply Exists.intro bad_req₁
have h₁ : bad_req₁.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Student")) := by
{ simp }
have h₂ : bad_req₁.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Assign")) := by
{ simp }
have h₃ : bad_req₁.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "ExternalGrades")) := by
{ simp }
apply And.intro
{ rw_local
roles bad_req₁ = bad_roles
by rfl }
apply And.intro
{ apply h₁ }
apply And.intro
{ apply h₂ }
rfl}
--- Property: Adding TAs should not affect ExternalGrades in any way.
def compiled_gradeAsgnAssigngrades_metadata := ((PolicyElement.Rule (Rule.mk [[[(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" XmlType.string none True) (Value.primitive (XmlType.string, "ExternalGrades"))), (Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" XmlType.string none True) (Value.primitive (XmlType.string, "Assign")))], [(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" XmlType.string none True) (Value.primitive (XmlType.string, "InternalGrades"))), (Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" XmlType.string none True) (Value.primitive (XmlType.string, "Assign")))], [(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" XmlType.string none True) (Value.primitive (XmlType.string, "ExternalGrades"))), (Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" XmlType.string none True) (Value.primitive (XmlType.string, "View")))], [(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" XmlType.string none True) (Value.primitive (XmlType.string, "InternalGrades"))), (Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" XmlType.string none True) (Value.primitive (XmlType.string, "View")))]]] none EffectType.permit [] [])))
def compiled_Assignp100_metadata := ((PolicyElement.Policy (Policy.mk RuleCombinatorAlgorithm.legacy_permit_overrides [] [] [])))
def compiled_PPSFaculty100_metadata := ((PolicyElement.PolicySet (PolicySet.mk PolicyCombinatorAlgorithm.legacy_permit_overrides [] [] [])))
def compiled_gradeAsgnAssigngrades_element := ((ElementTree.Node compiled_gradeAsgnAssigngrades_metadata []))
def compiled_Assignp100_element := ((ElementTree.Node compiled_Assignp100_metadata [compiled_gradeAsgnAssigngrades_element]))
def compiled_PPSFaculty100_element := ((ElementTree.Node compiled_PPSFaculty100_metadata [compiled_Assignp100_element]))
-- root element: compiled_PPSFaculty100_element
def compiled_gradedViewgrades_metadata := ((PolicyElement.Rule (Rule.mk [[[(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" XmlType.string none True) (Value.primitive (XmlType.string, "ExternalGrades"))), (Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" XmlType.string none True) (Value.primitive (XmlType.string, "Receive")))]]] none EffectType.permit [] [])))
def compiled_gradedp100_metadata := ((PolicyElement.Policy (Policy.mk RuleCombinatorAlgorithm.legacy_permit_overrides [] [] [])))
def compiled_PPSStudent100_metadata := ((PolicyElement.PolicySet (PolicySet.mk PolicyCombinatorAlgorithm.legacy_permit_overrides [] [] [])))
def compiled_gradedViewgrades_element := ((ElementTree.Node compiled_gradedViewgrades_metadata []))
def compiled_gradedp100_element := ((ElementTree.Node compiled_gradedp100_metadata [compiled_gradedViewgrades_element]))
def compiled_PPSStudent100_element := ((ElementTree.Node compiled_PPSStudent100_metadata [compiled_gradedp100_element]))
-- root element: compiled_PPSStudent100_element
def compiled_RPSFaculty100_metadata := ((PolicyElement.PolicySet (PolicySet.mk PolicyCombinatorAlgorithm.legacy_permit_overrides [[[(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" XmlType.string none True) (Value.primitive (XmlType.string, "Faculty")))]]] [] [])))
def compiled_RPSFaculty100_element := ((ElementTree.Node compiled_RPSFaculty100_metadata [compiled_PPSFaculty100_element]))
-- root element: compiled_RPSFaculty100_element
def compiled_RPSStudent100_metadata := ((PolicyElement.PolicySet (PolicySet.mk PolicyCombinatorAlgorithm.legacy_permit_overrides [[[(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" XmlType.string none True) (Value.primitive (XmlType.string, "Student")))]]] [] [])))
def compiled_RPSStudent100_element := ((ElementTree.Node compiled_RPSStudent100_metadata [compiled_PPSStudent100_element]))
-- root element: compiled_RPSStudent100_element
def compiled_RPSlist100_metadata := ((PolicyElement.PolicySet (PolicySet.mk PolicyCombinatorAlgorithm.legacy_permit_overrides [] [] [])))
def compiled_RPSlist100_element := ((ElementTree.Node compiled_RPSlist100_metadata [compiled_RPSFaculty100_element, compiled_RPSStudent100_element]))
-- root element: compiled_RPSlist100_element
def compiled_gradeAsgnAssigngrades_metadata' := ((PolicyElement.Rule (Rule.mk [[[(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" XmlType.string none True) (Value.primitive (XmlType.string, "ExternalGrades"))), (Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" XmlType.string none True) (Value.primitive (XmlType.string, "Assign")))], [(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" XmlType.string none True) (Value.primitive (XmlType.string, "InternalGrades"))), (Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" XmlType.string none True) (Value.primitive (XmlType.string, "Assign")))], [(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" XmlType.string none True) (Value.primitive (XmlType.string, "ExternalGrades"))), (Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" XmlType.string none True) (Value.primitive (XmlType.string, "View")))], [(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" XmlType.string none True) (Value.primitive (XmlType.string, "InternalGrades"))), (Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" XmlType.string none True) (Value.primitive (XmlType.string, "View")))]]] none EffectType.permit [] [])))
def compiled_Assignp100_metadata' := ((PolicyElement.Policy (Policy.mk RuleCombinatorAlgorithm.legacy_permit_overrides [] [] [])))
def compiled_PPSFaculty100_metadata' := ((PolicyElement.PolicySet (PolicySet.mk PolicyCombinatorAlgorithm.legacy_permit_overrides [] [] [])))
def compiled_gradeAsgnAssigngrades_element' := ((ElementTree.Node compiled_gradeAsgnAssigngrades_metadata []))
def compiled_Assignp100_element' := ((ElementTree.Node compiled_Assignp100_metadata [compiled_gradeAsgnAssigngrades_element]))
def compiled_PPSFaculty100_element' := ((ElementTree.Node compiled_PPSFaculty100_metadata [compiled_Assignp100_element]))
-- root element: compiled_PPSFaculty100_element
def compiled_gradedViewgrades_metadata' := ((PolicyElement.Rule (Rule.mk [[[(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" XmlType.string none True) (Value.primitive (XmlType.string, "ExternalGrades"))), (Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" XmlType.string none True) (Value.primitive (XmlType.string, "Receive")))]]] none EffectType.permit [] [])))
def compiled_gradedp100_metadata' := ((PolicyElement.Policy (Policy.mk RuleCombinatorAlgorithm.legacy_permit_overrides [] [] [])))
def compiled_PPSStudent100_metadata' := ((PolicyElement.PolicySet (PolicySet.mk PolicyCombinatorAlgorithm.legacy_permit_overrides [] [] [])))
def compiled_gradedViewgrades_element' := ((ElementTree.Node compiled_gradedViewgrades_metadata []))
def compiled_gradedp100_element' := ((ElementTree.Node compiled_gradedp100_metadata [compiled_gradedViewgrades_element]))
def compiled_PPSStudent100_element' := ((ElementTree.Node compiled_PPSStudent100_metadata [compiled_gradedp100_element]))
-- root element: compiled_PPSStudent100_element
def compiled_PPSTA100_metadata' := ((PolicyElement.PolicySet (PolicySet.mk PolicyCombinatorAlgorithm.legacy_permit_overrides [] [] [])))
def compiled_PPSTA100_element' := ((ElementTree.Node compiled_PPSTA100_metadata' [compiled_Assignp100_element]))
-- root element: compiled_PPSTA100_element
def compiled_RPSFaculty100_metadata' := ((PolicyElement.PolicySet (PolicySet.mk PolicyCombinatorAlgorithm.legacy_permit_overrides [[[(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" XmlType.string none True) (Value.primitive (XmlType.string, "Faculty")))]]] [] [])))
def compiled_RPSFaculty100_element' := ((ElementTree.Node compiled_RPSFaculty100_metadata [compiled_PPSFaculty100_element]))
-- root element: compiled_RPSFaculty100_element
def compiled_RPSStudent100_metadata' := ((PolicyElement.PolicySet (PolicySet.mk PolicyCombinatorAlgorithm.legacy_permit_overrides [[[(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" XmlType.string none True) (Value.primitive (XmlType.string, "Student")))]]] [] [])))
def compiled_RPSStudent100_element' := ((ElementTree.Node compiled_RPSStudent100_metadata [compiled_PPSStudent100_element]))
-- root element: compiled_RPSStudent100_element
def compiled_RPSTA100_metadata' := ((PolicyElement.PolicySet (PolicySet.mk PolicyCombinatorAlgorithm.legacy_permit_overrides [[[(Match.mk "urn:oasis:names:tc:xacml:1.0:function:string-equal" (AttributeDesignator.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" XmlType.string none True) (Value.primitive (XmlType.string, "TA")))]]] [] [])))
def compiled_RPSTA100_element' := ((ElementTree.Node compiled_RPSTA100_metadata' [compiled_PPSTA100_element']))
-- root element: compiled_RPSTA100_element
def compiled_RPSlist100_metadata' := ((PolicyElement.PolicySet (PolicySet.mk PolicyCombinatorAlgorithm.legacy_permit_overrides [] [] [])))
def compiled_RPSlist100_element' := ((ElementTree.Node compiled_RPSlist100_metadata [compiled_RPSFaculty100_element, compiled_RPSStudent100_element, compiled_RPSTA100_element']))
-- root element: compiled_RPSlist100_element
def separation_of_duty (req : Request) :=
∀ (role : String),
req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, role))
→ ∀ (role' : String),
req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, role'))
↔ role = role'
theorem pr :
∀ (req : Request),
separation_of_duty req
→ req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:resource" "resource-class" none (XmlType.string, "ExternalGrades"))
→ (ElementTree.eval req compiled_RPSlist100_element).fst == (ElementTree.eval req compiled_RPSlist100_element').fst := by
intros req hsod h
cases Classical.em (req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:subject" "role" none (XmlType.string, "Student"))) with
| inl h' =>
cases Classical.em (req.contains (Attribute.mk "urn:oasis:names:tc:xacml:3.0:attribute-category:action" "command" none (XmlType.string, "Receive"))) with
| inl h'' => sorry
| inr h'' => sorry
| inr h' => sorry
|