[5f551d3] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | """ |
---|
[f824a9e] | 4 | Run the queries described in README |
---|
[5f551d3] | 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() |
---|
[5f551d3] | 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) |
---|
[5f551d3] | 25 | |
---|
[f824a9e] | 26 | # retrieve principals' keyid value from local credential files |
---|
[5f551d3] | 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 | joeID=ABAC.ID("Joe_ID.pem") |
---|
| 36 | joeID.id_load_privkey_file("Joe_private.pem") |
---|
| 37 | joe=joeID.id_keyid() |
---|
| 38 | |
---|
| 39 | maryannID=ABAC.ID("Maryann_ID.pem") |
---|
| 40 | maryannID.id_load_privkey_file("Maryann_private.pem") |
---|
| 41 | maryann=maryannID.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 founding alumni of stateU ? |
---|
[5f551d3] | 57 | # role=[keyid:stateU].role:foundingAlumni |
---|
| 58 | # p=[keyid:Bob] |
---|
| 59 | role = ABAC.Role(stateU,"foundingAlumni") |
---|
| 60 | p = ABAC.Role(bob) |
---|
| 61 | print "\n===good============ stateU.foundingAlumni <- 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 maryann a founding alumni of stateU ? |
---|
[5f551d3] | 68 | # role=[keyid:stateU].role:foundingAlumni |
---|
| 69 | # p=[keyid:Maryann] |
---|
| 70 | role = ABAC.Role(stateU,"foundingAlumni") |
---|
| 71 | p = ABAC.Role(maryann) |
---|
| 72 | print "\n===bad============ stateU.foundingAlumni <- Maryann" |
---|
| 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 founding alumni of stateU ? |
---|
[5f551d3] | 79 | # role=[keyid:stateU].role:foundingAlumni |
---|
| 80 | # p=[keyid:Joe] |
---|
| 81 | role = ABAC.Role(stateU,"foundingAlumni") |
---|
| 82 | p = ABAC.Role(joe) |
---|
| 83 | print "\n===bad============ stateU.foundingAlumni <- Joe" |
---|
| 84 | out = ctxt.query(role, p) |
---|
| 85 | for c in out[1]: |
---|
| 86 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|