1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | to test with python |
---|
5 | |
---|
6 | cmd1:env keystore=`pwd` ./attr.py |
---|
7 | """ |
---|
8 | |
---|
9 | import os |
---|
10 | import ABAC |
---|
11 | |
---|
12 | keystore=os.environ["keystore"] |
---|
13 | |
---|
14 | ctxt = ABAC.Context() |
---|
15 | print "ABAC version %s" % ctxt.version() |
---|
16 | |
---|
17 | ctxt.load_directory(keystore) |
---|
18 | |
---|
19 | out = ctxt.context_principals() |
---|
20 | print "...initial principal set..." |
---|
21 | for x in out[1]: |
---|
22 | print "%s " % x.string() |
---|
23 | print "\n" |
---|
24 | |
---|
25 | out = ctxt.context_credentials() |
---|
26 | print "...initial policy attribute set..." |
---|
27 | for c in out[1]: |
---|
28 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
29 | print "\n" |
---|
30 | |
---|
31 | geniID=ABAC.ID("Geni_ID.pem"); |
---|
32 | geniID.id_load_privkey_file("Geni_private.pem"); |
---|
33 | geni=geniID.id_keyid() |
---|
34 | |
---|
35 | bobID=ABAC.ID("Bob_ID.pem"); |
---|
36 | bobID.id_load_privkey_file("Bob_private.pem"); |
---|
37 | bob=bobID.id_keyid() |
---|
38 | |
---|
39 | jackID=ABAC.ID("Jack_ID.pem"); |
---|
40 | jackID.id_load_privkey_file("Jack_private.pem"); |
---|
41 | jack=jackID.id_keyid() |
---|
42 | |
---|
43 | joeID=ABAC.ID("Joe_ID.pem"); |
---|
44 | joeID.id_load_privkey_file("Joe_private.pem"); |
---|
45 | joe=joeID.id_keyid() |
---|
46 | |
---|
47 | ################################################ |
---|
48 | # [keyid:geni].role:leader |
---|
49 | # <- [keyid:geni].role:equivalent([principal:?P[keyid:geni].role:leader]) |
---|
50 | head=ABAC.Role(geni,"leader") |
---|
51 | condoset=ABAC.Role(geni,"leader") |
---|
52 | cond=ABAC.Constraint(condoset) |
---|
53 | param=ABAC.DataTerm("principal","P", cond) |
---|
54 | tail = ABAC.Role(geni,"equivalent") |
---|
55 | tail.role_add_data_term(param) |
---|
56 | attr=ABAC.Attribute(head, 1800) |
---|
57 | attr.attribute_add_tail(tail) |
---|
58 | attr.attribute_bake() |
---|
59 | attr.attribute_write_cert("geni_leader__geni_leader_qP_attr.der") |
---|
60 | ctxt.load_attribute_file("geni_leader__geni_leader_qP_attr.der") |
---|
61 | print attr.string() |
---|
62 | print attr.typed_string() |
---|
63 | print "\n" |
---|
64 | |
---|
65 | ################################################# |
---|
66 | # [keyid:geni].role:leader <- [keyid:bob] |
---|
67 | head=ABAC.Role(geni,"leader") |
---|
68 | tail = ABAC.Role(bob) |
---|
69 | attr=ABAC.Attribute(head, 1800) |
---|
70 | attr.attribute_add_tail(tail) |
---|
71 | attr.attribute_bake() |
---|
72 | attr.attribute_write_cert("geni_leader__Bob_attr.der") |
---|
73 | ctxt.load_attribute_file("geni_leader__Bob_attr.der") |
---|
74 | print attr.string() |
---|
75 | print attr.typed_string() |
---|
76 | print "\n" |
---|
77 | |
---|
78 | ################################################# |
---|
79 | # [keyid:geni].role:equivalent([keyid:bob]) <- [keyid:Joe] |
---|
80 | param=ABAC.DataTerm(bobID) |
---|
81 | head = ABAC.Role(geni,"equivalent") |
---|
82 | head.role_add_data_term(param) |
---|
83 | tail = ABAC.Role(joe) |
---|
84 | attr=ABAC.Attribute(head, 1800) |
---|
85 | attr.attribute_add_tail(tail) |
---|
86 | attr.attribute_bake() |
---|
87 | attr.attribute_write_cert("geni_equivalent_Bob__Joe_attr.der") |
---|
88 | ctxt.load_attribute_file("geni_equivalent_Bob__Joe_attr.der") |
---|
89 | print attr.string() |
---|
90 | print attr.typed_string() |
---|
91 | print "\n" |
---|
92 | |
---|
93 | ################################################# |
---|
94 | # [keyid:geni].role:equivalent([keyid:Joe]) <- [keyid:Bob] |
---|
95 | param=ABAC.DataTerm(joeID) |
---|
96 | head = ABAC.Role(geni,"equivalent") |
---|
97 | head.role_add_data_term(param) |
---|
98 | tail = ABAC.Role(bob) |
---|
99 | attr=ABAC.Attribute(head, 1800) |
---|
100 | attr.attribute_add_tail(tail) |
---|
101 | attr.attribute_bake() |
---|
102 | attr.attribute_write_cert("geni_equivalent_Joe__Bob_attr.der") |
---|
103 | ctxt.load_attribute_file("geni_equivalent_Joe__Bob_attr.der") |
---|
104 | print attr.string() |
---|
105 | print attr.typed_string() |
---|
106 | print "\n" |
---|
107 | |
---|
108 | ################################################# |
---|
109 | # [keyid:Bob].role:niceCoworker <- [keyid:Maryann]) |
---|
110 | head = ABAC.Role(bob,"niceCoworker") |
---|
111 | tail = ABAC.Role(jack) |
---|
112 | attr=ABAC.Attribute(head, 1800) |
---|
113 | attr.attribute_add_tail(tail) |
---|
114 | attr.attribute_bake() |
---|
115 | attr.attribute_write_cert("Bob_nicecoworker__Maryann_attr.der") |
---|
116 | ctxt.load_attribute_file("Bob_nicecoworker__Maryann_attr.der") |
---|
117 | print attr.string() |
---|
118 | print attr.typed_string() |
---|
119 | print "\n" |
---|
120 | |
---|
121 | ################################################# |
---|
122 | # [keyid:geni].role:evaluatorOf([keyid:Joe]) <-[keyid:Bob] |
---|
123 | param=ABAC.DataTerm(joeID) |
---|
124 | head = ABAC.Role(geni,"evaluatorOf") |
---|
125 | head.role_add_data_term(param) |
---|
126 | tail = ABAC.Role(bob) |
---|
127 | attr=ABAC.Attribute(head, 1800) |
---|
128 | attr.attribute_add_tail(tail) |
---|
129 | attr.attribute_bake() |
---|
130 | attr.attribute_write_cert("Alpha_evaluator_j__Bob_attr.der") |
---|
131 | ctxt.load_attribute_file("Alpha_evaluator_j__Bob_attr.der") |
---|
132 | print attr.string() |
---|
133 | print attr.typed_string() |
---|
134 | print "\n" |
---|
135 | |
---|
136 | ################################################# |
---|
137 | # [keyid:Bob].role:goodPerformance <- [keyid:Joe]) |
---|
138 | head = ABAC.Role(bob,"goodPerformance") |
---|
139 | tail = ABAC.Role(joe) |
---|
140 | attr=ABAC.Attribute(head, 1800) |
---|
141 | attr.attribute_add_tail(tail) |
---|
142 | attr.attribute_bake() |
---|
143 | attr.attribute_write_cert("Bob_goodperformance__Joe_attr.der") |
---|
144 | ctxt.load_attribute_file("Bob_goodperformance__Joe_attr.der") |
---|
145 | print attr.string() |
---|
146 | print attr.typed_string() |
---|
147 | print "\n" |
---|
148 | |
---|
149 | |
---|
150 | ctxt.dump_yap_db() |
---|
151 | ## |
---|