1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | cmd1:env keystore=`pwd` ./attr.py |
---|
5 | """ |
---|
6 | |
---|
7 | import os |
---|
8 | import ABAC |
---|
9 | |
---|
10 | keystore=os.environ["keystore"] |
---|
11 | |
---|
12 | ctxt = ABAC.Context() |
---|
13 | print "ABAC version %s" % ctxt.version() |
---|
14 | |
---|
15 | ctxt.load_directory(keystore) |
---|
16 | |
---|
17 | out = ctxt.context_principals() |
---|
18 | print "...initial principal set..." |
---|
19 | for x in out[1]: |
---|
20 | print "%s " % x.string() |
---|
21 | print "\n" |
---|
22 | |
---|
23 | out = ctxt.context_credentials() |
---|
24 | print "...initial policy attribute set..." |
---|
25 | for c in out[1]: |
---|
26 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
27 | print "\n" |
---|
28 | |
---|
29 | ralphsID=ABAC.ID("Ralphs_ID.pem"); |
---|
30 | ralphsID.id_load_privkey_file("Ralphs_private.pem"); |
---|
31 | ralphs=ralphsID.id_keyid() |
---|
32 | |
---|
33 | bobID=ABAC.ID("Bob_ID.pem"); |
---|
34 | bobID.id_load_privkey_file("Bob_private.pem"); |
---|
35 | bob=bobID.id_keyid() |
---|
36 | |
---|
37 | maryID=ABAC.ID("Mary_ID.pem"); |
---|
38 | maryID.id_load_privkey_file("Mary_private.pem"); |
---|
39 | mary=maryID.id_keyid() |
---|
40 | |
---|
41 | ################################################ |
---|
42 | # [keyid:mary].oset:what2eat |
---|
43 | # <- [keyid:ralphs].oset:fruitprice([float:?P:[..2.00]]) |
---|
44 | # [keyid:alpha].role:access([string:'Read'],[urn:'file//fileB']) <- [keyid:bob] |
---|
45 | head = ABAC.Oset(mary,"what2eat") |
---|
46 | cond=ABAC.Constraint("float") |
---|
47 | cond.constraint_add_float_max(2.00) |
---|
48 | param=ABAC.DataTerm("float", "P", cond) |
---|
49 | tail = ABAC.Oset(ralphs,"fruitprice") |
---|
50 | tail.oset_add_data_term(param) |
---|
51 | attr=ABAC.Attribute(head, 1800) |
---|
52 | attr.attribute_add_tail(tail) |
---|
53 | attr.attribute_bake() |
---|
54 | attr.attribute_write_cert("mary_what2eat__ralphs_fruitprice_qP_attr.der") |
---|
55 | ctxt.load_attribute_file("mary_what2eat__ralphs_fruitprice_qP_attr.der") |
---|
56 | print attr.string() |
---|
57 | print attr.typed_string() |
---|
58 | print "\n" |
---|
59 | |
---|
60 | ################################################ |
---|
61 | # [keyid:bob].oset:what2eat |
---|
62 | # <- [keyid:ralphs].oset:fruitprice([float:?P:[1.00..5.00]]) |
---|
63 | head = ABAC.Oset(bob,"what2eat") |
---|
64 | cond=ABAC.Constraint("float") |
---|
65 | cond.constraint_add_float_min(1.00) |
---|
66 | cond.constraint_add_float_max(5.00) |
---|
67 | print cond.typed_string() |
---|
68 | param=ABAC.DataTerm("float", "P", cond) |
---|
69 | tail = ABAC.Oset(ralphs,"fruitprice") |
---|
70 | tail.oset_add_data_term(param) |
---|
71 | attr=ABAC.Attribute(head, 1800) |
---|
72 | attr.attribute_add_tail(tail) |
---|
73 | attr.attribute_bake() |
---|
74 | attr.attribute_write_cert("bob_what2eat__ralphs_fruitprice_qP_attr.der") |
---|
75 | ctxt.load_attribute_file("bob_what2eat__ralphs_fruitprice_qP_attr.der") |
---|
76 | print attr.string() |
---|
77 | print attr.typed_string() |
---|
78 | print "\n" |
---|
79 | |
---|
80 | ################################################# |
---|
81 | # [keyid:ralphs].oset:fruitprice([float:1.50]) <- [string:'apple'] |
---|
82 | param=ABAC.DataTerm("float", "1.50") |
---|
83 | head = ABAC.Oset(ralphs,"fruitprice") |
---|
84 | head.oset_add_data_term(param) |
---|
85 | param=ABAC.DataTerm("string", "'apple'") |
---|
86 | tail = ABAC.Oset(param) |
---|
87 | attr=ABAC.Attribute(head, 1800) |
---|
88 | attr.attribute_add_tail(tail) |
---|
89 | attr.attribute_bake() |
---|
90 | attr.attribute_write_cert("Ralphs_fruitprice__apple_attr.der") |
---|
91 | ctxt.load_attribute_file("Ralphs_fruitprice__apple_attr.der") |
---|
92 | print attr.string() |
---|
93 | print attr.typed_string() |
---|
94 | print "\n" |
---|
95 | |
---|
96 | ################################################# |
---|
97 | # [keyid:ralphs].oset:fruitprice([float:1.50]) <- [string:'kiwi'] |
---|
98 | param=ABAC.DataTerm("float", "1.50") |
---|
99 | head = ABAC.Oset(ralphs,"fruitprice") |
---|
100 | head.oset_add_data_term(param) |
---|
101 | param=ABAC.DataTerm("string", "'kiwi'") |
---|
102 | tail = ABAC.Oset(param) |
---|
103 | attr=ABAC.Attribute(head, 1800) |
---|
104 | attr.attribute_add_tail(tail) |
---|
105 | attr.attribute_bake() |
---|
106 | attr.attribute_write_cert("Ralphs_fruitprice__kiwi_attr.der") |
---|
107 | ctxt.load_attribute_file("Ralphs_fruitprice__kiwi_attr.der") |
---|
108 | print attr.string() |
---|
109 | print attr.typed_string() |
---|
110 | print "\n" |
---|
111 | |
---|
112 | ################################################# |
---|
113 | # [keyid:ralphs].oset:fruitprice([float:2.50]) <- [string:'black berry'] |
---|
114 | param=ABAC.DataTerm("float", "2.50") |
---|
115 | head = ABAC.Oset(ralphs,"fruitprice") |
---|
116 | head.oset_add_data_term(param) |
---|
117 | param=ABAC.DataTerm("string", "'black berry'") |
---|
118 | tail = ABAC.Oset(param) |
---|
119 | attr=ABAC.Attribute(head, 1800) |
---|
120 | attr.attribute_add_tail(tail) |
---|
121 | attr.attribute_bake() |
---|
122 | attr.attribute_write_cert("Ralphs_fruitprice__blackberry_attr.der") |
---|
123 | ctxt.load_attribute_file("Ralphs_fruitprice__blackberry_attr.der") |
---|
124 | print attr.string() |
---|
125 | print attr.typed_string() |
---|
126 | print "\n" |
---|
127 | |
---|
128 | ################################################# |
---|
129 | # [keyid:ralphs].oset:fruitprice([float:0.50]) <- [string:'navel orange'] |
---|
130 | param=ABAC.DataTerm("float", "0.50") |
---|
131 | head = ABAC.Oset(ralphs,"fruitprice") |
---|
132 | head.oset_add_data_term(param) |
---|
133 | param=ABAC.DataTerm("string", "'navel orange'") |
---|
134 | tail = ABAC.Oset(param) |
---|
135 | attr=ABAC.Attribute(head, 1800) |
---|
136 | attr.attribute_add_tail(tail) |
---|
137 | attr.attribute_bake() |
---|
138 | attr.attribute_write_cert("Ralphs_fruitprice__navelorange_attr.der") |
---|
139 | ctxt.load_attribute_file("Ralphs_fruitprice__navelorange_attr.der") |
---|
140 | print attr.string() |
---|
141 | print attr.typed_string() |
---|
142 | print "\n" |
---|
143 | |
---|
144 | ## |
---|
145 | ctxt.dump_yap_db() |
---|
146 | ## |
---|