source: examples/python_tests/acme_rockets_intersection_rt0/attr.py @ a59bc06

mei_rt2mei_rt2_fix_1
Last change on this file since a59bc06 was 646e57e, checked in by Mei <mei@…>, 12 years ago

1) add partial proof

  • Property mode set to 100755
File size: 3.6 KB
Line 
1#!/usr/bin/env python
2
3"""
4See README in this directory for the semantics of the example.  This file
5constructs the credentials described and puts copies into this directory
6
7cmd1:env keystore=`pwd` ./attr.py
8"""
9import os
10import ABAC
11
12ctxt = ABAC.Context()
13print "ABAC version %s" % ctxt.version()
14
15# Keystore is the directory containing the principal credentials.
16# Load existing principals and/or policy credentials
17if (os.environ.has_key("keystore")) :
18    keystore=os.environ["keystore"]
19    ctxt.load_directory(keystore)
20else:
21    print("keystore is not set...")
22    exit(1)
23
24# retrieve principals' keyid value from local credential files
25acmeID=ABAC.ID("Acme_ID.pem");
26acmeID.id_load_privkey_file("Acme_private.pem");
27ctxt.load_id(acmeID)
28acme=acmeID.id_keyid()
29
30coyoteID=ABAC.ID("Coyote_ID.pem");
31coyoteID.id_load_privkey_file("Coyote_private.pem");
32ctxt.load_id(coyoteID)
33coyote=coyoteID.id_keyid()
34
35warnerbrosID=ABAC.ID("WarnerBros_ID.pem");
36warnerbrosID.id_load_privkey_file("WarnerBros_private.pem");
37ctxt.load_id(warnerbrosID)
38warnerbros=warnerbrosID.id_keyid()
39
40batmanID=ABAC.ID("Batman_ID.pem");
41batmanID.id_load_privkey_file("Batman_private.pem");
42ctxt.load_id(batmanID)
43batman=batmanID.id_keyid()
44
45
46################################################
47# Credential 1, establish the intersection rule on who can buy
48# rockets from Acme
49#[keyid:Acme].role:buy_rockets <- [keyid:Acme].role:preferred_customer
50#                                    & [keyid:WarnerBros].role:charater
51head = ABAC.Role(acme,"buy_rockets")
52tail1 = ABAC.Role(acme,"preferred_customer")
53tail2 = ABAC.Role(warnerbros,"character")
54attr=ABAC.Attribute(head, 1800)
55
56# to add intersection, just add multiple tails, make sure they are all
57# roles or all osets
58attr.attribute_add_tail(tail1)
59attr.attribute_add_tail(tail2)
60
61# finalize the rule
62attr.attribute_bake()
63
64# save it out as external credential file
65attr.attribute_write_cert("Acme_buy_rockets__Acme_preferred_customer_and_WarnerBros_character_attr.der")
66
67# load it into context from the just created credential file
68ctxt.load_attribute_file("Acme_buy_rockets__Acme_preferred_customer_and_WarnerBros_character_attr.der")
69print attr.string() 
70print attr.typed_string()
71print "\n"
72
73#################################################
74# Credential 2
75#[keyid:Acme].role:preferred_customer <- [keyid:Coyote]
76head = ABAC.Role(acme,"preferred_customer")
77tail = ABAC.Role(coyote)
78attr=ABAC.Attribute(head, 1800)
79attr.attribute_add_tail(tail)
80attr.attribute_bake()
81attr.attribute_write_cert("Acme_preferred_customer__Coyote_attr.der")
82ctxt.load_attribute_file("Acme_preferred_customer__Coyote_attr.der")
83print attr.string() 
84print attr.typed_string()
85print "\n"
86
87#################################################
88# Credential 3
89#[keyid:Acme].role:preferred_customer <- [keyid:Batman]
90head = ABAC.Role(acme,"preferred_customer")
91tail = ABAC.Role(batman)
92attr=ABAC.Attribute(head,1800)
93attr.attribute_add_tail(tail)
94attr.attribute_bake()
95attr.attribute_write_cert("Acme_preferred_customer__Batman_attr.der")
96ctxt.load_attribute_file("Acme_preferred_customer__Batman_attr.der")
97print attr.string() 
98print attr.typed_string()
99print "\n"
100
101
102################################################
103# Credential 4
104#[keyid:WarnerBros].role:character <- [keyid:Coyote]
105head=ABAC.Role(warnerbros,"character")
106tail = ABAC.Role(coyote)
107attr=ABAC.Attribute(head, 1800)
108attr.attribute_add_tail(tail)
109attr.attribute_bake()
110attr.attribute_write_cert("WarnerBros_character__Coyote_attr.der")
111
112# demonstrate how attribute can be load from structure insted of a file
113ctxt.load_attribute(attr)
114print attr.string() 
115print attr.typed_string()
116print "\n"
117
Note: See TracBrowser for help on using the repository browser.