#!/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) 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 stateUID=ABAC.ID("StateU_ID.pem") stateUID.id_load_privkey_file("StateU_private.pem") stateU=stateUID.id_keyid() bobID=ABAC.ID("Bob_ID.pem") bobID.id_load_privkey_file("Bob_private.pem") bob=bobID.id_keyid() joeID=ABAC.ID("Joe_ID.pem") joeID.id_load_privkey_file("Joe_private.pem") joe=joeID.id_keyid() maryannID=ABAC.ID("Maryann_ID.pem") maryannID.id_load_privkey_file("Maryann_private.pem") maryann=maryannID.id_keyid() ################################################ # Credential 1, Any alumni of stateU is a member of foundingAlumni if # they have diploma from those specific years # [keyid:stateU].role:foundingAlumni # <- [keyid:stateU].role:diploma([?], [integer:?Year:[1960,1961,1963]]) head = ABAC.Role(stateU,"foundingAlumni") # constructing an anonymous parameter param1=ABAC.DataTerm("anonymous", "_") # initialize a integer range constraint cond=ABAC.Constraint("integer") # add specific target value for the integer range constraint cond.constraint_add_integer_target(1963) cond.constraint_add_integer_target(1961) cond.constraint_add_integer_target(1960) # create a paramter term that has a range constraint on it, # the variable name supplied has to start with a capitalized alphabet character param2=ABAC.DataTerm("integer", "Year", cond) tail = ABAC.Role(stateU,"diploma") tail.role_add_data_term(param1) tail.role_add_data_term(param2) attr=ABAC.Attribute(head, 1800) # construct the attribute attr.attribute_add_tail(tail) # finalize the attribute attr.attribute_bake() attr.attribute_write_cert("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der") ctxt.load_attribute_file("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # Credential 2 # [keyid:stateU].role:diploma([string:'mathmatics'],[integer:1961]) <- [keyid:bob] param1=ABAC.DataTerm("string", "'mathmatics'") param2=ABAC.DataTerm("integer", "1961") head = ABAC.Role(stateU,"diploma") head.role_add_data_term(param1) head.role_add_data_term(param2) tail = ABAC.Role(bob) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("StateU_diploma_m__Bob_attr.der") ctxt.load_attribute_file("StateU_diploma_m__Bob_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # Credential 3 # [keyid:stateU].role:diploma([string:'zoology'],[integer:1955]) <- [keyid:joe] param1=ABAC.DataTerm("string", "'zoology'") param2=ABAC.DataTerm("integer", "1955") head = ABAC.Role(stateU,"diploma") head.role_add_data_term(param1) head.role_add_data_term(param2) tail = ABAC.Role(joe) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("StateU_diploma_z__Joe_attr.der") ctxt.load_attribute_file("StateU_diploma_z__Joe_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # Credential 4 # [keyid:stateU].role:diploma([string:'psychology'],[integer:1962]) <- [keyid:maryann] param1=ABAC.DataTerm("string", "'psychology'") param2=ABAC.DataTerm("integer", "1962") head = ABAC.Role(stateU,"diploma") head.role_add_data_term(param1) head.role_add_data_term(param2) tail = ABAC.Role(maryann) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("StateU_diploma_p__Maryann_attr.der") ctxt.load_attribute_file("StateU_diploma_p__Maryann_attr.der") print attr.string() print attr.typed_string() print "\n"