#!/usr/bin/env python """ See README in this directory for the semantics of the example. This file constructs the credentials described and puts copies into this directory cmd1:env keystore=`pwd` ./attr.py """ import os import ABAC ctxt = ABAC.Context() print "ABAC version %s" % ctxt.version() # 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) 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" # retrieve principals' keyid value from local credential files isiID=ABAC.ID("ISI_ID.pem") isiID.id_load_privkey_file("ISI_private.pem"); isi=isiID.id_keyid() uscID=ABAC.ID("USC_ID.pem") uscID.id_load_privkey_file("USC_private.pem"); usc=uscID.id_keyid() maryannID=ABAC.ID("Maryann_ID.pem") maryannID.id_load_privkey_file("Maryann_private.pem"); maryann=maryannID.id_keyid() johnID=ABAC.ID("John_ID.pem") johnID.id_load_privkey_file("John_private.pem"); john=johnID.id_keyid() ################################################ #[keyid:USC].role:evaluatorOf([principal:?K]) # <-[keyid:USC].role:managerOf([principal:?K]) param=ABAC.DataTerm("principal", "K") head = ABAC.Role(usc,"evaluatorOf") head.role_add_data_term(param) param=ABAC.DataTerm("principal","K") tail = ABAC.Role(usc,"managerOf") tail.role_add_data_term(param) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("USC_evaluatorof_qK__USC_managerof_qK_attr.der") ctxt.load_attribute_file("USC_evaluatorof_qK__USC_managerof_qK_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # Credential 1, double uninstantiated parameters # [keyid:USC].role:managerOf([principal:?K]) # <-[keyid:ISI].role:managerOf([principal:?K]) # param=ABAC.DataTerm("principal", "K") head = ABAC.Role(usc,"managerOf") head.role_add_data_term(param) # create variable princpal parameter param=ABAC.DataTerm("principal", "K") tail = ABAC.Role(isi,"managerOf") tail.role_add_data_term(param) attr=ABAC.Attribute(head, 1800) # compose the attribute for the policy attr.attribute_add_tail(tail) # finalize the policy attr.attribute_bake() # write the policy to a file attr.attribute_write_cert("USC_managerof_qK__USC_employee_attr.der") ctxt.load_attribute_file("USC_managerof_qK__USC_employee_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # Credential 2 # [keyid:ISI].role:managerOf([keyid:Maryann]) # <- [keyid:John] param=ABAC.DataTerm(maryannID) head = ABAC.Role(isi,"managerOf") head.role_add_data_term(param) tail = ABAC.Role(john) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("ISI_manageof_Maryann__John_attr.der") ctxt.load_attribute_file("ISI_manageof_Maryann__John_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################ # Credential 3 # [keyid:USC].role:employee <- [keyid:ISI].role:employee head=ABAC.Role(usc,"employee") tail = ABAC.Role(isi,"employee") attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("USC_employee__ISI_employee_attr.der") ctxt.load_attribute(attr) print attr.string() print attr.typed_string() print "\n" ################################################# # Credential 4 # [keyid:ISI].role:employee <- [keyid:Maryann] head = ABAC.Role(isi,"employee") tail= ABAC.Role(maryann) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("ISI_employee__Maryann_attr.der") ctxt.load_attribute(attr) print attr.string() print attr.typed_string() print "\n" ################################################# # Credential 4 # [keyid:ISI].role:employee <- [keyid:John] head = ABAC.Role(isi,"employee") tail= ABAC.Role(john) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("ISI_employee__John_attr.der") ctxt.load_attribute(attr) print attr.string() print attr.typed_string() print "\n"