1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | See README in this directory for the semantics of the example. This file |
---|
5 | constructs the credentials described and puts copies into this directory |
---|
6 | |
---|
7 | cmd1:env keystore=`pwd` ./attr.py |
---|
8 | """ |
---|
9 | |
---|
10 | import os |
---|
11 | import ABAC |
---|
12 | |
---|
13 | ctxt = ABAC.Context() |
---|
14 | print "ABAC version %s" % ctxt.version() |
---|
15 | |
---|
16 | # Keystore is the directory containing the principal credentials. |
---|
17 | # Load existing principals and/or policy credentials |
---|
18 | if (os.environ.has_key("keystore")) : |
---|
19 | keystore=os.environ["keystore"] |
---|
20 | ctxt.load_directory(keystore) |
---|
21 | else: |
---|
22 | print("keystore is not set...") |
---|
23 | exit(1) |
---|
24 | |
---|
25 | ################################################ |
---|
26 | # [keyid:john0].role:likes <- [keyid:john0] |
---|
27 | a="John0_ID.pem" |
---|
28 | ap="John0_private.pem" |
---|
29 | f="John0_likes__John0_attr.der" |
---|
30 | |
---|
31 | aID=ABAC.ID(a); |
---|
32 | aID.id_load_privkey_file(ap); |
---|
33 | aid=aID.id_keyid() |
---|
34 | |
---|
35 | head = ABAC.Role(aid,"likes") |
---|
36 | tail = ABAC.Role(aid) |
---|
37 | attr=ABAC.Attribute(head, 18000) |
---|
38 | attr.attribute_add_tail(tail) |
---|
39 | attr.attribute_bake() |
---|
40 | attr.attribute_write_cert(f) |
---|
41 | |
---|
42 | # [keyid:john1].role:likes <- [keyid:john0].role:likes |
---|
43 | i=1 |
---|
44 | while i <= #VAL#: |
---|
45 | n=i-1 |
---|
46 | |
---|
47 | a="John%s_ID.pem"%i |
---|
48 | ap="John%s_private.pem"%i |
---|
49 | b="John%s_ID.pem"%n |
---|
50 | f="John%s_likes__John%s_likes_attr.der" %(i,n) |
---|
51 | |
---|
52 | aID=ABAC.ID(a); |
---|
53 | aID.id_load_privkey_file(ap); |
---|
54 | aid=aID.id_keyid() |
---|
55 | bID=ABAC.ID(b); |
---|
56 | bid=bID.id_keyid() |
---|
57 | |
---|
58 | head = ABAC.Role(aid,"likes") |
---|
59 | tail = ABAC.Role(bid,"likes") |
---|
60 | attr=ABAC.Attribute(head, 18000) |
---|
61 | attr.attribute_add_tail(tail) |
---|
62 | attr.attribute_bake() |
---|
63 | attr.attribute_write_cert(f) |
---|
64 | i=i+1 |
---|
65 | |
---|