[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 | import os |
---|
| 11 | import ABAC |
---|
| 12 | |
---|
| 13 | ctxt = ABAC.Context() |
---|
[646e57e] | 14 | ctxt.set_no_partial_proof() |
---|
[7211a95] | 15 | |
---|
[f824a9e] | 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) |
---|
[7211a95] | 24 | |
---|
[f824a9e] | 25 | # retrieve principals' keyid value from local credential files |
---|
[7211a95] | 26 | acmeID=ABAC.ID("Acme_ID.pem"); |
---|
| 27 | acmeID.id_load_privkey_file("Acme_private.pem"); |
---|
| 28 | acme=acmeID.id_keyid() |
---|
| 29 | |
---|
| 30 | coyoteID=ABAC.ID("Coyote_ID.pem"); |
---|
| 31 | coyoteID.id_load_privkey_file("Coyote_private.pem"); |
---|
| 32 | coyote=coyoteID.id_keyid() |
---|
| 33 | |
---|
| 34 | warnerbrosID=ABAC.ID("WarnerBros_ID.pem"); |
---|
| 35 | warnerbrosID.id_load_privkey_file("WarnerBros_private.pem"); |
---|
| 36 | warnerbros=warnerbrosID.id_keyid() |
---|
| 37 | |
---|
| 38 | batmanID=ABAC.ID("Batman_ID.pem"); |
---|
| 39 | batmanID.id_load_privkey_file("Batman_private.pem"); |
---|
| 40 | batman=batmanID.id_keyid() |
---|
| 41 | |
---|
| 42 | ########################################################################## |
---|
[f824a9e] | 43 | # dump the loaded principals/policies |
---|
| 44 | # |
---|
| 45 | out = ctxt.context_principals() |
---|
| 46 | print "\n...final principal set..." |
---|
| 47 | for x in out[1]: |
---|
| 48 | print "%s " % x.string() |
---|
| 49 | out = ctxt.context_credentials() |
---|
| 50 | print "\n...final policy attribute set..." |
---|
| 51 | for c in out[1]: |
---|
| 52 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 53 | |
---|
| 54 | ########################################################################## |
---|
| 55 | # can coyote buy rockets from Acme ? |
---|
[7211a95] | 56 | # role = "[keyid:Acme].role:buy_rockets" |
---|
| 57 | # p = "[keyid:coyote]" |
---|
| 58 | role = ABAC.Role(acme,"buy_rockets") |
---|
| 59 | p = ABAC.Role(coyote) |
---|
| 60 | |
---|
| 61 | print "\n===good============ Acme.buy_rockets <- Coyote" |
---|
| 62 | out = ctxt.query(role, p) |
---|
| 63 | |
---|
| 64 | for c in out[1]: |
---|
| 65 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | ########################################################################## |
---|
[f824a9e] | 69 | # can batman buy rockets from Acme ? |
---|
[7211a95] | 70 | # role = "[keyid:Acme].role:buy_rockets" |
---|
| 71 | # p = "[keyid:batman]" |
---|
| 72 | role = ABAC.Role(acme,"buy_rockets") |
---|
| 73 | p = ABAC.Role(batman) |
---|
| 74 | |
---|
| 75 | print "\n===bad============ Acme.buy_rockets <- Batman" |
---|
| 76 | out = ctxt.query(role, p) |
---|
| 77 | |
---|
| 78 | for c in out[1]: |
---|
| 79 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 80 | |
---|