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