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 | leagueID=ABAC.ID("League_ID.pem"); |
---|
30 | leagueID.id_load_privkey_file("League_private.pem"); |
---|
31 | league=leagueID.id_keyid() |
---|
32 | |
---|
33 | johnID=ABAC.ID("John_ID.pem"); |
---|
34 | johnID.id_load_privkey_file("John_private.pem"); |
---|
35 | john=johnID.id_keyid() |
---|
36 | |
---|
37 | markID=ABAC.ID("Mark_ID.pem"); |
---|
38 | markID.id_load_privkey_file("Mark_private.pem"); |
---|
39 | mark=markID.id_keyid() |
---|
40 | |
---|
41 | ################################################ |
---|
42 | #[keyid:league].role:stadium([string:'access'],[boolean:true], |
---|
43 | # [time:?F:[keyid:league].oset.gametime([string:?T])]) |
---|
44 | # <-[keyid:league].role:players([string:?T]) |
---|
45 | param1=ABAC.DataTerm("string","'access'") |
---|
46 | param2=ABAC.DataTerm("boolean","true") |
---|
47 | |
---|
48 | param=ABAC.DataTerm("string","T") |
---|
49 | condoset=ABAC.Oset(league,"gametime") |
---|
50 | condoset.oset_add_data_term(param) |
---|
51 | cond=ABAC.Constraint(condoset) |
---|
52 | param3=ABAC.DataTerm("time", "F", cond) |
---|
53 | head = ABAC.Role(league,"stadium") |
---|
54 | head.role_add_data_term(param1) |
---|
55 | head.role_add_data_term(param2) |
---|
56 | head.role_add_data_term(param3) |
---|
57 | |
---|
58 | param=ABAC.DataTerm("string", "T") |
---|
59 | tail = ABAC.Role(league,"players") |
---|
60 | tail.role_add_data_term(param) |
---|
61 | attr=ABAC.Attribute(head, 1800) |
---|
62 | attr.attribute_add_tail(tail) |
---|
63 | attr.attribute_bake() |
---|
64 | attr.attribute_write_cert("League_access_qFqT__League_players_qT_attr.der") |
---|
65 | ctxt.load_attribute_file("League_access_qFqT__League_players_qT_attr.der") |
---|
66 | print attr.string() |
---|
67 | print attr.typed_string() |
---|
68 | print "\n" |
---|
69 | |
---|
70 | ################################################ |
---|
71 | # ??? not sure if this is a valid policy |
---|
72 | #[keyid:league].role:stadium([string:'access'],[boolean:?B:[true], |
---|
73 | # [time:?F:[20120228T080000..20120228T090000]]) |
---|
74 | # <- [keyid:league].role:players(string:?T) |
---|
75 | param1=ABAC.DataTerm("string","'access'") |
---|
76 | cond=ABAC.Constraint("boolean") |
---|
77 | cond.constraint_add_boolean_target("true") |
---|
78 | param2=ABAC.DataTerm("boolean", "B", cond) |
---|
79 | cond=ABAC.Constraint("time") |
---|
80 | cond.constraint_add_time_min("20120228T080000") |
---|
81 | cond.constraint_add_time_max("20120228T090000") |
---|
82 | param3=ABAC.DataTerm("time", "F", cond) |
---|
83 | head = ABAC.Role(league,"stadium") |
---|
84 | head.role_add_data_term(param1) |
---|
85 | head.role_add_data_term(param2) |
---|
86 | head.role_add_data_term(param3) |
---|
87 | |
---|
88 | param=ABAC.DataTerm("string", "T") |
---|
89 | tail = ABAC.Role(league,"players") |
---|
90 | tail.role_add_data_term(param) |
---|
91 | |
---|
92 | attr=ABAC.Attribute(head, 1800) |
---|
93 | attr.attribute_add_tail(tail) |
---|
94 | attr.attribute_bake() |
---|
95 | attr.attribute_write_cert("League_access_qR__League_players_qT_attr.der") |
---|
96 | ctxt.load_attribute_file("League_access_qR__League_players_qT_attr.der") |
---|
97 | print attr.string() |
---|
98 | print attr.typed_string() |
---|
99 | print "\n" |
---|
100 | |
---|
101 | ################################################# |
---|
102 | # [keyid:league].oset:gametime([string:'north']) |
---|
103 | # <- [time:20120228T130000] |
---|
104 | param=ABAC.DataTerm("string","'north'") |
---|
105 | head = ABAC.Oset(league,"gametime") |
---|
106 | head.oset_add_data_term(param) |
---|
107 | term=ABAC.DataTerm("time", "20120228T130000") |
---|
108 | tail = ABAC.Oset(term) |
---|
109 | attr=ABAC.Attribute(head, 1800) |
---|
110 | attr.attribute_add_tail(tail) |
---|
111 | attr.attribute_bake() |
---|
112 | attr.attribute_write_cert("League_gametime_north__timeT_attr.der") |
---|
113 | ctxt.load_attribute_file("League_gametime_north__timeT_attr.der") |
---|
114 | print attr.string() |
---|
115 | print attr.typed_string() |
---|
116 | print "\n" |
---|
117 | |
---|
118 | ################################################# |
---|
119 | # [keyid:league].oset:gametime([string:'south']) |
---|
120 | # <-[time:20120228T140000] |
---|
121 | param=ABAC.DataTerm("string","'south'") |
---|
122 | head = ABAC.Oset(league,"gametime") |
---|
123 | head.oset_add_data_term(param) |
---|
124 | term=ABAC.DataTerm("time", "20120228T140000") |
---|
125 | tail = ABAC.Oset(term) |
---|
126 | attr=ABAC.Attribute(head, 1800) |
---|
127 | attr.attribute_add_tail(tail) |
---|
128 | attr.attribute_bake() |
---|
129 | attr.attribute_write_cert("League_gametime_south__time2T_attr.der") |
---|
130 | ctxt.load_attribute_file("League_gametime_south__time2T_attr.der") |
---|
131 | print attr.string() |
---|
132 | print attr.typed_string() |
---|
133 | print "\n" |
---|
134 | |
---|
135 | ################################################# |
---|
136 | # [keyid:league].role:players([string:'north'])<-[keyid:John] |
---|
137 | param=ABAC.DataTerm("string", "'north'") |
---|
138 | head = ABAC.Role(league,"players") |
---|
139 | head.role_add_data_term(param) |
---|
140 | tail = ABAC.Role(john) |
---|
141 | attr=ABAC.Attribute(head, 1800) |
---|
142 | attr.attribute_add_tail(tail) |
---|
143 | attr.attribute_bake() |
---|
144 | attr.attribute_write_cert("League_players_north__John_attr.der") |
---|
145 | ctxt.load_attribute_file("League_players_north__John_attr.der") |
---|
146 | print attr.string() |
---|
147 | print attr.typed_string() |
---|
148 | print "\n" |
---|
149 | |
---|
150 | ################################################# |
---|
151 | # [keyid:league].role:players([string:'south'])<-[keyid:Mark] |
---|
152 | param=ABAC.DataTerm("string", "'south'") |
---|
153 | head = ABAC.Role(league,"players") |
---|
154 | head.role_add_data_term(param) |
---|
155 | tail = ABAC.Role(mark) |
---|
156 | attr=ABAC.Attribute(head, 1800) |
---|
157 | attr.attribute_add_tail(tail) |
---|
158 | attr.attribute_bake() |
---|
159 | attr.attribute_write_cert("League_players_south__Mark_attr.der") |
---|
160 | ctxt.load_attribute_file("League_players_north__John_attr.der") |
---|
161 | print attr.string() |
---|
162 | print attr.typed_string() |
---|
163 | print "\n" |
---|
164 | |
---|
165 | |
---|
166 | ctxt.dump_yap_db() |
---|
167 | ## |
---|