#!/usr/bin/env 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" ralphsID=ABAC.ID("Ralphs_ID.pem"); ralphsID.id_load_privkey_file("Ralphs_private.pem"); ralphs=ralphsID.id_keyid() bobID=ABAC.ID("Bob_ID.pem"); bobID.id_load_privkey_file("Bob_private.pem"); bob=bobID.id_keyid() maryID=ABAC.ID("Mary_ID.pem"); maryID.id_load_privkey_file("Mary_private.pem"); mary=maryID.id_keyid() ################################################ # [keyid:mary].oset:what2eat # <- [keyid:ralphs].oset:fruitprice([float:?P:[..2.00]]) # [keyid:alpha].role:access([string:'Read'],[urn:'file//fileB']) <- [keyid:bob] head = ABAC.Oset(mary,"what2eat") cond=ABAC.Constraint("float") cond.constraint_add_float_max(2.00) param=ABAC.DataTerm("float", "P", cond) tail = ABAC.Oset(ralphs,"fruitprice") tail.oset_add_data_term(param) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("mary_what2eat__ralphs_fruitprice_qP_attr.der") ctxt.load_attribute_file("mary_what2eat__ralphs_fruitprice_qP_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################ # [keyid:bob].oset:what2eat # <- [keyid:ralphs].oset:fruitprice([float:?P:[1.00..5.00]]) head = ABAC.Oset(bob,"what2eat") cond=ABAC.Constraint("float") cond.constraint_add_float_min(1.00) cond.constraint_add_float_max(5.00) print cond.typed_string() param=ABAC.DataTerm("float", "P", cond) tail = ABAC.Oset(ralphs,"fruitprice") tail.oset_add_data_term(param) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("bob_what2eat__ralphs_fruitprice_qP_attr.der") ctxt.load_attribute_file("bob_what2eat__ralphs_fruitprice_qP_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # [keyid:ralphs].oset:fruitprice([float:1.50]) <- [string:'apple'] param=ABAC.DataTerm("float", "1.50") head = ABAC.Oset(ralphs,"fruitprice") head.oset_add_data_term(param) param=ABAC.DataTerm("string", "'apple'") tail = ABAC.Oset(param) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("Ralphs_fruitprice__apple_attr.der") ctxt.load_attribute_file("Ralphs_fruitprice__apple_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # [keyid:ralphs].oset:fruitprice([float:1.50]) <- [string:'kiwi'] param=ABAC.DataTerm("float", "1.50") head = ABAC.Oset(ralphs,"fruitprice") head.oset_add_data_term(param) param=ABAC.DataTerm("string", "'kiwi'") tail = ABAC.Oset(param) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("Ralphs_fruitprice__kiwi_attr.der") ctxt.load_attribute_file("Ralphs_fruitprice__kiwi_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # [keyid:ralphs].oset:fruitprice([float:2.50]) <- [string:'black berry'] param=ABAC.DataTerm("float", "2.50") head = ABAC.Oset(ralphs,"fruitprice") head.oset_add_data_term(param) param=ABAC.DataTerm("string", "'black berry'") tail = ABAC.Oset(param) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("Ralphs_fruitprice__blackberry_attr.der") ctxt.load_attribute_file("Ralphs_fruitprice__blackberry_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # [keyid:ralphs].oset:fruitprice([float:0.50]) <- [string:'navel orange'] param=ABAC.DataTerm("float", "0.50") head = ABAC.Oset(ralphs,"fruitprice") head.oset_add_data_term(param) param=ABAC.DataTerm("string", "'navel orange'") tail = ABAC.Oset(param) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("Ralphs_fruitprice__navelorange_attr.der") ctxt.load_attribute_file("Ralphs_fruitprice__navelorange_attr.der") print attr.string() print attr.typed_string() print "\n" ## ctxt.dump_yap_db() ##