source: examples/python_tests/acme_friend_rt1/attr.py @ 669b481

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

1) finish test conversion from creddy-prover to python
2) update the abac.hh/API doc more, adding more intermediate calls

to make abac.hh more uniform

3) found out why a very long attribute rule can not survive in/out of

ietf_attribute_t call (m64 en/decoding - abac_verifier, alice_rt1)

  • Property mode set to 100755
File size: 2.7 KB
Line 
1#!/usr/bin/env python
2
3"""
4  Setup access policy attribute rules
5
6cmd1:env keystore=`pwd` ./attr.py
7
8"""
9
10import os
11import ABAC
12
13keystore=os.environ["keystore"]
14
15ctxt = ABAC.Context()
16print "ABAC version %s" % ctxt.version()
17
18ctxt.load_directory(keystore)
19
20out = ctxt.context_principals()
21print "...initial principal set..."
22for x in out[1]:
23    print "%s " % x.string()
24print "\n" 
25
26out = ctxt.context_credentials()
27print "...initial policy attribute set..."
28for c in out[1]:
29    print "%s <- %s" % (c.head_string(), c.tail_string())
30print "\n"
31
32acmeID=ABAC.ID("Acme_ID.pem")
33acmeID.id_load_privkey_file("Acme_private.pem");
34acme=acmeID.id_keyid()
35
36coyoteID=ABAC.ID("Coyote_ID.pem")
37coyoteID.id_load_privkey_file("Coyote_private.pem");
38coyote=coyoteID.id_keyid()
39
40roadrunnerID=ABAC.ID("Roadrunner_ID.pem")
41roadrunnerID.id_load_privkey_file("Roadrunner_private.pem");
42roadrunner=roadrunnerID.id_keyid()
43
44jackrabbitID=ABAC.ID("Jackrabbit_ID.pem")
45jackrabbitID.id_load_privkey_file("Jackrabbit_private.pem");
46jackrabbit=jackrabbitID.id_keyid()
47
48################################################
49# [keyid:Acme].role:preferred_customer <- [keyid:Acme].role:friendof([keyid:Roadrunner])
50head = ABAC.Role(acme,"preferred_customer")
51param=ABAC.DataTerm(roadrunnerID)
52tail = ABAC.Role(acme,"friendof")
53tail.role_add_data_term(param)
54attr=ABAC.Attribute(head, 1800)
55attr.attribute_add_tail(tail)
56attr.attribute_bake()
57attr.attribute_write_cert("Acme_preferred_customer__Acme_friendof_Roadrunner_attr.der")
58#ctxt.load_attribute_file("Acme_preferred_customer__Acme_friendof_Roadrunner_attr.der")
59ctxt.load_attribute(attr)
60print attr.string() 
61print attr.typed_string()
62print "\n"
63
64#################################################
65# [keyid:Acme].role:prefered_customer <- [keyid:Coyote]
66head = ABAC.Role(acme,"preferred_customer")
67tail = ABAC.Role(coyote)
68attr=ABAC.Attribute(head, 1800)
69attr.attribute_add_tail(tail)
70attr.attribute_bake()
71attr.attribute_write_cert("Acme_preferred_customer__Coyote_attr.der")
72#ctxt.load_attribute_file("Acme_preferred_customer__Coyote_attr.der")
73ctxt.load_attribute(attr)
74print attr.string() 
75print attr.typed_string()
76print "\n"
77
78#################################################
79# [keyid:Acme].role:friendof([keyid:Roadrunner]) <- [keyid:Jackrabbit]
80param=ABAC.DataTerm(roadrunnerID)
81head = ABAC.Role(acme,"friendof")
82head.role_add_data_term(param)
83tail = ABAC.Role(jackrabbit)
84attr=ABAC.Attribute(head, 1800)
85attr.attribute_add_tail(tail)
86attr.attribute_bake()
87attr.attribute_write_cert("Acme_friendof_Roadrunner__Jackrabbit_attr.der")
88#ctxt.load_attribute_file("Acme_friendof_Roadrunner__Jackrabbit_attr.der")
89ctxt.load_attribute(attr)
90print attr.string() 
91print attr.typed_string()
92print "\n"
93
94ctxt.dump_yap_db()
95##
Note: See TracBrowser for help on using the repository browser.