1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | Setup access policy attribute rules |
---|
5 | |
---|
6 | cmd1:env keystore=`pwd` ./attr.py |
---|
7 | |
---|
8 | """ |
---|
9 | import os |
---|
10 | import ABAC |
---|
11 | |
---|
12 | keystore=os.environ["keystore"] |
---|
13 | |
---|
14 | ctxt = ABAC.Context() |
---|
15 | print "ABAC version %s" % ctxt.version() |
---|
16 | |
---|
17 | acmeID=ABAC.ID("Acme_ID.pem"); |
---|
18 | acmeID.id_load_privkey_file("Acme_private.pem"); |
---|
19 | ctxt.load_id(acmeID) |
---|
20 | acme=acmeID.id_keyid() |
---|
21 | |
---|
22 | coyoteID=ABAC.ID("Coyote_ID.pem"); |
---|
23 | coyoteID.id_load_privkey_file("Coyote_private.pem"); |
---|
24 | ctxt.load_id(coyoteID) |
---|
25 | coyote=coyoteID.id_keyid() |
---|
26 | |
---|
27 | ################################################ |
---|
28 | #[keyid:Acme].role:buy_rockets <- [keyid:Acme].role:preferred_customer |
---|
29 | head = ABAC.Role(acme,"buy_rockets") |
---|
30 | tail = ABAC.Role(acme,"preferred_customer") |
---|
31 | attr=ABAC.Attribute(head, 1800) |
---|
32 | attr.attribute_add_tail(tail) |
---|
33 | attr.attribute_bake() |
---|
34 | attr.attribute_write_cert("Acme_buy_rockets__Acme_preferred_customer_attr.der") |
---|
35 | ctxt.load_attribute_file("Acme_buy_rockets__Acme_preferred_customer_attr.der") |
---|
36 | print attr.string() |
---|
37 | print attr.typed_string() |
---|
38 | print "\n" |
---|
39 | |
---|
40 | ################################################# |
---|
41 | #[keyid:Acme].role:preferred_customer <- [keyid:Coyote] |
---|
42 | head = ABAC.Role(acme,"preferred_customer") |
---|
43 | tail = ABAC.Role(coyote) |
---|
44 | attr=ABAC.Attribute(head, 1800) |
---|
45 | attr.attribute_add_tail(tail) |
---|
46 | attr.attribute_bake() |
---|
47 | attr.attribute_write_cert("Acme_preferred_customer__Coyote_attr.der") |
---|
48 | ctxt.load_attribute_file("Acme_preferred_customer__Coyote_attr.der") |
---|
49 | print attr.string() |
---|
50 | print attr.typed_string() |
---|
51 | print "\n" |
---|
52 | |
---|
53 | ctxt.dump_yap_db() |
---|
54 | ## |
---|