#!/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 acmeID=ABAC.ID("Acme_ID.pem") acmeID.id_load_privkey_file("Acme_private.pem"); acme=acmeID.id_keyid() coyoteID=ABAC.ID("Coyote_ID.pem") coyoteID.id_load_privkey_file("Coyote_private.pem"); coyote=coyoteID.id_keyid() roadrunnerID=ABAC.ID("Roadrunner_ID.pem") roadrunnerID.id_load_privkey_file("Roadrunner_private.pem"); roadrunner=roadrunnerID.id_keyid() jackrabbitID=ABAC.ID("Jackrabbit_ID.pem") jackrabbitID.id_load_privkey_file("Jackrabbit_private.pem"); jackrabbit=jackrabbitID.id_keyid() ################################################ # Credential 1 # [keyid:Acme].role:preferred_customer <- [keyid:Acme].role:friendof([keyid:Roadrunner]) head = ABAC.Role(acme,"preferred_customer") param=ABAC.DataTerm(roadrunnerID) tail = ABAC.Role(acme,"friendof") # adding parameter to friendOf role tail.role_add_data_term(param) # link the head and tail parts of attribute together attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) # finalize the attribute attr.attribute_bake() # write to file system to be accessible later on attr.attribute_write_cert("Acme_preferred_customer__Acme_friendof_Roadrunner_attr.der") # load the credential just made into the context directly # (bypass the external credential file) ctxt.load_attribute(attr) print attr.string() print attr.typed_string() print "\n" ################################################# # Credential 2 # [keyid:Acme].role:prefered_customer <- [keyid:Coyote] head = ABAC.Role(acme,"preferred_customer") tail = ABAC.Role(coyote) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("Acme_preferred_customer__Coyote_attr.der") ctxt.load_attribute(attr) print attr.string() print attr.typed_string() print "\n" ################################################# # Credential 3 # [keyid:Acme].role:friendof([keyid:Roadrunner]) <- [keyid:Jackrabbit] param=ABAC.DataTerm(roadrunnerID) head = ABAC.Role(acme,"friendof") head.role_add_data_term(param) tail = ABAC.Role(jackrabbit) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("Acme_friendof_Roadrunner__Jackrabbit_attr.der") ctxt.load_attribute(attr) print attr.string() print attr.typed_string() print "\n"