1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | to test with python |
---|
5 | |
---|
6 | cmd1:env keystore=`pwd` ./id.py |
---|
7 | cmd2:env ABAC_CN=1 keystore=`pwd` ./id.py |
---|
8 | |
---|
9 | """ |
---|
10 | |
---|
11 | import os |
---|
12 | import ABAC |
---|
13 | |
---|
14 | ctxt = ABAC.Context() |
---|
15 | |
---|
16 | print "ABAC version %s" % ctxt.version() |
---|
17 | |
---|
18 | keystore=os.environ["keystore"] |
---|
19 | |
---|
20 | ctxt.load_directory(keystore) |
---|
21 | out = ctxt.context_principals() |
---|
22 | print "...initial principal set..." |
---|
23 | for x in out[1]: |
---|
24 | print "%s " % x.string() |
---|
25 | print "\n" |
---|
26 | |
---|
27 | id=ABAC.ID("Mary", 0) |
---|
28 | print "adding -> %s(good)" % id.name() |
---|
29 | id.write_cert("Mary_ID.pem") |
---|
30 | id.write_privkey("Mary_private.pem") |
---|
31 | ctxt.load_id_file("Mary_ID.pem","Mary_private.pem") |
---|
32 | |
---|
33 | nid=ABAC.ID("Jack", 0) |
---|
34 | print "adding -> %s(good)" % nid.name() |
---|
35 | ctxt.load_id(nid) |
---|
36 | |
---|
37 | id=ABAC.ID("Mark", 0) |
---|
38 | print "adding -> %s(good)" % id.name() |
---|
39 | id.write_privkey("Mark_IDKEY.pem") |
---|
40 | id.write_cert("Mark_IDKEY.pem") |
---|
41 | ctxt.load_id_file("Mark_IDKEY.pem") |
---|
42 | |
---|
43 | id=ABAC.ID("John", 0) |
---|
44 | print "adding -> %s(good,invisible)" % id.name() |
---|
45 | id.write_privkey("John_other.pem") |
---|
46 | id.write_cert("John_other.pem") |
---|
47 | ctxt.load_id_file("John_other.pem") |
---|
48 | |
---|
49 | id=ABAC.ID("Lori", 0) |
---|
50 | print "adding -> %s(good,nokey)" % id.name() |
---|
51 | id.write_cert("Lori_IDKEY.pem") |
---|
52 | ctxt.load_id_file("Lori_IDKEY.pem") |
---|
53 | |
---|
54 | id=ABAC.ID("Tom", 0) |
---|
55 | print "adding -> %s(bad,nocert)" % id.name() |
---|
56 | id.write_privkey("Tom_IDKEY.pem") |
---|
57 | ctxt.load_id_file("Tom_IDKEY.pem") |
---|
58 | |
---|
59 | print "adding -> Casper(bad,unknown file)" |
---|
60 | ctxt.load_id_file("Casper_IDKEY.pem") |
---|
61 | |
---|
62 | print "...final principal set..." |
---|
63 | out = ctxt.context_principals() |
---|
64 | for x in out[1]: |
---|
65 | print "%s " % x.string() |
---|
66 | print "\n" |
---|
67 | |
---|
68 | ctxt.dump_yap() |
---|