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 | alphaID=ABAC.ID("Alpha_ID.pem"); |
---|
32 | alphaID.id_load_privkey_file("Alpha_private.pem"); |
---|
33 | alpha=alphaID.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 | maryannID=ABAC.ID("Maryann_ID.pem"); |
---|
40 | maryannID.id_load_privkey_file("Maryann_private.pem"); |
---|
41 | maryann=maryannID.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:alpha].role:payRaise <- |
---|
49 | # [keyid:alpha].role:evaluatorOf([principal:?this]).role:goodPerformance & |
---|
50 | # [keyid:alpha].role:managerOf([principal:?this]).role:niceCoworker |
---|
51 | head=ABAC.Role(alpha,"payRaise") |
---|
52 | param=ABAC.DataTerm("principal", "This") |
---|
53 | tail1 = ABAC.Role(alpha,"evaluatorOf","goodPerformance") |
---|
54 | tail1.role_add_linked_data_term(param) |
---|
55 | param=ABAC.DataTerm("principal", "This") |
---|
56 | tail2 = ABAC.Role(alpha,"managerOf","niceCoworker") |
---|
57 | tail2.role_add_linked_data_term(param) |
---|
58 | attr=ABAC.Attribute(head, 1800) |
---|
59 | attr.attribute_add_tail(tail1) |
---|
60 | attr.attribute_add_tail(tail2) |
---|
61 | attr.attribute_bake() |
---|
62 | attr.attribute_write_cert("Alpha_payraise__Alpha_performance_qT_niceguy_qT_attr.der") |
---|
63 | ctxt.load_attribute_file("Alpha_payraise__Alpha_performance_qT_niceguy_qT_attr.der") |
---|
64 | print attr.string() |
---|
65 | print attr.typed_string() |
---|
66 | print "\n" |
---|
67 | |
---|
68 | ################################################# |
---|
69 | # [keyid:alpha].role:managerOf([principal:?Z])<- |
---|
70 | # [keyid:alpha].role:evaluatorOf([principal:?Z]) |
---|
71 | param=ABAC.DataTerm("principal", "Z") |
---|
72 | head=ABAC.Role(alpha,"managerOf") |
---|
73 | head.role_add_data_term(param) |
---|
74 | param=ABAC.DataTerm("principal", "Z") |
---|
75 | tail = ABAC.Role(alpha,"evaluatorOf") |
---|
76 | tail.role_add_data_term(param) |
---|
77 | attr=ABAC.Attribute(head, 1800) |
---|
78 | attr.attribute_add_tail(tail) |
---|
79 | attr.attribute_bake() |
---|
80 | attr.attribute_write_cert("Alpha_manager_qZ__Alpha_evaluator_qZ_attr.der") |
---|
81 | ctxt.load_attribute_file("Alpha_manager_qZ__Alpha_evaluator_qZ_attr.der") |
---|
82 | print attr.string() |
---|
83 | print attr.typed_string() |
---|
84 | print "\n" |
---|
85 | |
---|
86 | ################################################# |
---|
87 | # [keyid:alpha].role:evaluatorOf([keyid:Maryann]) <-[keyid:Bob] |
---|
88 | param=ABAC.DataTerm(maryannID) |
---|
89 | head = ABAC.Role(alpha,"evaluatorOf") |
---|
90 | head.role_add_data_term(param) |
---|
91 | tail = ABAC.Role(bob) |
---|
92 | attr=ABAC.Attribute(head, 1800) |
---|
93 | attr.attribute_add_tail(tail) |
---|
94 | attr.attribute_bake() |
---|
95 | attr.attribute_write_cert("Alpha_evaluator_m__Bob_attr.der") |
---|
96 | ctxt.load_attribute_file("Alpha_evaluator_m__Bob_attr.der") |
---|
97 | print attr.string() |
---|
98 | print attr.typed_string() |
---|
99 | print "\n" |
---|
100 | |
---|
101 | ################################################# |
---|
102 | # [keyid:Bob].role:goodPerformance <- [keyid:Maryann]) |
---|
103 | head = ABAC.Role(bob,"goodPerformance") |
---|
104 | tail = ABAC.Role(maryann) |
---|
105 | attr=ABAC.Attribute(head, 1800) |
---|
106 | attr.attribute_add_tail(tail) |
---|
107 | attr.attribute_bake() |
---|
108 | attr.attribute_write_cert("Bob_goodperformance__Maryann_attr.der") |
---|
109 | ctxt.load_attribute_file("Bob_goodperformance__Maryann_attr.der") |
---|
110 | print attr.string() |
---|
111 | print attr.typed_string() |
---|
112 | print "\n" |
---|
113 | |
---|
114 | ################################################# |
---|
115 | # [keyid:Bob].role:niceCoworker <- [keyid:Maryann]) |
---|
116 | head = ABAC.Role(bob,"niceCoworker") |
---|
117 | tail = ABAC.Role(maryann) |
---|
118 | attr=ABAC.Attribute(head, 1800) |
---|
119 | attr.attribute_add_tail(tail) |
---|
120 | attr.attribute_bake() |
---|
121 | attr.attribute_write_cert("Bob_nicecoworker__Maryann_attr.der") |
---|
122 | ctxt.load_attribute_file("Bob_nicecoworker__Maryann_attr.der") |
---|
123 | print attr.string() |
---|
124 | print attr.typed_string() |
---|
125 | print "\n" |
---|
126 | |
---|
127 | ################################################# |
---|
128 | # [keyid:alpha].role:evaluatorOf([keyid:Joe]) <-[keyid:Bob] |
---|
129 | param=ABAC.DataTerm(joeID) |
---|
130 | head = ABAC.Role(alpha,"evaluatorOf") |
---|
131 | head.role_add_data_term(param) |
---|
132 | tail = ABAC.Role(bob) |
---|
133 | attr=ABAC.Attribute(head, 1800) |
---|
134 | attr.attribute_add_tail(tail) |
---|
135 | attr.attribute_bake() |
---|
136 | attr.attribute_write_cert("Alpha_evaluator_j__Bob_attr.der") |
---|
137 | ctxt.load_attribute_file("Alpha_evaluator_j__Bob_attr.der") |
---|
138 | print attr.string() |
---|
139 | print attr.typed_string() |
---|
140 | print "\n" |
---|
141 | |
---|
142 | ################################################# |
---|
143 | # [keyid:Bob].role:goodPerformance <- [keyid:Joe]) |
---|
144 | head = ABAC.Role(bob,"goodPerformance") |
---|
145 | tail = ABAC.Role(joe) |
---|
146 | attr=ABAC.Attribute(head, 1800) |
---|
147 | attr.attribute_add_tail(tail) |
---|
148 | attr.attribute_bake() |
---|
149 | attr.attribute_write_cert("Bob_goodperformance__Joe_attr.der") |
---|
150 | ctxt.load_attribute_file("Bob_goodperformance__Joe_attr.der") |
---|
151 | print attr.string() |
---|
152 | print attr.typed_string() |
---|
153 | print "\n" |
---|
154 | |
---|
155 | |
---|
156 | ctxt.dump_yap_db() |
---|
157 | ## |
---|