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