1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | to test with python |
---|
5 | |
---|
6 | cmd:env keystore=`pwd` ./id.py |
---|
7 | |
---|
8 | """ |
---|
9 | |
---|
10 | import os |
---|
11 | import ABAC |
---|
12 | |
---|
13 | ctxt = ABAC.Context() |
---|
14 | |
---|
15 | # Keystore is the directory containing the principal credentials. |
---|
16 | # Load existing principals and/or policy credentials |
---|
17 | if (os.environ.has_key("keystore")) : |
---|
18 | keystore=os.environ["keystore"] |
---|
19 | # ctxt.load_directory(keystore) |
---|
20 | else: |
---|
21 | print("keystore is not set...") |
---|
22 | exit(1) |
---|
23 | |
---|
24 | ## case 1 |
---|
25 | ## creating and writing out using libabac ID |
---|
26 | id=ABAC.ID("Mary", 0) |
---|
27 | print "adding -> %s(Mary/good)" % id.keyid() |
---|
28 | id.write_cert_file("Mary_ID.pem") |
---|
29 | id.write_privkey_file("Mary_private.pem") |
---|
30 | ## load principal with id/key file pair |
---|
31 | ## note, with this, we do not have handle on the keyid |
---|
32 | ## to Mary but it will be in the db |
---|
33 | #XXX# ctxt.load_id_files("Mary_ID.pem","Mary_private.pem") |
---|
34 | |
---|
35 | ## case 2 |
---|
36 | ## creating principal using ID |
---|
37 | id2=ABAC.ID("Jack2", 0) |
---|
38 | print "adding -> %s(Jack2/good)" % id2.keyid() |
---|
39 | ## load principal directly with the ID, no external |
---|
40 | ## credential files were created |
---|
41 | #XXX# ctxt.load_id(id2) |
---|
42 | |
---|
43 | ## case 3 |
---|
44 | ## creating principal using ID |
---|
45 | id3=ABAC.ID("Mark", 0) |
---|
46 | print "adding -> %s(Mark/good)" % id3.keyid() |
---|
47 | ## write cert and key content to a combo file. One is appended |
---|
48 | ## after another |
---|
49 | id3.write_privkey_file("Mark_IDKEY.pem") |
---|
50 | id3.write_cert_file("Mark_IDKEY.pem") |
---|
51 | ## load principal in with the combo file with the tandem format |
---|
52 | ctxt.load_id_file("Mark_IDKEY.pem") |
---|
53 | |
---|
54 | ## case 4 |
---|
55 | ## creating principal using ID |
---|
56 | id4=ABAC.ID("John", 0) |
---|
57 | print "adding -> %s(John/good,invisible)" % id4.keyid() |
---|
58 | id4.write_cert_file("John_other.pem") |
---|
59 | ## load id without the key file |
---|
60 | ctxt.load_id_file("John_other.pem") |
---|
61 | |
---|
62 | ## case 5 |
---|
63 | ## creating principal using ID |
---|
64 | id5=ABAC.ID("Lori", 0) |
---|
65 | print "adding -> %s(Lori/good,nokey)" % id5.keyid() |
---|
66 | ## write just cert into the combo file |
---|
67 | id5.write_cert_file("Lori_IDKEY.pem") |
---|
68 | ##load principal from a combo file that only contains cert part |
---|
69 | ctxt.load_id_file("Lori2_IDKEY.pem") |
---|
70 | |
---|
71 | ## case 6 |
---|
72 | ## creating principal using ID |
---|
73 | id6=ABAC.ID("Tom", 0) |
---|
74 | print "adding -> %s(Tom/bad,nocert)" % id6.keyid() |
---|
75 | ## write just key into the combo file |
---|
76 | id6.write_privkey_file("Tom_IDKEY.pem") |
---|
77 | ## load principal from combo file that only contains key part |
---|
78 | ctxt.load_id_file("Tom_IDKEY.pem") |
---|
79 | |
---|
80 | ## case 7 |
---|
81 | ## creating ID using chunk |
---|
82 | ## this already created a Tim with private key and |
---|
83 | ## stored in the master list |
---|
84 | id7=ABAC.ID("Tim", 0) |
---|
85 | chunk=id7.cert_chunk() |
---|
86 | id77=ABAC.ID_chunk(chunk) |
---|
87 | ## load principal from new id |
---|
88 | ctxt.load_id_chunk(id77.cert_chunk()) |
---|
89 | |
---|
90 | ## case 8 |
---|
91 | ## load directly using chunk |
---|
92 | ## this already created a Stanley with private key |
---|
93 | ## and stored in the master list |
---|
94 | id8=ABAC.ID("Stanley", 0) |
---|
95 | chunk=id8.cert_chunk() |
---|
96 | ## load principal as chunk |
---|
97 | ctxt.load_id_chunk(chunk) |
---|
98 | |
---|
99 | ## case 9 |
---|
100 | ## failure case, loading a non-existing combo file |
---|
101 | print "adding -> Casper(bad,unknown file)" |
---|
102 | ctxt.load_id_file("Casper_IDKEY.pem") |
---|
103 | |
---|