#!/usr/bin/env python """ Run the queries described in README cmd1:env keystore=`pwd` ./query.py cmd2: env ABAC_CN=1 keystore=`pwd` ./query.py """ import os import ABAC ctxt = ABAC.Context() # Keystore is the directory containing the principal credentials. # Load existing principals and/or policy credentials if (os.environ.has_key("keystore")) : keystore=os.environ["keystore"] ctxt.load_directory(keystore) else: print("keystore is not set...") exit(1) # retrieve principals' keyid value from local credential files alphaID=ABAC.ID("Alpha_ID.pem") alphaID.id_load_privkey_file("Alpha_private.pem"); alpha=alphaID.id_keyid() bobID=ABAC.ID("Bob_ID.pem") bobID.id_load_privkey_file("Bob_private.pem"); bob=bobID.id_keyid() maryannID=ABAC.ID("Maryann_ID.pem") maryannID.id_load_privkey_file("Maryann_private.pem") maryann=maryannID.id_keyid() joeID=ABAC.ID("Joe_ID.pem") joeID.id_load_privkey_file("Joe_private.pem") joe=joeID.id_keyid() ########################################################################## # dump the loaded principals/policies # out = ctxt.context_principals() print "\n...final principal set..." for x in out[1]: print "%s " % x.string() out = ctxt.context_credentials() print "\n...final policy attribute set..." for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string()) ########################################################################## # can Bob read fileA ? # role=[keyid:Alpha].role:read([urn:'file://fileA']) # p=[keyid:Bob] param=ABAC.DataTerm("urn", "'file://fileA'") role = ABAC.Role(alpha,"read") role.role_add_data_term(param) p=ABAC.Role(bob) print "\n===good============ alpha.read(fileA) <- Bob" out = ctxt.query(role, p) for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string()) ########################################################################## # can Maryann read fileA ? # role=[keyid:Alpha].role:read([urn:'file://fileA']) # p=[keyid:Maryann] param=ABAC.DataTerm("urn", "'file://fileA'") role = ABAC.Role(alpha,"read") p=ABAC.Role(maryann) print "\n===bad============ alpha.read(fileA) <- Maryann" out = ctxt.query(role, p) for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string())