#!/usr/bin/env python """ to test with python cmd1:env keystore=`pwd` ./attr.py """ import os import ABAC keystore=os.environ["keystore"] ctxt = ABAC.Context() print "ABAC version %s" % ctxt.version() ctxt.load_directory(keystore) out = ctxt.context_principals() print "...initial principal set..." for x in out[1]: print "%s " % x.string() print "\n" out = ctxt.context_credentials() print "...initial policy attribute set..." for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string()) print "\n" 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() ################################################ # [keyid:alpha].role:read([urn:?F])<- # [keyid:alpha].role:managerOf([principal:?E[keyid:alpha].role:ownerOf([urn:?F])] param=ABAC.DataTerm("urn", "F") head = ABAC.Role(alpha,"read") head.role_add_data_term(param) param=ABAC.DataTerm("urn", "F") condoset=ABAC.Role(alpha,"ownerOf") condoset.role_add_data_term(param) cond=ABAC.Constraint(condoset) param=ABAC.DataTerm("principal", "E", cond) tail = ABAC.Role(alpha,"managerOf") tail.role_add_data_term(param) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("Alpha_read_qF__alpha_managerof_qE_attr.der") ctxt.load_attribute_file("Alpha_read_qF__alpha_managerof_qE_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # [keyid:Alpha].role:managerOf([Keyid:Joe]) <- [keyid:Bob] # param=ABAC.DataTerm(joeID) role = ABAC.Role(alpha,"managerOf") role.role_add_data_term(param) tail = ABAC.Role(bob) attr=ABAC.Attribute(role, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("Alpha_managerof_Joe__Bob_attr.der") ctxt.load_attribute_file("Alpha_managerof_Joe__Bob_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# #[keyid:Alpha].role:ownerOf([urn:'file://fileA']) <- [keyid:Joe] # param=ABAC.DataTerm("urn", "'file://fileA'") role = ABAC.Role(alpha,"ownerOf") role.role_add_data_term(param) tail = ABAC.Role(joe) attr=ABAC.Attribute(role, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("Alpha_ownerof_fileA__Joe_attr.der") ctxt.load_attribute_file("Alpha_ownerof_fileA__Joe_attr.der") print attr.string() print attr.typed_string() print "\n" ctxt.dump_yap_db() ##