#!/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 leagueID=ABAC.ID("League_ID.pem"); leagueID.id_load_privkey_file("League_private.pem"); league=leagueID.id_keyid() johnID=ABAC.ID("John_ID.pem"); johnID.id_load_privkey_file("John_private.pem"); john=johnID.id_keyid() markID=ABAC.ID("Mark_ID.pem"); markID.id_load_privkey_file("Mark_private.pem"); mark=markID.id_keyid() ################################################ # Credential 1, oset constraint on a time parameter #[keyid:league].role:stadium([string:'access'],[boolean:true], # [time:?F:[keyid:league].oset.gametime([string:?T])]) # <-[keyid:league].role:players([string:?T]) param1=ABAC.DataTerm("string","'access'") param2=ABAC.DataTerm("boolean","true") # setup the uninstantiated variable as the oset constraint's parameter param=ABAC.DataTerm("string","T") # make the oset condition condoset=ABAC.Oset(league,"gametime") # add the parameter for the constraint condoset.oset_add_data_term(param) # create the constraint with the oset condition cond=ABAC.Constraint(condoset) # make the data term that is being constrained param3=ABAC.DataTerm("time", "F", cond) head = ABAC.Role(league,"stadium") head.role_add_data_term(param1) head.role_add_data_term(param2) head.role_add_data_term(param3) param=ABAC.DataTerm("string", "T") tail = ABAC.Role(league,"players") tail.role_add_data_term(param) # build up the attribute policy attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) # finalize the policy attr.attribute_bake() # create the credential file for this policy attr.attribute_write_cert("League_access_qFqT__League_players_qT_attr.der") ctxt.load_attribute_file("League_access_qFqT__League_players_qT_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################ # Credential 2, 2 different range constraints, one on a boolean and # and the other is on a time #[keyid:league].role:stadium([string:'access'],[boolean:?B:[true], # [time:?F:[20120228T080000..20120228T090000]]) # <- [keyid:league].role:players(string:?T) param1=ABAC.DataTerm("string","'access'") # generate a range constraint with a single target value cond=ABAC.Constraint("boolean") cond.constraint_add_boolean_target("true") param2=ABAC.DataTerm("boolean", "B", cond) # generate a range constraint with a min and a max cond=ABAC.Constraint("time") cond.constraint_add_time_min("20120228T080000") cond.constraint_add_time_max("20120228T090000") param3=ABAC.DataTerm("time", "F", cond) head = ABAC.Role(league,"stadium") head.role_add_data_term(param1) head.role_add_data_term(param2) head.role_add_data_term(param3) param=ABAC.DataTerm("string", "T") tail = ABAC.Role(league,"players") tail.role_add_data_term(param) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("League_access_qR__League_players_qT_attr.der") ctxt.load_attribute_file("League_access_qR__League_players_qT_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # Credential 3 # [keyid:league].oset:gametime([string:'north']) # <- [time:20120228T130000] param=ABAC.DataTerm("string","'north'") head = ABAC.Oset(league,"gametime") head.oset_add_data_term(param) term=ABAC.DataTerm("time", "20120228T130000") tail = ABAC.Oset(term) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("League_gametime_north__timeT_attr.der") ctxt.load_attribute_file("League_gametime_north__timeT_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # Credential 4 # [keyid:league].oset:gametime([string:'south']) # <-[time:20120228T140000] param=ABAC.DataTerm("string","'south'") head = ABAC.Oset(league,"gametime") head.oset_add_data_term(param) term=ABAC.DataTerm("time", "20120228T140000") tail = ABAC.Oset(term) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("League_gametime_south__time2T_attr.der") ctxt.load_attribute_file("League_gametime_south__time2T_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # Credential 5 # [keyid:league].role:players([string:'north'])<-[keyid:John] param=ABAC.DataTerm("string", "'north'") head = ABAC.Role(league,"players") 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("League_players_north__John_attr.der") ctxt.load_attribute_file("League_players_north__John_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # Credential 6 # [keyid:league].role:players([string:'south'])<-[keyid:Mark] param=ABAC.DataTerm("string", "'south'") head = ABAC.Role(league,"players") head.role_add_data_term(param) tail = ABAC.Role(mark) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("League_players_south__Mark_attr.der") ctxt.load_attribute_file("League_players_north__John_attr.der") print attr.string() print attr.typed_string() print "\n"