1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | Setup access policy attribute rules |
---|
5 | |
---|
6 | cmd1:env keystore=`pwd` ./attr.py |
---|
7 | |
---|
8 | """ |
---|
9 | |
---|
10 | import os |
---|
11 | import ABAC |
---|
12 | |
---|
13 | keystore=os.environ["keystore"] |
---|
14 | |
---|
15 | ctxt = ABAC.Context() |
---|
16 | print "ABAC version %s" % ctxt.version() |
---|
17 | |
---|
18 | ctxt.load_directory(keystore) |
---|
19 | |
---|
20 | out = ctxt.context_principals() |
---|
21 | print "...initial principal set..." |
---|
22 | for x in out[1]: |
---|
23 | print "%s " % x.string() |
---|
24 | print "\n" |
---|
25 | |
---|
26 | out = ctxt.context_credentials() |
---|
27 | print "...initial policy attribute set..." |
---|
28 | for c in out[1]: |
---|
29 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
30 | print "\n" |
---|
31 | |
---|
32 | stateUID=ABAC.ID("StateU_ID.pem") |
---|
33 | stateUID.id_load_privkey_file("StateU_private.pem") |
---|
34 | stateU=stateUID.id_keyid() |
---|
35 | |
---|
36 | bobID=ABAC.ID("Bob_ID.pem") |
---|
37 | bobID.id_load_privkey_file("Bob_private.pem") |
---|
38 | bob=bobID.id_keyid() |
---|
39 | |
---|
40 | markID=ABAC.ID("Mark_ID.pem") |
---|
41 | markID.id_load_privkey_file("Mark_private.pem") |
---|
42 | mark=markID.id_keyid() |
---|
43 | |
---|
44 | joeID=ABAC.ID("Joe_ID.pem") |
---|
45 | joeID.id_load_privkey_file("Joe_private.pem") |
---|
46 | joe=joeID.id_keyid() |
---|
47 | |
---|
48 | maryannID=ABAC.ID("Maryann_ID.pem") |
---|
49 | maryannID.id_load_privkey_file("Maryann_private.pem") |
---|
50 | maryann=maryannID.id_keyid() |
---|
51 | |
---|
52 | janID=ABAC.ID("Jan_ID.pem") |
---|
53 | janID.id_load_privkey_file("Jan_private.pem") |
---|
54 | jan=janID.id_keyid() |
---|
55 | |
---|
56 | |
---|
57 | ################################################ |
---|
58 | # [keyid:stateU].role:foundingAlumni |
---|
59 | # <- [keyid:stateU].role:diploma([string:?D:['mathmatics','psychology']], |
---|
60 | # [integer:?Year:[1960,1961,1963]]) |
---|
61 | head = ABAC.Role(stateU,"foundingAlumni") |
---|
62 | cond=ABAC.Constraint("string") |
---|
63 | cond.constraint_add_string_target("'mathmatics'") |
---|
64 | cond.constraint_add_string_target("'psychology'") |
---|
65 | param1=ABAC.DataTerm("string", "D", cond) |
---|
66 | cond=ABAC.Constraint("integer") |
---|
67 | cond.constraint_add_integer_target(1960) |
---|
68 | cond.constraint_add_integer_target(1961) |
---|
69 | cond.constraint_add_integer_target(1963) |
---|
70 | param2=ABAC.DataTerm("integer", "Year", cond) |
---|
71 | tail = ABAC.Role(stateU,"diploma") |
---|
72 | tail.role_add_data_term(param1) |
---|
73 | tail.role_add_data_term(param2) |
---|
74 | attr=ABAC.Attribute(head, 1800) |
---|
75 | attr.attribute_add_tail(tail) |
---|
76 | attr.attribute_bake() |
---|
77 | attr.attribute_write_cert("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der") |
---|
78 | ctxt.load_attribute_file("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der") |
---|
79 | print attr.string() |
---|
80 | print attr.typed_string() |
---|
81 | print "\n" |
---|
82 | |
---|
83 | ################################################# |
---|
84 | # [keyid:stateU].role:diploma([string:'mathmatics'],[integer:1961]) <- [keyid:bob] |
---|
85 | param1=ABAC.DataTerm("string", "'mathmatics'") |
---|
86 | param2=ABAC.DataTerm("integer", "1961") |
---|
87 | head = ABAC.Role(stateU,"diploma") |
---|
88 | head.role_add_data_term(param1) |
---|
89 | head.role_add_data_term(param2) |
---|
90 | tail = ABAC.Role(bob) |
---|
91 | attr=ABAC.Attribute(head, 1800) |
---|
92 | attr.attribute_add_tail(tail) |
---|
93 | attr.attribute_bake() |
---|
94 | attr.attribute_write_cert("StateU_diploma_m__Bob_attr.der") |
---|
95 | ctxt.load_attribute_file("StateU_diploma_m__Bob_attr.der") |
---|
96 | print attr.string() |
---|
97 | print attr.typed_string() |
---|
98 | print "\n" |
---|
99 | |
---|
100 | ################################################# |
---|
101 | # [keyid:stateU].role:diploma([string:'mathmatics'],[integer:1965]) <- [keyid:mark] |
---|
102 | param1=ABAC.DataTerm("string", "'mathmatics'") |
---|
103 | param2=ABAC.DataTerm("integer", "1965") |
---|
104 | head = ABAC.Role(stateU,"diploma") |
---|
105 | head.role_add_data_term(param1) |
---|
106 | head.role_add_data_term(param2) |
---|
107 | tail = ABAC.Role(mark) |
---|
108 | attr=ABAC.Attribute(head, 1800) |
---|
109 | attr.attribute_add_tail(tail) |
---|
110 | attr.attribute_bake() |
---|
111 | attr.attribute_write_cert("StateU_diploma_m__Mark_attr.der") |
---|
112 | ctxt.load_attribute_file("StateU_diploma_m__Mark_attr.der") |
---|
113 | print attr.string() |
---|
114 | print attr.typed_string() |
---|
115 | print "\n" |
---|
116 | |
---|
117 | ################################################# |
---|
118 | # [keyid:stateU].role:diploma([string:'zoology'],[integer:1961]) <- [keyid:joe] |
---|
119 | param1=ABAC.DataTerm("string", "'zoology'") |
---|
120 | param2=ABAC.DataTerm("integer", "1961") |
---|
121 | head = ABAC.Role(stateU,"diploma") |
---|
122 | head.role_add_data_term(param1) |
---|
123 | head.role_add_data_term(param2) |
---|
124 | tail = ABAC.Role(joe) |
---|
125 | attr=ABAC.Attribute(head, 1800) |
---|
126 | attr.attribute_add_tail(tail) |
---|
127 | attr.attribute_bake() |
---|
128 | attr.attribute_write_cert("StateU_diploma_z__Joe_attr.der") |
---|
129 | ctxt.load_attribute_file("StateU_diploma_z__Joe_attr.der") |
---|
130 | print attr.string() |
---|
131 | print attr.typed_string() |
---|
132 | print "\n" |
---|
133 | |
---|
134 | ################################################# |
---|
135 | # [keyid:stateU].role:diploma([string:'psychology'],[integer:1962]) <- [keyid:maryann] |
---|
136 | param1=ABAC.DataTerm("string", "'psychology'") |
---|
137 | param2=ABAC.DataTerm("integer", "1962") |
---|
138 | head = ABAC.Role(stateU,"diploma") |
---|
139 | head.role_add_data_term(param1) |
---|
140 | head.role_add_data_term(param2) |
---|
141 | tail = ABAC.Role(maryann) |
---|
142 | attr=ABAC.Attribute(head, 1800) |
---|
143 | attr.attribute_add_tail(tail) |
---|
144 | attr.attribute_bake() |
---|
145 | attr.attribute_write_cert("StateU_diploma_p__Maryann_attr.der") |
---|
146 | ctxt.load_attribute_file("StateU_diploma_p__Maryann_attr.der") |
---|
147 | print attr.string() |
---|
148 | print attr.typed_string() |
---|
149 | print "\n" |
---|
150 | |
---|
151 | |
---|
152 | ################################################# |
---|
153 | # [keyid:stateU].role:diploma([string:'psychology'],[integer:1960]) <- [keyid:jan] |
---|
154 | param1=ABAC.DataTerm("string", "'psychology'") |
---|
155 | param2=ABAC.DataTerm("integer", "1960") |
---|
156 | head = ABAC.Role(stateU,"diploma") |
---|
157 | head.role_add_data_term(param1) |
---|
158 | head.role_add_data_term(param2) |
---|
159 | tail = ABAC.Role(jan) |
---|
160 | attr=ABAC.Attribute(head, 1800) |
---|
161 | attr.attribute_add_tail(tail) |
---|
162 | attr.attribute_bake() |
---|
163 | attr.attribute_write_cert("StateU_diploma_p__Jan_attr.der") |
---|
164 | ctxt.load_attribute_file("StateU_diploma_p__Maryann_attr.der") |
---|
165 | print attr.string() |
---|
166 | print attr.typed_string() |
---|
167 | print "\n" |
---|
168 | |
---|
169 | |
---|
170 | ctxt.dump_yap_db() |
---|
171 | ## |
---|