Index: examples/python_tests/evaluator_rt1/README
===================================================================
--- examples/python_tests/evaluator_rt1/README	(revision 5f551d32ce8befe42bdd0b6cc9391e217749c595)
+++ examples/python_tests/evaluator_rt1/README	(revision 5f551d32ce8befe42bdd0b6cc9391e217749c595)
@@ -0,0 +1,76 @@
+#!/bin/sh
+#
+# This example demonstrates linking parameterized roles and delegating across
+# institutions.  There are 4 principals USC, ISI, John, and Maryann.  USC and
+# ISI are companies, and USC owns ISI.  USC sets the policy that the manager of
+# a principal (an employee) has the role of evaluating that employee (and no
+# others).  That policy is expressed in Credential 1.  Credential 2 says that
+# ISI's assignment of manager roles is accepted by USC.  Similarly Credential 4
+# says that any ISI employee is a USC employee.
+#
+# Credential 3 encodes ISI asserting that John is the manager of Maryann and
+# credentials 5 and 6 idicate that John and Maryann are ISI employees.
+# 
+# the attached ./run_query script queries that USC grants John the role of evaluator
+# of Maryann, that ISI asserts John is Maryann's manager and that John is an
+# ISI employee.
+
+# evaluator_rt1_typed
+
+#[keyid:USC].role:employee <-?- [keyid:John]
+#[keyid:USC].role:evaluatorOf([keyid:Maryann])<-?- [keyid:John]
+
+creddy --generate --cn ISI
+creddy --generate --cn USC
+creddy --generate --cn Maryann
+creddy --generate --cn John
+
+isi_keyid=`creddy --keyid --cert ISI_ID.pem`
+usc_keyid=`creddy --keyid --cert USC_ID.pem`
+maryann_keyid=`creddy --keyid --cert Maryann_ID.pem`
+john_keyid=`creddy --keyid --cert John_ID.pem`
+
+managerof_maryann="managerOf([keyid:$maryann_keyid])"
+
+#[keyid:USC].role:evaluatorOf([principal:?K])<-[keyid:USC].role:managerOf([principal:?K])
+# Credential 1
+creddy --attribute \
+       --issuer USC_ID.pem --key USC_private.pem --role 'evaluatorOf([principal:?K])' \
+       --subject-cert USC_ID.pem --subject-role 'managerOf([principal:?K])' \
+       --out USC_evaluatorof_qK__USC_managerof_qK_attr.der
+
+#[keyid:USC].role:managerOf([principal:?K])<-[keyid:ISI].role:managerOf([principal:?K])
+# Credential 2
+creddy --attribute \
+       --issuer USC_ID.pem --key USC_private.pem --role 'managerOf([principal:?K])' \
+       --subject-cert ISI_ID.pem --subject-role 'managerOf([principal:?K])' \
+       --out USC_managerof_qK__USC_employee_attr.der
+
+#[keyid:ISI].role:managerOf([keyid:Maryann]) <- [keyid:John]
+# Credential 3
+creddy --attribute \
+       --issuer ISI_ID.pem --key ISI_private.pem --role "$managerof_maryann" \
+       --subject-cert John_ID.pem \
+       --out ISI_manageof_Maryann__John_attr.der
+
+#[keyid:USC].role:employee <- [keyid:ISI].role:employee
+# Credential 4
+creddy --attribute \
+       --issuer USC_ID.pem --key USC_private.pem --role employee \
+       --subject-cert ISI_ID.pem --subject-role employee \
+       --out USC_employee__ISI_employee_attr.der
+
+#[keyid:ISI].role:employee  <- [keyid:Maryann]
+# Credential 5
+creddy --attribute \
+       --issuer ISI_ID.pem --key ISI_private.pem --role employee \
+       --subject-cert Maryann_ID.pem \
+       --out ISI_employee__Maryann_attr.der
+
+#[keyid:ISI].role:employee <- [keyid:John]
+# Credential 6
+creddy --attribute \
+       --issuer ISI_ID.pem --key ISI_private.pem --role employee \
+       --subject-cert John_ID.pem \
+       --out ISI_employee__John_attr.der
+
Index: examples/python_tests/evaluator_rt1/attr.py
===================================================================
--- examples/python_tests/evaluator_rt1/attr.py	(revision 5f551d32ce8befe42bdd0b6cc9391e217749c595)
+++ examples/python_tests/evaluator_rt1/attr.py	(revision 5f551d32ce8befe42bdd0b6cc9391e217749c595)
@@ -0,0 +1,144 @@
+#!/usr/bin/env python
+
+"""
+  to test with 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"
+
+isiID=ABAC.ID("ISI_ID.pem")
+isiID.id_load_privkey_file("ISI_private.pem");
+isi=isiID.id_keyid()
+
+uscID=ABAC.ID("USC_ID.pem")
+uscID.id_load_privkey_file("USC_private.pem");
+usc=uscID.id_keyid()
+
+maryannID=ABAC.ID("Maryann_ID.pem")
+maryannID.id_load_privkey_file("Maryann_private.pem");
+maryann=maryannID.id_keyid()
+
+johnID=ABAC.ID("John_ID.pem")
+johnID.id_load_privkey_file("John_private.pem");
+john=johnID.id_keyid()
+
+################################################
+#[keyid:USC].role:evaluatorOf([principal:?K])
+#           <-[keyid:USC].role:managerOf([principal:?K])
+param=ABAC.DataTerm("principal", "K")
+head = ABAC.Role(usc,"evaluatorOf")
+head.role_add_data_term(param)
+param=ABAC.DataTerm("principal","K")
+tail = ABAC.Role(usc,"managerOf")
+tail.role_add_data_term(param)
+attr=ABAC.Attribute(head, 1800)
+attr.attribute_add_tail(tail)
+attr.attribute_bake()
+attr.attribute_write_cert("USC_evaluatorof_qK__USC_managerof_qK_attr.der")
+ctxt.load_attribute_file("USC_evaluatorof_qK__USC_managerof_qK_attr.der")
+print attr.string() 
+print attr.typed_string()
+print "\n"
+
+#################################################
+# [keyid:USC].role:managerOf([principal:?K])
+#            <-[keyid:ISI].role:managerOf([principal:?K])
+#
+param=ABAC.DataTerm("principal", "K")
+head = ABAC.Role(usc,"managerOf")
+head.role_add_data_term(param)
+param=ABAC.DataTerm("principal", "K")
+tail = ABAC.Role(isi,"managerOf")
+tail.role_add_data_term(param)
+attr=ABAC.Attribute(head, 1800)
+attr.attribute_add_tail(tail)
+attr.attribute_bake()
+attr.attribute_write_cert("USC_managerof_qK__USC_employee_attr.der")
+ctxt.load_attribute_file("USC_managerof_qK__USC_employee_attr.der")
+print attr.string() 
+print attr.typed_string()
+print "\n"
+
+#################################################
+# [keyid:ISI].role:managerOf([keyid:Maryann]) 
+#                        <- [keyid:John]
+param=ABAC.DataTerm(maryannID)
+head = ABAC.Role(isi,"managerOf")
+head.role_add_data_term(param)
+tail = ABAC.Role(john)
+attr=ABAC.Attribute(head, 1800)
+attr.attribute_add_tail(tail)
+attr.attribute_bake()
+attr.attribute_write_cert("ISI_manageof_Maryann__John_attr.der")
+ctxt.load_attribute_file("ISI_manageof_Maryann__John_attr.der")
+print attr.string() 
+print attr.typed_string()
+print "\n"
+
+################################################
+# [keyid:USC].role:employee <- [keyid:ISI].role:employee
+head=ABAC.Role(usc,"employee")
+tail = ABAC.Role(isi,"employee")
+attr=ABAC.Attribute(head, 1800)
+attr.attribute_add_tail(tail)
+attr.attribute_bake()
+attr.attribute_write_cert("USC_employee__ISI_employee_attr.der")
+#ctxt.load_attribute_file("USC_employee__ISI_employee_attr.der")
+ctxt.load_attribute(attr)
+#print attr.string() 
+#print attr.typed_string()
+#print "\n"
+
+
+#################################################
+# [keyid:ISI].role:employee  <- [keyid:Maryann]
+head = ABAC.Role(isi,"employee")
+tail= ABAC.Role(maryann)
+attr=ABAC.Attribute(head, 1800)
+attr.attribute_add_tail(tail)
+attr.attribute_bake()
+attr.attribute_write_cert("ISI_employee__Maryann_attr.der")
+#ctxt.load_attribute_file("ISI_employee__Maryann_attr.der")
+ctxt.load_attribute(attr)
+print attr.string() 
+print attr.typed_string()
+print "\n"
+
+#################################################
+# [keyid:ISI].role:employee  <- [keyid:John]
+head = ABAC.Role(isi,"employee")
+tail= ABAC.Role(john)
+attr=ABAC.Attribute(head, 1800)
+attr.attribute_add_tail(tail)
+attr.attribute_bake()
+attr.attribute_write_cert("ISI_employee__John_attr.der")
+#ctxt.load_attribute_file("ISI_employee__John_attr.der")
+ctxt.load_attribute(attr)
+print attr.string() 
+print attr.typed_string()
+print "\n"
+
+ctxt.dump_yap_db()
+##
Index: examples/python_tests/evaluator_rt1/evaluator.save
===================================================================
--- examples/python_tests/evaluator_rt1/evaluator.save	(revision 5f551d32ce8befe42bdd0b6cc9391e217749c595)
+++ examples/python_tests/evaluator_rt1/evaluator.save	(revision 5f551d32ce8befe42bdd0b6cc9391e217749c595)
@@ -0,0 +1,35 @@
+% Restoring file /usr/local/lib/Yap/startup.yss
+
+===good============ USC.evaluatorOf(Maryann) <- John
+YAP query succeed
+pUSC.evaluatorOf(K) <- pUSC.managerOf(K)
+pUSC.managerOf(K) <- pISI.managerOf(K)
+pISI.managerOf(pMaryann) <- pJohn
+
+===good============ USC.managerOf(Maryann) <- John
+YAP query succeed
+pUSC.managerOf(K) <- pISI.managerOf(K)
+pISI.managerOf(pMaryann) <- pJohn
+
+===good============  USC.employee <-?- John
+YAP query succeed
+pUSC.employee <- pISI.employee
+pISI.employee <- pJohn
+
+...final principal set...
+(pISI,keyid,y) 
+(pJohn,keyid,y) 
+(pMaryann,keyid,y) 
+(pUSC,keyid,y) 
+
+
+
+...final policy attribute set...
+pISI.employee <- pJohn
+pISI.employee <- pMaryann
+pISI.managerOf(pMaryann) <- pJohn
+pUSC.employee <- pISI.employee
+pUSC.evaluatorOf(K) <- pUSC.managerOf(K)
+pUSC.managerOf(K) <- pISI.managerOf(K)
+
+
Index: examples/python_tests/evaluator_rt1/query.py
===================================================================
--- examples/python_tests/evaluator_rt1/query.py	(revision 5f551d32ce8befe42bdd0b6cc9391e217749c595)
+++ examples/python_tests/evaluator_rt1/query.py	(revision 5f551d32ce8befe42bdd0b6cc9391e217749c595)
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+
+"""
+  to test with python
+
+cmd1:env keystore=`pwd` ./query.py 
+cmd2: env ABAC_CN=1 keystore=`pwd` ./query.py
+
+"""
+
+import os
+import ABAC
+
+ctxt = ABAC.Context()
+
+# print "ABAC version %s" % ctxt.version()
+
+keystore=os.environ["keystore"]
+
+ctxt.load_directory(keystore)
+
+isiID=ABAC.ID("ISI_ID.pem")
+isiID.id_load_privkey_file("ISI_private.pem");
+isi=isiID.id_keyid()
+
+uscID=ABAC.ID("USC_ID.pem")
+uscID.id_load_privkey_file("USC_private.pem");
+usc=uscID.id_keyid()
+
+maryannID=ABAC.ID("Maryann_ID.pem")
+maryannID.id_load_privkey_file("Maryann_private.pem");
+maryann=maryannID.id_keyid()
+
+johnID=ABAC.ID("John_ID.pem")
+johnID.id_load_privkey_file("John_private.pem");
+john=johnID.id_keyid()
+
+##########################################################################
+#role=[keyid:USC].role:evaluatorOf([keyid:Maryann])
+#p=[keyid:John]
+param=ABAC.DataTerm(maryannID)
+role = ABAC.Role(usc,"evaluatorOf")
+role.role_add_data_term(param)
+p = ABAC.Role(john)
+print "\n===good============ USC.evaluatorOf(Maryann) <- John"
+out = ctxt.query(role, p)
+for c in out[1]:
+    print "%s <- %s" % (c.head_string(), c.tail_string())
+
+##########################################################################
+#role=[keyid:USC].role:managerOf([keyid:Maryann])
+#p=[keyid:John]
+param=ABAC.DataTerm(maryannID)
+role = ABAC.Role(usc,"managerOf")
+role.role_add_data_term(param)
+p = ABAC.Role(john)
+print "\n===good============ USC.managerOf(Maryann) <- John"
+out = ctxt.query(role, p)
+for c in out[1]:
+    print "%s <- %s" % (c.head_string(), c.tail_string())
+
+##########################################################################
+# role=[keyid:USC].role:employee 
+# p=[keyid:John]"
+role = ABAC.Role(usc,"employee")
+p = ABAC.Role(john)
+print "\n===good============  USC.employee <-?- John"
+out = ctxt.query(role,p)
+for c in out[1]:
+    print "%s <- %s" % (c.head_string(), c.tail_string())
+
+
+##########################################################################
+# dump the loaded principals/policies 
+#
+out = ctxt.context_principals()
+print "\n...final principal set..."
+for x in out[1]:
+    print "%s " % x.string()
+print "\n"
+out = ctxt.context_credentials()
+print "\n...final policy attribute set..."
+for c in out[1]:
+    print "%s <- %s" % (c.head_string(), c.tail_string())
+print "\n"
+
Index: examples/python_tests/evaluator_rt1/run_test
===================================================================
--- examples/python_tests/evaluator_rt1/run_test	(revision 5f551d32ce8befe42bdd0b6cc9391e217749c595)
+++ examples/python_tests/evaluator_rt1/run_test	(revision 5f551d32ce8befe42bdd0b6cc9391e217749c595)
@@ -0,0 +1,36 @@
+#!/bin/sh 
+
+ABAC_PROVER_PATH="/home/mei/Deter/abac/libabac"
+export ABAC_PROVER_PATH
+
+
+echo '---setup principals'
+env keystore=`pwd` ./setup.py 1>/dev/null 2>& 1
+
+echo '---setup attributes'
+env keystore=`pwd` ./attr.py 1>/dev/null 2>& 1
+
+echo '---run queries'
+
+# Make prover queries
+g_cmd_sha=`grep "cmd1:" query.py |sed "s/cmd1://g" `
+g_cmd_cn=`grep "cmd2:" query.py |sed "s/cmd2://g" `
+
+echo '...with sha'
+eval $g_cmd_sha 2>/dev/null 1 > evaluator.sha
+
+echo '...with cn'
+eval $g_cmd_cn 1>evaluator.cn 2>&1
+
+result=`diff evaluator.cn evaluator.save 2>/dev/null`
+if [ $? -eq 0 ]; then
+    if [ "$result" = "" ]; then
+       echo "   PASSED"
+    else
+       echo "   ERROR:evaluator_rt1 test result differs!!!"
+    fi
+else
+    echo "   ERROR:evaluator_rt1 test result differs!!!"
+fi
+
+
Index: examples/python_tests/evaluator_rt1/setup.py
===================================================================
--- examples/python_tests/evaluator_rt1/setup.py	(revision 5f551d32ce8befe42bdd0b6cc9391e217749c595)
+++ examples/python_tests/evaluator_rt1/setup.py	(revision 5f551d32ce8befe42bdd0b6cc9391e217749c595)
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+"""
+  to test with python
+
+
+"""
+import os
+import ABAC
+
+ctxt = ABAC.Context()
+
+isiID=ABAC.ID("ISI", 0)
+isiID.id_write_cert("ISI_ID.pem")
+isiID.id_write_privkey("ISI_private.pem")
+
+uscID=ABAC.ID("USC", 0)
+uscID.id_write_cert("USC_ID.pem")
+uscID.id_write_privkey("USC_private.pem")
+
+maryannID=ABAC.ID("Maryann", 0)
+maryannID.id_write_cert("Maryann_ID.pem")
+maryannID.id_write_privkey("Maryann_private.pem")
+
+johnID=ABAC.ID("John", 0)
+johnID.id_write_cert("John_ID.pem")
+johnID.id_write_privkey("John_private.pem")
+
