Index: examples/example_scripts/python/Makefile
===================================================================
--- examples/example_scripts/python/Makefile	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/Makefile	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,47 @@
+
+all: run_attr run_e_attr run_id run_id2 run_prove
+
+clean:
+	@rm -f *.pem *.xml *.log pfile
+
+setup:
+	creddy --generate --cn IceCream
+	creddy --generate --cn Chocolate
+
+run_attr: 
+	make clean
+	rm -rf attr.log
+	make setup
+	./abac_attr.py IceCream_ID.pem IceCream_private.pem IceCream_attr.xml Chocolate_ID.pem 1>attr.log 2>&1
+
+run_e_attr: 
+	make clean
+	rm -rf e_attr.log pfile
+	echo "dumdum" > pfile
+	openssl genrsa -des3 -out Soda_private.pem -passout file:pfile
+	creddy --generate --cn Soda --key Soda_private.pem --p=pfile
+	creddy --generate --cn Cream
+	./abac_e_attr.py Soda_ID.pem Soda_private.pem Soda_attr.xml pfile Cream_ID.pem 1>e_attr.log 2>&1
+
+run_id: 
+	make clean
+	rm -rf id.log
+	make setup
+	./abac_keyid.py IceCream_ID.pem 1>id.log 2>&1
+
+run_id2: 
+	make clean
+	rm -rf id2.log
+	make setup
+	./abac_keyid.py IceCream_private.pem 1>id2.log 2>&1
+
+run_id3: 
+	make clean
+	rm -rf id3.log
+	make setup
+	./abac_keyid2.py IceCream_ID.pem IceCream_private.pem 1>id3.log 2>&1
+
+run_prove:
+	rm -rf prover.log
+	make run_attr
+	./run_prover 1>prover.log 2>& 1
Index: examples/example_scripts/python/abac_attr.py
===================================================================
--- examples/example_scripts/python/abac_attr.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/abac_attr.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+
+"""
+     abac_attr.py
+
+     To demonstrate how to use ABAC's api in python 
+  
+     call:   attr_abac IceCream_ID.pem IceCream_private.pem IceCream_attr.xml Chocolate_ID.pem
+  
+     pre-conditions: generate IceCream_ID.pem and IceCream_private.pem with
+             creddy --generate --cn IceCream
+                     generate Chocolate_ID.pem and Chocolate_private.pem with
+             creddy --generate --cn Chocolate
+  
+     This program will generate an attribute rule, write it out to an external
+             file and also load it into the context (prolog db)
+             IceCream.delicious <- Chocolate
+  
+     Then, a query is made against the context to see if it is populated correctly.
+  
+     Note: Chocolate's principal is loaded without it private key. It does not
+           need to because it is not being used to generate attribute credential
+  
+"""
+
+from sys import argv, exit
+from ABAC import Context
+from ABAC import ID, Attribute, Role
+
+debug=0
+
+## initial context
+ctxt = Context()
+
+print len(argv)
+
+if len(argv) != 5:
+    print "Usage: abac_attr.py <cert.pem> <key.pem> <attr.xml> <pcert.pem>"
+    exit(1)
+
+# load the ID and its key
+id = None
+cid = None
+
+try:
+    id = ID(argv[1])
+    id.load_privkey(argv[2])
+    cid = ID(argv[4])
+except Exception, e:
+    print "Problem loading ID cert: %s" % e
+    exit(1)
+
+# load the id into the context
+ctxt.load_id_chunk(id.cert_chunk())
+# another way to load the id into the context
+#XXX  not implemented yet...ctxt.load_id(cid)
+ctxt.load_id_chunk(cid.cert_chunk())
+
+#out = ctxt.credentials()
+#print "\n...final principal set..."
+#for x in out[1]:
+#    print "%s " % x.string()
+
+# create an attribute cert
+# iceCream.delicous <- chocolate
+attr = Attribute(id, "delicious", 1000)
+attr.principal(cid.keyid())
+attr.bake()
+
+# load attribute cert into the context
+ctxt.load_attribute_chunk(attr.cert_chunk())
+
+# another way to load the attribute cert into the context,
+# not implemented, ctxt.load_attribute(attr)
+
+# yet another way to load the attribute cert into the context,
+attr.write_file(argv[3])
+# ctxt.load_attribute_file(argv[3])
+
+# run a proof
+(success, credentials) = ctxt.query("%s.delicious" % id.keyid(), cid.keyid())
+
+if success:
+    print "success!"
+
+for credential in credentials:
+    print "credential %s <- %s" % (credential.head().string(), credential.tail().string())
+
+
Index: examples/example_scripts/python/abac_e_attr.py
===================================================================
--- examples/example_scripts/python/abac_e_attr.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/abac_e_attr.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+
+"""
+   abac_e_attr.py
+
+   To demonstrate how to use ABAC's api in python with principal credential that uses
+   encrypted private key
+
+   call:   attr_e_abac Soda_ID.pem Soda_private.pem Soda_attr.der pfile Cream_ID.pem
+
+   pre-conditions: make a passpphrase file and
+                   generate a Soda_private.pem with passphrase with openssl
+                   generate Soda_ID.pem with creddy with supplied private key
+                   generate Cream_ID.pem and clear Cream_private.pem with
+                          creddy --generate --cn Cream
+
+   This program will generate an attribute rule, write it out to an external
+           file and also load it into the context 
+           Soda.delicious <- Cream
+
+   Then, a query is made against the context to see if it is populated correctly.
+
+   Note: Cream's principal is loaded without it private key. It does not
+         need to because it is not being used to generate attribute credential
+
+"""
+
+
+
+
+from sys import argv, exit
+from ABAC import Context
+from ABAC import ID, Attribute, Role
+
+debug=0
+
+## initial context
+ctxt = Context()
+
+if len(argv) != 6:
+    print "Usage: abac_attr.py <cert.pem> <key.pem> <attr.xml> <pfile> <c_cert.pem>"
+    exit(1)
+
+# load the ID and its key
+id = None
+try:
+    id = ID(argv[1])
+    id.load_privkey(argv[2])
+    cream_id = ID(argv[5])
+except Exception, e:
+    print "Problem loading ID cert: %s" % e
+    exit(1)
+
+# load the id into the context
+ctxt.load_id_chunk(id.cert_chunk())
+# another way to load the id into the context
+# ctxt.load_id(cream_id), not implemented
+ctxt.load_id_chunk(cream_id.cert_chunk())
+
+# create an attribute cert
+attr = Attribute(id, "delicious", 1000)
+attr.principal(cream_id.keyid())
+attr.bake()
+
+# load attribute cert into the context
+ctxt.load_attribute_chunk(attr.cert_chunk())
+
+# another way to load the attribute cert into the context,
+# ctxt.load_attribute(attr)
+
+# yet another way to load the attribute cert into the context,
+attr.write_file(argv[3])
+# ctxt.load_attribute_file(argv[3])
+
+print '---------'
+(credentials) = ctxt.credentials()
+for credential in credentials:
+    print "credential %s <- %s" % (credential.head().string(), credential.tail().string())
+print '---------'
+
+
+(success, credentials) = ctxt.query("%s.delicious" % id.keyid(), cream_id.keyid())
+if success:
+    print "success!"
+for credential in credentials:
+    print "credential %s <- %s" % (credential.head().string(), credential.tail().string())
+
Index: examples/example_scripts/python/abac_keyid.py
===================================================================
--- examples/example_scripts/python/abac_keyid.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/abac_keyid.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+
+"""
+  abac_keyid.py
+
+   To demonstrate how to use ABAC's api in python to access keyid of a 
+principal credential
+
+   pre-condition: generate IceCream_ID.pem and IceCream_private.pem with
+           creddy --generate --cn IceCream
+
+   keyid of the loaded principal credential is printed
+
+"""
+
+from sys import argv, exit
+from ABAC import ID
+
+if len(argv) < 2:
+    print "Usage: abac_keyid.py <cert.pem>"
+    exit(1)
+
+id = None
+try:
+    print argv[1]
+    id = ID(argv[1])
+except Exception, e:
+    print "Problem loading cert: %s" % e
+    exit(1)
+
+print id.keyid()
+print "okay"
+
Index: examples/example_scripts/python/abac_keyid2.py
===================================================================
--- examples/example_scripts/python/abac_keyid2.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/abac_keyid2.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+
+"""
+  abac_keyid2.py
+
+   To demonstrate how to use ABAC's api in python to access keyid of a 
+principal credential
+
+   pre-condition: generate IceCream_ID.pem and IceCream_private.pem with
+           creddy --generate --cn IceCream
+
+   keyid of the loaded principal credential is printed
+
+"""
+
+from sys import argv, exit
+from ABAC import ID
+
+if len(argv) < 2:
+    print "Usage: abac_keyid.py <cert.pem>"
+    exit(1)
+
+id = None
+try:
+    print argv[1]
+    id = ID(argv[1])
+    id.load_privkey(argv[2])
+except Exception, e:
+    print "Problem loading cert: %s" % e
+    exit(1)
+
+print id.keyid()
+print 'okay'
+
Index: examples/example_scripts/python/abac_prover.py
===================================================================
--- examples/example_scripts/python/abac_prover.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/abac_prover.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+
+"""
+   abac_prover.py
+    
+   To demonstrate how to use ABAC's api in python to make a query
+
+   call:   abac_prover "keystorestring" "rolestring" "principalstring"
+
+   pre-condition: run make attr_abac  generate IceCream_ID.pem and IceCream_private.pem with
+
+   This program will make a prover call using
+           rolestring <- principalstring
+
+"""
+
+import getopt
+import sys
+from ABAC import Context
+
+
+def usage():
+    print "Usage: abac_prover.py \\"
+    print "        --keystore <keystore> \\"
+    print "        --role <role> --principal <principal> "
+    print "    loads the keystore and runs the query role <-?- principal"
+    sys.exit(1)
+
+keystore = ''
+role = ''
+principal = ''
+
+try:
+    opts, args = getopt.getopt(sys.argv[1:], '', ['keystore=', 'role=', 'principal='])
+except getopt.GetoptError, err:
+    print str(err)
+    sys.exit(1)
+
+for o, a in opts:
+    if o == '--keystore':
+        keystore = a
+    elif o == '--role':
+        role = a
+    elif o == '--principal':
+        principal = a
+    else:
+        assert False, "WAT"
+
+if keystore == '' or role == '' or principal == '':
+    usage()
+
+# code begins here! sorry about that
+
+print keystore
+print role
+print principal
+
+ctx = Context()
+ctx.load_directory(keystore)
+
+(success, credentials) = ctx.query(role, principal)
+
+if success:
+    print "success"
+
+for credential in credentials:
+    print "credential %s <- %s" % (credential.head().string(), credential.tail().string())
+
Index: examples/example_scripts/python/run_e_prover
===================================================================
--- examples/example_scripts/python/run_e_prover	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/run_e_prover	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+keystore=`pwd`
+
+echo "dumdum" > pfile
+openssl genrsa -des3 -out Soda_private.pem -passout file:pfile
+creddy --generate --cn Soda --key Soda_private.pem
+creddy --generate --cn Cream 
+./abac_e_attr.py Soda_ID.pem Soda_private.pem Soda_attr.xml pfile Cream_ID.pem 
+
+
Index: examples/example_scripts/python/run_prover
===================================================================
--- examples/example_scripts/python/run_prover	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/run_prover	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+keystore=`pwd`
+pID=`creddy --keyid --cert ${keystore}/IceCream_ID.pem`
+cID=`creddy --keyid --cert ${keystore}/Chocolate_ID.pem`
+
+role="${pID}.delicious"
+principal="${cID}"
+
+./abac_prover.py --keystore "$keystore" --role "$role" --principal "$principal"
+
+
+
Index: examples/example_scripts/python/run_test
===================================================================
--- examples/example_scripts/python/run_test	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/run_test	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,55 @@
+#!/bin/sh 
+
+echo '---running (python) attr script'
+make run_attr 1>/dev/null 2>& 1
+result=`grep success attr.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
+
+#echo '---running (python) encrypted key attr script'
+#make run_e_attr 1>/dev/null 2>& 1
+#result=`grep succeed e_attr.log 2>/dev/null`
+#if [ "$result" = "" ]; then
+#   echo "   ERROR"
+#else   
+#   echo "   PASSED"
+#fi
+
+echo '---running (python) id script'
+make run_id 1>/dev/null 2>& 1
+result=`grep okay id.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
+
+echo '---running (python) id2 script, expect failure'
+make run_id2 1>/dev/null 2>& 1
+result=`grep "okay" id2.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   PASSED"
+else   
+   echo "   ERROR"
+fi
+
+echo '---running (python) id3 script, expect failure'
+make run_id3 1>/dev/null 2>& 1
+result=`grep "okay" id3.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
+
+echo '---running (python) prover script'
+make run_prove 1>/dev/null 2>& 1
+result=`grep success prover.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
