1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | Run the queries described in README |
---|
5 | |
---|
6 | cmd1:env keystore=`pwd` ./query.py |
---|
7 | cmd2: env ABAC_CN=1 keystore=`pwd` ./query.py |
---|
8 | |
---|
9 | """ |
---|
10 | |
---|
11 | import os |
---|
12 | import ABAC |
---|
13 | |
---|
14 | ctxt = ABAC.Context() |
---|
15 | |
---|
16 | # Keystore is the directory containing the principal credentials. |
---|
17 | # Load existing principals and/or policy credentials |
---|
18 | if (os.environ.has_key("keystore")) : |
---|
19 | keystore=os.environ["keystore"] |
---|
20 | ctxt.load_directory(keystore) |
---|
21 | else: |
---|
22 | print("keystore is not set...") |
---|
23 | exit(1) |
---|
24 | |
---|
25 | # retrieve principals' keyid value from local credential files |
---|
26 | stateUID=ABAC.ID("StateU_ID.pem") |
---|
27 | stateUID.id_load_privkey_file("StateU_private.pem") |
---|
28 | stateU=stateUID.id_keyid() |
---|
29 | |
---|
30 | bobID=ABAC.ID("Bob_ID.pem") |
---|
31 | bobID.id_load_privkey_file("Bob_private.pem") |
---|
32 | bob=bobID.id_keyid() |
---|
33 | |
---|
34 | markID=ABAC.ID("Mark_ID.pem") |
---|
35 | markID.id_load_privkey_file("Mark_private.pem") |
---|
36 | mark=markID.id_keyid() |
---|
37 | |
---|
38 | joeID=ABAC.ID("Joe_ID.pem") |
---|
39 | joeID.id_load_privkey_file("Joe_private.pem") |
---|
40 | joe=joeID.id_keyid() |
---|
41 | |
---|
42 | maryannID=ABAC.ID("Maryann_ID.pem") |
---|
43 | maryannID.id_load_privkey_file("Maryann_private.pem") |
---|
44 | maryann=maryannID.id_keyid() |
---|
45 | |
---|
46 | janID=ABAC.ID("Jan_ID.pem") |
---|
47 | janID.id_load_privkey_file("Jan_private.pem") |
---|
48 | jan=janID.id_keyid() |
---|
49 | |
---|
50 | ########################################################################## |
---|
51 | # dump the loaded principals/policies |
---|
52 | # |
---|
53 | out = ctxt.context_principals() |
---|
54 | print "\n...final principal set..." |
---|
55 | for x in out[1]: |
---|
56 | print "%s " % x.string() |
---|
57 | out = ctxt.context_credentials() |
---|
58 | print "\n...final policy attribute set..." |
---|
59 | for c in out[1]: |
---|
60 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
61 | |
---|
62 | ########################################################################## |
---|
63 | # role=[keyid:stateU].role:foundingAlumni |
---|
64 | # p=[keyid:Bob] |
---|
65 | role = ABAC.Role(stateU,"foundingAlumni") |
---|
66 | p = ABAC.Role(bob) |
---|
67 | print "\n===good============ stateU.foundingAlumni <- Bob" |
---|
68 | out = ctxt.query(role, p) |
---|
69 | for c in out[1]: |
---|
70 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
71 | |
---|
72 | ########################################################################## |
---|
73 | # role=[keyid:stateU].role:foundingAlumni |
---|
74 | # p=[keyid:Mark] |
---|
75 | role = ABAC.Role(stateU,"foundingAlumni") |
---|
76 | p = ABAC.Role(mark) |
---|
77 | print "\n===bad============ stateU.foundingAlumni <- Mark" |
---|
78 | out = ctxt.query(role, p) |
---|
79 | for c in out[1]: |
---|
80 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
81 | |
---|
82 | ########################################################################## |
---|
83 | # role=[keyid:stateU].role:foundingAlumni |
---|
84 | # p=[keyid:Joe] |
---|
85 | role = ABAC.Role(stateU,"foundingAlumni") |
---|
86 | p = ABAC.Role(joe) |
---|
87 | print "\n===bad============ stateU.foundingAlumni <- Joe" |
---|
88 | out = ctxt.query(role, p) |
---|
89 | for c in out[1]: |
---|
90 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
91 | |
---|
92 | ########################################################################## |
---|
93 | # role=[keyid:stateU].role:foundingAlumni |
---|
94 | # p=[keyid:Maryann] |
---|
95 | role = ABAC.Role(stateU,"foundingAlumni") |
---|
96 | p = ABAC.Role(maryann) |
---|
97 | print "\n===bad============ stateU.foundingAlumni <- Maryann" |
---|
98 | out = ctxt.query(role, p) |
---|
99 | for c in out[1]: |
---|
100 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
101 | |
---|
102 | ########################################################################## |
---|
103 | # role=[keyid:stateU].role:foundingAlumni |
---|
104 | # p=[keyid:Jan] |
---|
105 | role = ABAC.Role(stateU,"foundingAlumni") |
---|
106 | p = ABAC.Role(jan) |
---|
107 | print "\n===good============ stateU.foundingAlumni <- Jan" |
---|
108 | out = ctxt.query(role, p) |
---|
109 | for c in out[1]: |
---|
110 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
111 | |
---|