#!/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 nid=ABAC.ID("Jack", 0) print "adding -> %s(good)" % nid.id_name() ## load principal directly with the ID, no external ## credential files were created ctxt.load_id(nid) ## case 3 ## creating principal using ID id=ABAC.ID("Mark", 0) print "adding -> %s(good)" % id.id_name() ## write cert and key content to a combo file. One is appended ## after another id.id_write_privkey("Mark_IDKEY.pem") id.id_write_cert("Mark_IDKEY.pem") ## load principal in with the combo file with the tandem format ctxt.load_id_file("Mark_IDKEY.pem") ## case 4 ## creating principal using ID id=ABAC.ID("John", 0) print "adding -> %s(good,invisible)" % id.id_name() id.id_write_privkey("John_other.pem") id.id_write_cert("John_other.pem") ## load id without the key file ctxt.load_id_file("John_other.pem") ## case 5 ## creating principal using ID id=ABAC.ID("Lori", 0) print "adding -> %s(good,nokey)" % id.id_name() ## write just cert into the combo file id.id_write_cert("Lori_IDKEY.pem") ##load principal from a combo file that only contains cert part ctxt.load_id_file("Lori_IDKEY.pem") ## case 6 ## creating principal using ID id=ABAC.ID("Tom", 0) print "adding -> %s(bad,nocert)" % id.id_name() ## write just key into the combo file id.id_write_privkey("Tom_IDKEY.pem") ## load principal from combo file that only contains key part ctxt.load_id_file("Tom_IDKEY.pem") ## case 7 ## creating ID using chunk id=ABAC.ID("Tim", 0) chunk=id.id_cert_chunk_ptr() nid=ABAC.ID(chunk) ## load principal from new id file ctxt.load_id(nid) ## case 8 ## 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.dump_yap_db()