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 | alphaID=ABAC.ID("Alpha_ID.pem"); |
---|
28 | alphaID.id_load_privkey_file("Alpha_private.pem"); |
---|
29 | alpha=alphaID.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 | maryannID=ABAC.ID("Maryann_ID.pem"); |
---|
36 | maryannID.id_load_privkey_file("Maryann_private.pem"); |
---|
37 | maryann=maryannID.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 | ########################################################################## |
---|
44 | # dump the loaded principals/policies |
---|
45 | # |
---|
46 | out = ctxt.context_principals() |
---|
47 | print "\n...final principal set..." |
---|
48 | for x in out[1]: |
---|
49 | print "%s " % x.string() |
---|
50 | out = ctxt.context_credentials() |
---|
51 | print "\n...final policy attribute set..." |
---|
52 | for c in out[1]: |
---|
53 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
54 | |
---|
55 | ########################################################################## |
---|
56 | # Is Joe getting a pay raise ? |
---|
57 | # role=[keyid:alpha].role:payRaise |
---|
58 | # p=[keyid:Joe] |
---|
59 | role = ABAC.Role(alpha,"payRaise") |
---|
60 | p = ABAC.Role(joe) |
---|
61 | print "\n===bad============ alpha.payRaise <- Joe" |
---|
62 | out = ctxt.query(role, p) |
---|
63 | for c in out[1]: |
---|
64 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | ########################################################################## |
---|
69 | # Is Maryann getting a pay raise ? |
---|
70 | # role=[keyid:alpha].role:payRaise |
---|
71 | # p=[keyid:Maryann] |
---|
72 | role = ABAC.Role(alpha,"payRaise") |
---|
73 | p = ABAC.Role(maryann) |
---|
74 | print "\n===good============ alpha.payRaise <- Maryann" |
---|
75 | out = ctxt.query(role, p) |
---|
76 | for c in out[1]: |
---|
77 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
78 | |
---|
79 | |
---|
80 | ########################################################################## |
---|
81 | #ctxt.dump_yap_db() |
---|
82 | |
---|