source: examples/python_tests/acme_multi_rt0/attr.py @ dfe6b61

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

1) add backtrack/multiple solutions proof code changes and new

examples.

  • Property mode set to 100755
File size: 3.0 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# retrieve principals' keyid value from local credential files
16acmeID=ABAC.ID("Acme_ID.pem");
17acmeID.id_load_privkey_file("Acme_private.pem");
18ctxt.load_id(acmeID)
19acme=acmeID.id_keyid()
20
21coyoteID=ABAC.ID("Coyote_ID.pem");
22coyoteID.id_load_privkey_file("Coyote_private.pem");
23ctxt.load_id(coyoteID)
24coyote=coyoteID.id_keyid()
25
26################################################
27# Credential 1, only preferred_customer of Acme can buy_rockets
28#[keyid:Acme].role:buy_rockets <- [keyid:Acme].role:preferred_customer
29head = ABAC.Role(acme,"buy_rockets")
30tail = ABAC.Role(acme,"preferred_customer")
31
32# compose the attribute of a basic rt0 role rule
33attr=ABAC.Attribute(head, 1800)
34attr.attribute_add_tail(tail)
35
36# finalize the policy
37attr.attribute_bake()
38
39# create a policy file at the file system
40attr.attribute_write_cert("Acme_buy_rockets__Acme_preferred_customer_attr.der")
41
42# load the policy into current context by with the newly created policy file
43ctxt.load_attribute_file("Acme_buy_rockets__Acme_preferred_customer_attr.der")
44print attr.string() 
45print attr.typed_string()
46print "\n"
47
48################################################
49# Credential 2, only worst_lucked of Acme can buy_rockets
50#[keyid:Acme].role:buy_rockets <- [keyid:Acme].role:worst_lucked
51head = ABAC.Role(acme,"buy_rockets")
52tail = ABAC.Role(acme,"worst_lucked")
53
54# compose the attribute of a basic rt0 role rule
55attr=ABAC.Attribute(head, 1800)
56attr.attribute_add_tail(tail)
57
58# finalize the policy
59attr.attribute_bake()
60
61# create a policy file at the file system
62attr.attribute_write_cert("Acme_buy_rockets__Acme_worst_lucked_attr.der")
63
64# load the policy into current context by with the newly created policy file
65ctxt.load_attribute_file("Acme_buy_rockets__Acme_worst_lucked_attr.der")
66print attr.string() 
67print attr.typed_string()
68print "\n"
69
70#################################################
71# Credential 3
72#[keyid:Acme].role:preferred_customer <- [keyid:Coyote]
73head = ABAC.Role(acme,"preferred_customer")
74tail = ABAC.Role(coyote)
75attr=ABAC.Attribute(head, 1800)
76attr.attribute_add_tail(tail)
77attr.attribute_bake()
78attr.attribute_write_cert("Acme_preferred_customer__Coyote_attr.der")
79ctxt.load_attribute_file("Acme_preferred_customer__Coyote_attr.der")
80print attr.string() 
81print attr.typed_string()
82print "\n"
83
84#################################################
85# Credential 4
86#[keyid:Acme].role:worst_lucked <- [keyid:Coyote]
87head = ABAC.Role(acme,"worst_lucked")
88tail = ABAC.Role(coyote)
89attr=ABAC.Attribute(head, 1800)
90attr.attribute_add_tail(tail)
91attr.attribute_bake()
92attr.attribute_write_cert("Acme_worst_lucked__Coyote_attr.der")
93ctxt.load_attribute_file("Acme_worst_lucked__Coyote_attr.der")
94print attr.string() 
95print attr.typed_string()
96print "\n"
97
Note: See TracBrowser for help on using the repository browser.