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

abac0-leakabac0-meimei-idmei-rt0-nmei_rt0tvf-new-xml
Last change on this file since bc7133b was be6cb41, checked in by Mei <mei@…>, 12 years ago

1) forgot to add the new files

  • Property mode set to 100755
File size: 2.8 KB
RevLine 
[be6cb41]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: ./attr.py
8"""
9import os
10import ABAC
11
12ctxt = ABAC.Context()
13
14# retrieve principals' keyid value from local credential files
15acmeID=ABAC.ID("Acme_ID.pem");
16acmeID.load_privkey("Acme_private.pem");
17ctxt.load_id_chunk(acmeID.cert_chunk())
18acme=acmeID.keyid()
19
20coyoteID=ABAC.ID("Coyote_ID.pem");
21coyoteID.load_privkey("Coyote_private.pem");
22ctxt.load_id_chunk(coyoteID.cert_chunk())
23coyote=coyoteID.keyid()
24
25warnerbrosID=ABAC.ID("WarnerBros_ID.pem");
26warnerbrosID.load_privkey("WarnerBros_private.pem");
27ctxt.load_id_chunk(warnerbrosID.cert_chunk())
28warnerbros=warnerbrosID.keyid()
29
30batmanID=ABAC.ID("Batman_ID.pem");
31batmanID.load_privkey("Batman_private.pem");
32ctxt.load_id_chunk(batmanID.cert_chunk())
33batman=batmanID.keyid()
34
35
36################################################
37# Credential 1, establish the intersection rule on who can buy
38# rockets from Acme
39#[keyid:Acme].role:buy_rockets <- [keyid:Acme].role:preferred_customer
40#                                    & [keyid:WarnerBros].role:charater
41attr = ABAC.Attribute(acmeID, "buy_rockets", 0)
42
43# to add intersection, just add multiple roles
44attr.role(acme,"preferred_customer")
45attr.role(warnerbros,"character")
46
47# finalize the rule
48attr.bake()
49
50# create a policy file at the file system
51attr.write_file("Acme_buy_rockets__Acme_preferred_customer_and_WarnerBros_character_attr.xml")
52
53# load the policy into current context by with the newly created policy file
54ctxt.load_attribute_file("Acme_buy_rockets__Acme_preferred_customer_and_WarnerBros_character_attr.xml")
55
56#################################################
57# Credential 2
58#[keyid:Acme].role:preferred_customer <- [keyid:Coyote]
59attr = ABAC.Attribute(acmeID, "preferred_customer", 0)
60attr.principal(coyote)
61attr.bake()
62
63attr.write_file("Acme_preferred_customer__Coyote_attr.xml")
64ctxt.load_attribute_file("Acme_preferred_customer__Coyote_attr.xml")
65
66#################################################
67# Credential 3
68#[keyid:Acme].role:preferred_customer <- [keyid:Batman]
69attr = ABAC.Attribute(acmeID, "preferred_customer", 0)
70attr.principal(batman)
71attr.bake()
72
73attr.write_file("Acme_preferred_customer__Batman_attr.xml")
74ctxt.load_attribute_file("Acme_preferred_customer__Batman_attr.xml")
75
76################################################
77# Credential 4
78#[keyid:WarnerBros].role:character <- [keyid:Coyote]
79attr = ABAC.Attribute(warnerbrosID, "character", 0)
80attr.principal(coyote)
81attr.bake()
82
83attr.write_file("WarnerBros_character__Coyote_attr.xml")
84ctxt.load_attribute_file("WarnerBros_character__Coyote_attr.xml")
85
86# demonstrate how attribute can be load from structure insted of a file
87ctxt.load_attribute_chunk(attr.cert_chunk())
88
Note: See TracBrowser for help on using the repository browser.