source: examples/python_tests/acme_rockets_rt0/attr.py @ e205b49

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

1) add more doc to python_tests

  • Property mode set to 100755
File size: 1.8 KB
RevLine 
[5f551d3]1#!/usr/bin/env python
2
3"""
[f824a9e]4See README in this directory for the semantics of the example.  This file
5constructs the credentials described and puts copies into this directory
[5f551d3]6
7cmd1:env keystore=`pwd` ./attr.py
8"""
9import os
10import ABAC
11
12ctxt = ABAC.Context()
13print "ABAC version %s" % ctxt.version()
14
[f824a9e]15# retrieve principals' keyid value from local credential files
[5f551d3]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################################################
[f824a9e]27# Credential 1, only preferred_customer of Acme can buy_rockets
[5f551d3]28#[keyid:Acme].role:buy_rockets <- [keyid:Acme].role:preferred_customer
29head = ABAC.Role(acme,"buy_rockets")
30tail = ABAC.Role(acme,"preferred_customer")
[f824a9e]31
32# compose the attribute of a basic rt0 role rule
[5f551d3]33attr=ABAC.Attribute(head, 1800)
34attr.attribute_add_tail(tail)
[f824a9e]35
36# finalize the policy
[5f551d3]37attr.attribute_bake()
[f824a9e]38
39# create a policy file at the file system
[5f551d3]40attr.attribute_write_cert("Acme_buy_rockets__Acme_preferred_customer_attr.der")
[f824a9e]41
42# load the policy into current context by with the newly created policy file
[5f551d3]43ctxt.load_attribute_file("Acme_buy_rockets__Acme_preferred_customer_attr.der")
44print attr.string() 
45print attr.typed_string()
46print "\n"
47
48#################################################
[f824a9e]49# Credential 2
[5f551d3]50#[keyid:Acme].role:preferred_customer <- [keyid:Coyote]
51head = ABAC.Role(acme,"preferred_customer")
52tail = ABAC.Role(coyote)
53attr=ABAC.Attribute(head, 1800)
54attr.attribute_add_tail(tail)
55attr.attribute_bake()
56attr.attribute_write_cert("Acme_preferred_customer__Coyote_attr.der")
57ctxt.load_attribute_file("Acme_preferred_customer__Coyote_attr.der")
58print attr.string() 
59print attr.typed_string()
60print "\n"
61
Note: See TracBrowser for help on using the repository browser.