source: examples/passphrase_tests/python/acme_rockets_rt0/attr.py @ 20eaefe

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

1) modified code all around to add support for encrypted private key for

ID credential

2) add new abac_key_t structure (abac_key.c)
3) add new keycheck option to creddy
4) add 2 new test suites

  • Property mode set to 100755
File size: 1.8 KB
RevLine 
[ba6027a]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_encrypted_privkey_file("Acme_private.pem","pfile");
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
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.