source: examples/python_tests/acme_friend_rt1/attr.py @ c3c73bd

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

1) add partial proof

  • Property mode set to 100755
File size: 3.1 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"""
9
10import os
11import ABAC
12
13ctxt = ABAC.Context()
14print "ABAC version %s" % ctxt.version()
15
16# Keystore is the directory containing the principal credentials.
17# Load existing principals and/or policy credentials
18if (os.environ.has_key("keystore")) :
19    keystore=os.environ["keystore"]
20    ctxt.load_directory(keystore)
21else:
22    print("keystore is not set...")
23    exit(1)
24
25out = ctxt.context_principals()
26print "...initial principal set..."
27for x in out[1]:
28    print "%s " % x.string()
29print "\n" 
30
31out = ctxt.context_credentials()
32print "...initial policy attribute set..."
33for c in out[1]:
34    print "%s <- %s" % (c.head_string(), c.tail_string())
35print "\n"
36
37# retrieve principals' keyid value from local credential files
38acmeID=ABAC.ID("Acme_ID.pem")
39acmeID.id_load_privkey_file("Acme_private.pem");
40acme=acmeID.id_keyid()
41
42coyoteID=ABAC.ID("Coyote_ID.pem")
43coyoteID.id_load_privkey_file("Coyote_private.pem");
44coyote=coyoteID.id_keyid()
45
46roadrunnerID=ABAC.ID("Roadrunner_ID.pem")
47roadrunnerID.id_load_privkey_file("Roadrunner_private.pem");
48roadrunner=roadrunnerID.id_keyid()
49
50jackrabbitID=ABAC.ID("Jackrabbit_ID.pem")
51jackrabbitID.id_load_privkey_file("Jackrabbit_private.pem");
52jackrabbit=jackrabbitID.id_keyid()
53
54################################################
55# Credential 1
56# [keyid:Acme].role:preferred_customer <- [keyid:Acme].role:friendof([keyid:Roadrunner])
57head = ABAC.Role(acme,"preferred_customer")
58param=ABAC.DataTerm(roadrunnerID)
59tail = ABAC.Role(acme,"friendof")
60
61# adding parameter to friendOf role
62tail.role_add_data_term(param)
63
64# link the head and tail parts of attribute together
65attr=ABAC.Attribute(head, 1800)
66attr.attribute_add_tail(tail)
67
68# finalize the attribute
69attr.attribute_bake()
70
71# write to file system to be accessible later on
72attr.attribute_write_cert("Acme_preferred_customer__Acme_friendof_Roadrunner_attr.der")
73
74# load the credential just made into the context directly
75# (bypass the external credential file)
76ctxt.load_attribute(attr)
77print attr.string() 
78print attr.typed_string()
79print "\n"
80
81#################################################
82# Credential 2
83# [keyid:Acme].role:prefered_customer <- [keyid:Coyote]
84head = ABAC.Role(acme,"preferred_customer")
85tail = ABAC.Role(coyote)
86attr=ABAC.Attribute(head, 1800)
87attr.attribute_add_tail(tail)
88attr.attribute_bake()
89attr.attribute_write_cert("Acme_preferred_customer__Coyote_attr.der")
90ctxt.load_attribute(attr)
91print attr.string() 
92print attr.typed_string()
93print "\n"
94
95#################################################
96# Credential 3
97# [keyid:Acme].role:friendof([keyid:Roadrunner]) <- [keyid:Jackrabbit]
98param=ABAC.DataTerm(roadrunnerID)
99head = ABAC.Role(acme,"friendof")
100head.role_add_data_term(param)
101tail = ABAC.Role(jackrabbit)
102attr=ABAC.Attribute(head, 1800)
103attr.attribute_add_tail(tail)
104attr.attribute_bake()
105attr.attribute_write_cert("Acme_friendof_Roadrunner__Jackrabbit_attr.der")
106ctxt.load_attribute(attr)
107print attr.string() 
108print attr.typed_string()
109print "\n"
110
Note: See TracBrowser for help on using the repository browser.