#!/usr/bin/env python """ to test with python cmd1:env keystore=`pwd` ./id.py cmd2:env ABAC_CN=1 keystore=`pwd` ./id.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" ## case 1 ## creating and writing out using libabac ID id=ABAC.ID("Mary", 0) print "adding -> %s(good)" % id.id_name() id.id_write_cert("Mary_ID.pem") id.id_write_privkey("Mary_private.pem") ## load principal with id/key file pair ## note, with this, we do not have handle on the keyid ## to Mary but it will be in the db ctxt.load_id_files("Mary_ID.pem","Mary_private.pem") ## case 2 ## creating principal using ID id2=ABAC.ID("Jack2", 0) print "adding -> %s(good)" % id2.id_name() ## load principal directly with the ID, no external ## credential files were created ctxt.load_id(id2) ## case 3 ## creating principal using ID id3=ABAC.ID("Mark", 0) print "adding -> %s(good)" % id3.id_name() ## write cert and key content to a combo file. One is appended ## after another id3.id_write_privkey("Mark_IDKEY.pem") id3.id_write_cert("Mark_IDKEY.pem") ## load principal in with the combo file with the tandem format ctxt.load_id_file("Mark2_IDKEY.pem") ## case 4 ## creating principal using ID id4=ABAC.ID("John", 0) print "adding -> %s(good,invisible)" % id4.id_name() id4.id_write_cert("John_other.pem") ## load id without the key file ctxt.load_id_file("John2_other.pem") ## case 5 ## creating principal using ID id5=ABAC.ID("Lori", 0) print "adding -> %s(good,nokey)" % id5.id_name() ## write just cert into the combo file id5.id_write_cert("Lori_IDKEY.pem") ##load principal from a combo file that only contains cert part ctxt.load_id_file("Lori2_IDKEY.pem") ## case 6 ## creating principal using ID id6=ABAC.ID("Tom", 0) print "adding -> %s(bad,nocert)" % id6.id_name() ## write just key into the combo file id6.id_write_privkey("Tom_IDKEY.pem") ## load principal from combo file that only contains key part ctxt.load_id_file("Tom2_IDKEY.pem") ## case 7 ## creating ID using chunk ## this already created a Tim with private key and ## stored in the master list id7=ABAC.ID("Tim", 0) chunk=id7.id_cert_chunk() id7=ABAC.ID_chunk(chunk) ## load principal from new id file ctxt.load_id(id7) ## case 8 ## load directly using chunk ## this already created a Stanley with private key ## and stored in the master list id8=ABAC.ID("Stanley", 0) chunk=id8.id_cert_chunk() ## load principal as chunk ctxt.load_id_chunk(chunk) ## case 9 ## failure case, loading a non-existing combo file print "adding -> Casper(bad,unknown file)" ctxt.load_id_file("Casper_IDKEY.pem") print "...final principal set..." out = ctxt.context_principals() for x in out[1]: print "%s " % x.string() print "\n" #ctxt.context_free_now(); #ctxt.dump_yap_db()