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 | joeID=ABAC.ID("Joe_ID.pem") |
---|
41 | joeID.id_load_privkey_file("Joe_private.pem") |
---|
42 | joe=joeID.id_keyid() |
---|
43 | |
---|
44 | maryannID=ABAC.ID("Maryann_ID.pem") |
---|
45 | maryannID.id_load_privkey_file("Maryann_private.pem") |
---|
46 | maryann=maryannID.id_keyid() |
---|
47 | |
---|
48 | |
---|
49 | ################################################ |
---|
50 | # [keyid:stateU].role:foundingAlumni |
---|
51 | # <- [keyid:stateU].role:diploma([?], [integer:?Year:[1955 .. 1958]]) |
---|
52 | head = ABAC.Role(stateU,"foundingAlumni") |
---|
53 | param1=ABAC.DataTerm("anonymous", "_") |
---|
54 | cond=ABAC.Constraint("integer") |
---|
55 | cond.constraint_add_integer_min(1955) |
---|
56 | cond.constraint_add_integer_max(1958) |
---|
57 | param2=ABAC.DataTerm("integer", "Year", cond) |
---|
58 | tail = ABAC.Role(stateU,"diploma") |
---|
59 | tail.role_add_data_term(param1) |
---|
60 | tail.role_add_data_term(param2) |
---|
61 | attr=ABAC.Attribute(head, 1800) |
---|
62 | attr.attribute_add_tail(tail) |
---|
63 | attr.attribute_bake() |
---|
64 | attr.attribute_write_cert("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der") |
---|
65 | ctxt.load_attribute_file("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der") |
---|
66 | print attr.string() |
---|
67 | print attr.typed_string() |
---|
68 | print "\n" |
---|
69 | |
---|
70 | ################################################# |
---|
71 | # [keyid:stateU].role:diploma([string:'mathmatics'],[integer:1960]) <- [keyid:bob] |
---|
72 | param1=ABAC.DataTerm("string", "'mathmatics'") |
---|
73 | param2=ABAC.DataTerm("integer", "1960") |
---|
74 | head = ABAC.Role(stateU,"diploma") |
---|
75 | head.role_add_data_term(param1) |
---|
76 | head.role_add_data_term(param2) |
---|
77 | tail = ABAC.Role(bob) |
---|
78 | attr=ABAC.Attribute(head, 1800) |
---|
79 | attr.attribute_add_tail(tail) |
---|
80 | attr.attribute_bake() |
---|
81 | attr.attribute_write_cert("StateU_diploma_m__Bob_attr.der") |
---|
82 | ctxt.load_attribute_file("StateU_diploma_m__Bob_attr.der") |
---|
83 | print attr.string() |
---|
84 | print attr.typed_string() |
---|
85 | print "\n" |
---|
86 | |
---|
87 | ################################################# |
---|
88 | # [keyid:stateU].role:diploma([string:'zoology'],[integer:1955]) <- [keyid:joe] |
---|
89 | param1=ABAC.DataTerm("string", "'zoology'") |
---|
90 | param2=ABAC.DataTerm("integer", "1955") |
---|
91 | head = ABAC.Role(stateU,"diploma") |
---|
92 | head.role_add_data_term(param1) |
---|
93 | head.role_add_data_term(param2) |
---|
94 | tail = ABAC.Role(joe) |
---|
95 | attr=ABAC.Attribute(head, 1800) |
---|
96 | attr.attribute_add_tail(tail) |
---|
97 | attr.attribute_bake() |
---|
98 | attr.attribute_write_cert("StateU_diploma_z__Joe_attr.der") |
---|
99 | ctxt.load_attribute_file("StateU_diploma_z__Joe_attr.der") |
---|
100 | print attr.string() |
---|
101 | print attr.typed_string() |
---|
102 | print "\n" |
---|
103 | |
---|
104 | ################################################# |
---|
105 | # [keyid:stateU].role:diploma([string:'psychology'],[integer:1956]) <- [keyid:maryann] |
---|
106 | param1=ABAC.DataTerm("string", "'psychology'") |
---|
107 | param2=ABAC.DataTerm("integer", "1956") |
---|
108 | head = ABAC.Role(stateU,"diploma") |
---|
109 | head.role_add_data_term(param1) |
---|
110 | head.role_add_data_term(param2) |
---|
111 | tail = ABAC.Role(maryann) |
---|
112 | attr=ABAC.Attribute(head, 1800) |
---|
113 | attr.attribute_add_tail(tail) |
---|
114 | attr.attribute_bake() |
---|
115 | attr.attribute_write_cert("StateU_diploma_p__Maryann_attr.der") |
---|
116 | ctxt.load_attribute_file("StateU_diploma_p__Maryann_attr.der") |
---|
117 | print attr.string() |
---|
118 | print attr.typed_string() |
---|
119 | print "\n" |
---|
120 | |
---|
121 | ctxt.dump_yap_db() |
---|
122 | ## |
---|