Index: examples/python_tests/acme_rockets_intersection_rt0/README
===================================================================
--- examples/python_tests/acme_rockets_intersection_rt0/README	(revision 7211a95f1601147c8c72a41f8043ef08062de055)
+++ examples/python_tests/acme_rockets_intersection_rt0/README	(revision 7211a95f1601147c8c72a41f8043ef08062de055)
@@ -0,0 +1,30 @@
+#
+# This example demonstrates intersections.  An intersection is a logical and of
+# roles or osets.  An intersection succeeds if the principal is in the
+# intersection of the sets defined by the roles.
+#
+# The policy set by Acme is that a character must both a preferred customer and
+# a WarnerBrothers character to buy rockets.  Each of those attributes is
+# specified by a role.
+#
+# This example defines 4 principals, Acme, WarnerBrothers, Coyote and Batman.
+# Credential 1 defines the policy requiring both roles to get the buy_rockets
+# role.  Credential 2 gives the Coyote a preferred_customer role.  Credential 3
+# gives Batman the preferred_customer role and Credential 4 recognizes the
+# Coyote as a Warner Brothers character.
+#
+#In order to buy rockets from Acme, you must be BOTH a preferred customer
+#AND a WarnerBros character. In this example, the following query will be
+#successful:
+#
+#    Acme.buy_rockets <-?- Coyote
+#
+#The following query will fail (because Batman does not have the
+#attribute WarnerBros.character):
+#
+#    Acme.buy_rockets <-?- Batman
+# 
+# Acme.buy_rockets <- Acme.preferred_customer & WarnerBros.character
+# Acme.preferred_customer <- Coyote
+# Acme.preferred_customer <- Batman
+# WarnerBros.character <- Coyote
Index: examples/python_tests/acme_rockets_intersection_rt0/attr.py
===================================================================
--- examples/python_tests/acme_rockets_intersection_rt0/attr.py	(revision 7211a95f1601147c8c72a41f8043ef08062de055)
+++ examples/python_tests/acme_rockets_intersection_rt0/attr.py	(revision 7211a95f1601147c8c72a41f8043ef08062de055)
@@ -0,0 +1,96 @@
+#!/usr/bin/env python
+
+"""
+  Setup access policy attribute rules
+
+cmd1:env keystore=`pwd` ./attr.py 
+
+"""
+import os
+import ABAC
+
+keystore=os.environ["keystore"]
+
+ctxt = ABAC.Context()
+print "ABAC version %s" % ctxt.version()
+
+acmeID=ABAC.ID("Acme_ID.pem");
+acmeID.id_load_privkey_file("Acme_private.pem");
+ctxt.load_id(acmeID)
+acme=acmeID.id_keyid()
+
+coyoteID=ABAC.ID("Coyote_ID.pem");
+coyoteID.id_load_privkey_file("Coyote_private.pem");
+ctxt.load_id(coyoteID)
+coyote=coyoteID.id_keyid()
+
+warnerbrosID=ABAC.ID("WarnerBros_ID.pem");
+warnerbrosID.id_load_privkey_file("WarnerBros_private.pem");
+ctxt.load_id(warnerbrosID)
+warnerbros=warnerbrosID.id_keyid()
+
+batmanID=ABAC.ID("Batman_ID.pem");
+batmanID.id_load_privkey_file("Batman_private.pem");
+ctxt.load_id(batmanID)
+batman=batmanID.id_keyid()
+
+
+################################################
+#[keyid:Acme].role:buy_rockets <- [keyid:Acme].role:preferred_customer 
+#                                    & [keyid:WarnerBros].role:charater
+head = ABAC.Role(acme,"buy_rockets")
+tail1 = ABAC.Role(acme,"preferred_customer")
+tail2 = ABAC.Role(warnerbros,"character")
+attr=ABAC.Attribute(head, 1800)
+attr.attribute_add_tail(tail1)
+attr.attribute_add_tail(tail2)
+attr.attribute_bake()
+attr.attribute_write_cert("Acme_buy_rockets__Acme_preferred_customer_and_WarnerBros_character_attr.der")
+ctxt.load_attribute_file("Acme_buy_rockets__Acme_preferred_customer_and_WarnerBros_character_attr.der")
+print attr.string() 
+print attr.typed_string()
+print "\n"
+
+#################################################
+#[keyid:Acme].role:preferred_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_file("Acme_preferred_customer__Coyote_attr.der")
+print attr.string() 
+print attr.typed_string()
+print "\n"
+
+#################################################
+#[keyid:Acme].role:preferred_customer <- [keyid:Batman]
+head = ABAC.Role(acme,"preferred_customer")
+tail = ABAC.Role(batman)
+attr=ABAC.Attribute(head,1800)
+attr.attribute_add_tail(tail)
+attr.attribute_bake()
+attr.attribute_write_cert("Acme_preferred_customer__Batman_attr.der")
+ctxt.load_attribute_file("Acme_preferred_customer__Batman_attr.der")
+print attr.string() 
+print attr.typed_string()
+print "\n"
+
+
+################################################
+#[keyid:WarnerBros].role:character <- [keyid:Coyote]
+head=ABAC.Role(warnerbros,"character")
+tail = ABAC.Role(coyote)
+attr=ABAC.Attribute(head, 1800)
+attr.attribute_add_tail(tail)
+attr.attribute_bake()
+attr.attribute_write_cert("WarnerBros_character__Coyote_attr.der")
+#ctxt.load_attribute_file("WarnerBros_character__Coyote_attr.der")
+ctxt.load_attribute(attr)
+#print attr.string() 
+#print attr.typed_string()
+#print "\n"
+
+ctxt.dump_yap_db()
+##
Index: examples/python_tests/acme_rockets_intersection_rt0/intersect.save
===================================================================
--- examples/python_tests/acme_rockets_intersection_rt0/intersect.save	(revision 7211a95f1601147c8c72a41f8043ef08062de055)
+++ examples/python_tests/acme_rockets_intersection_rt0/intersect.save	(revision 7211a95f1601147c8c72a41f8043ef08062de055)
@@ -0,0 +1,26 @@
+% Restoring file /usr/local/lib/Yap/startup.yss
+
+===good============ Acme.buy_rockets <- Coyote
+YAP query succeed
+pAcme.buy_rockets <- pAcme.preferred_customer & pWarnerBros.character
+pAcme.preferred_customer <- pCoyote
+pWarnerBros.character <- pCoyote
+
+===bad============ Acme.buy_rockets <- Batman
+YAP query failed
+
+...final principal set...
+(pAcme,keyid,y) 
+(pBatman,keyid,y) 
+(pCoyote,keyid,y) 
+(pWarnerBros,keyid,y) 
+
+
+
+...final policy attribute set...
+pAcme.buy_rockets <- pAcme.preferred_customer & pWarnerBros.character
+pAcme.preferred_customer <- pBatman
+pAcme.preferred_customer <- pCoyote
+pWarnerBros.character <- pCoyote
+
+
Index: examples/python_tests/acme_rockets_intersection_rt0/query.py
===================================================================
--- examples/python_tests/acme_rockets_intersection_rt0/query.py	(revision 7211a95f1601147c8c72a41f8043ef08062de055)
+++ examples/python_tests/acme_rockets_intersection_rt0/query.py	(revision 7211a95f1601147c8c72a41f8043ef08062de055)
@@ -0,0 +1,79 @@
+#!/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)
+
+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()
+
+warnerbrosID=ABAC.ID("WarnerBros_ID.pem");
+warnerbrosID.id_load_privkey_file("WarnerBros_private.pem");
+warnerbros=warnerbrosID.id_keyid()
+
+batmanID=ABAC.ID("Batman_ID.pem");
+batmanID.id_load_privkey_file("Batman_private.pem");
+batman=batmanID.id_keyid()
+
+##########################################################################
+# role = "[keyid:Acme].role:buy_rockets"
+# p = "[keyid:coyote]" 
+role = ABAC.Role(acme,"buy_rockets")
+p = ABAC.Role(coyote)
+
+print "\n===good============ Acme.buy_rockets <- Coyote"
+out = ctxt.query(role, p)
+
+for c in out[1]:
+    print "%s <- %s" % (c.head_string(), c.tail_string())
+
+
+##########################################################################
+# role = "[keyid:Acme].role:buy_rockets"
+# p = "[keyid:batman]" 
+role = ABAC.Role(acme,"buy_rockets")
+p = ABAC.Role(batman)
+
+print "\n===bad============ Acme.buy_rockets <- Batman"
+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/acme_rockets_intersection_rt0/run_test
===================================================================
--- examples/python_tests/acme_rockets_intersection_rt0/run_test	(revision 7211a95f1601147c8c72a41f8043ef08062de055)
+++ examples/python_tests/acme_rockets_intersection_rt0/run_test	(revision 7211a95f1601147c8c72a41f8043ef08062de055)
@@ -0,0 +1,35 @@
+#!/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 > intersect.sha
+
+echo '...with cn'
+eval $g_cmd_cn 1>intersect.cn 2>&1
+
+result=`diff intersect.cn intersect.save 2>/dev/null`
+if [ $? -eq 0 ]; then
+    if [ "$result" = "" ]; then
+       echo "   PASSED"
+    else
+       echo "   ERROR:acme_rockets_intersection_rt0 test result differs!!!"
+    fi
+else
+    echo "   ERROR:acme_rockets_intersection_rt0 test result differs!!!"
+fi
+
+
Index: examples/python_tests/acme_rockets_intersection_rt0/setup.py
===================================================================
--- examples/python_tests/acme_rockets_intersection_rt0/setup.py	(revision 7211a95f1601147c8c72a41f8043ef08062de055)
+++ examples/python_tests/acme_rockets_intersection_rt0/setup.py	(revision 7211a95f1601147c8c72a41f8043ef08062de055)
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+
+"""
+  Setup 4 principal ID credentials
+
+  Acme, Coyote, WarnerBros and Batman
+
+"""
+import os
+import ABAC
+
+ctxt = ABAC.Context()
+
+alpha=ABAC.ID("Acme", 0)
+alpha.id_write_cert("Acme_ID.pem")
+alpha.id_write_privkey("Acme_private.pem")
+
+coyote=ABAC.ID("Coyote", 0)
+coyote.id_write_cert("Coyote_ID.pem")
+coyote.id_write_privkey("Coyote_private.pem")
+
+warnerbros=ABAC.ID("WarnerBros", 0)
+warnerbros.id_write_cert("WarnerBros_ID.pem")
+warnerbros.id_write_privkey("WarnerBros_private.pem")
+
+batman=ABAC.ID("Batman", 0)
+batman.id_write_cert("Batman_ID.pem")
+batman.id_write_privkey("Batman_private.pem")
+
+
