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 | warnerbrosID=ABAC.ID("WarnerBros_ID.pem"); |
---|
28 | warnerbrosID.id_load_privkey_file("WarnerBros_private.pem"); |
---|
29 | ctxt.load_id(warnerbrosID) |
---|
30 | warnerbros=warnerbrosID.id_keyid() |
---|
31 | |
---|
32 | batmanID=ABAC.ID("Batman_ID.pem"); |
---|
33 | batmanID.id_load_privkey_file("Batman_private.pem"); |
---|
34 | ctxt.load_id(batmanID) |
---|
35 | batman=batmanID.id_keyid() |
---|
36 | |
---|
37 | |
---|
38 | ################################################ |
---|
39 | #[keyid:Acme].role:buy_rockets <- [keyid:Acme].role:preferred_customer |
---|
40 | # & [keyid:WarnerBros].role:charater |
---|
41 | head = ABAC.Role(acme,"buy_rockets") |
---|
42 | tail1 = ABAC.Role(acme,"preferred_customer") |
---|
43 | tail2 = ABAC.Role(warnerbros,"character") |
---|
44 | attr=ABAC.Attribute(head, 1800) |
---|
45 | attr.attribute_add_tail(tail1) |
---|
46 | attr.attribute_add_tail(tail2) |
---|
47 | attr.attribute_bake() |
---|
48 | attr.attribute_write_cert("Acme_buy_rockets__Acme_preferred_customer_and_WarnerBros_character_attr.der") |
---|
49 | ctxt.load_attribute_file("Acme_buy_rockets__Acme_preferred_customer_and_WarnerBros_character_attr.der") |
---|
50 | print attr.string() |
---|
51 | print attr.typed_string() |
---|
52 | print "\n" |
---|
53 | |
---|
54 | ################################################# |
---|
55 | #[keyid:Acme].role:preferred_customer <- [keyid:Coyote] |
---|
56 | head = ABAC.Role(acme,"preferred_customer") |
---|
57 | tail = ABAC.Role(coyote) |
---|
58 | attr=ABAC.Attribute(head, 1800) |
---|
59 | attr.attribute_add_tail(tail) |
---|
60 | attr.attribute_bake() |
---|
61 | attr.attribute_write_cert("Acme_preferred_customer__Coyote_attr.der") |
---|
62 | ctxt.load_attribute_file("Acme_preferred_customer__Coyote_attr.der") |
---|
63 | print attr.string() |
---|
64 | print attr.typed_string() |
---|
65 | print "\n" |
---|
66 | |
---|
67 | ################################################# |
---|
68 | #[keyid:Acme].role:preferred_customer <- [keyid:Batman] |
---|
69 | head = ABAC.Role(acme,"preferred_customer") |
---|
70 | tail = ABAC.Role(batman) |
---|
71 | attr=ABAC.Attribute(head,1800) |
---|
72 | attr.attribute_add_tail(tail) |
---|
73 | attr.attribute_bake() |
---|
74 | attr.attribute_write_cert("Acme_preferred_customer__Batman_attr.der") |
---|
75 | ctxt.load_attribute_file("Acme_preferred_customer__Batman_attr.der") |
---|
76 | print attr.string() |
---|
77 | print attr.typed_string() |
---|
78 | print "\n" |
---|
79 | |
---|
80 | |
---|
81 | ################################################ |
---|
82 | #[keyid:WarnerBros].role:character <- [keyid:Coyote] |
---|
83 | head=ABAC.Role(warnerbros,"character") |
---|
84 | tail = ABAC.Role(coyote) |
---|
85 | attr=ABAC.Attribute(head, 1800) |
---|
86 | attr.attribute_add_tail(tail) |
---|
87 | attr.attribute_bake() |
---|
88 | attr.attribute_write_cert("WarnerBros_character__Coyote_attr.der") |
---|
89 | #ctxt.load_attribute_file("WarnerBros_character__Coyote_attr.der") |
---|
90 | ctxt.load_attribute(attr) |
---|
91 | #print attr.string() |
---|
92 | #print attr.typed_string() |
---|
93 | #print "\n" |
---|
94 | |
---|
95 | ctxt.dump_yap_db() |
---|
96 | ## |
---|