[7211a95] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | """ |
---|
[f824a9e] | 4 | Run the queries described in README |
---|
[7211a95] | 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() |
---|
[646e57e] | 15 | ctxt.set_no_partial_proof() |
---|
[7211a95] | 16 | |
---|
[f824a9e] | 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) |
---|
[7211a95] | 25 | |
---|
[f824a9e] | 26 | # retrieve principals' keyid value from local credential files |
---|
[7211a95] | 27 | geniID=ABAC.ID("Geni_ID.pem"); |
---|
| 28 | geniID.id_load_privkey_file("Geni_private.pem"); |
---|
| 29 | geni=geniID.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 | jackID=ABAC.ID("Jack_ID.pem"); |
---|
| 36 | jackID.id_load_privkey_file("Jack_private.pem"); |
---|
| 37 | jack=jackID.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 | ########################################################################## |
---|
[f824a9e] | 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 Bob a leader at Geni ? |
---|
[7211a95] | 57 | # role=[keyid:geni].role:leader |
---|
| 58 | # p=[keyid:Bob] |
---|
| 59 | role = ABAC.Role(geni,"leader") |
---|
| 60 | p = ABAC.Role(bob) |
---|
| 61 | print "\n===good============ geni.leader <- Bob" |
---|
| 62 | out = ctxt.query(role, p) |
---|
| 63 | for c in out[1]: |
---|
| 64 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 65 | |
---|
| 66 | ########################################################################## |
---|
[f824a9e] | 67 | # is Jack a leader at Geni ? |
---|
[7211a95] | 68 | # role=[keyid:geni].role:leader |
---|
| 69 | # p=[keyid:Jack] |
---|
| 70 | role = ABAC.Role(geni,"leader") |
---|
| 71 | p = ABAC.Role(jack) |
---|
| 72 | print "\n===bad============ geni.leader <- Jack" |
---|
| 73 | out = ctxt.query(role, p) |
---|
| 74 | for c in out[1]: |
---|
| 75 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 76 | |
---|
| 77 | ########################################################################## |
---|
[f824a9e] | 78 | # is Joe a leader at Geni ? |
---|
[7211a95] | 79 | # role=[keyid:geni].role:leader |
---|
| 80 | # p=[keyid:Joe] |
---|
| 81 | role = ABAC.Role(geni,"leader") |
---|
| 82 | p = ABAC.Role(joe) |
---|
| 83 | print "\n===good============ geni.leader <- Joe" |
---|
| 84 | out = ctxt.query(role, p) |
---|
| 85 | for c in out[1]: |
---|
| 86 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 87 | |
---|