source: swig/python/abac_attr.py @ f89b991

mei_rt2
Last change on this file since f89b991 was 5730a10, checked in by Mei <mei@…>, 12 years ago

1) fix up the sample scripts under swig and added some docs for them

  • Property mode set to 100755
File size: 1.3 KB
Line 
1#!/usr/bin/env python
2
3from sys import argv, exit
4from ABAC import Context
5from ABAC import ID, Attribute, Role
6
7## initial context
8ctxt = Context()
9
10if len(argv) != 4:
11    print "Usage: abac_attr.py <cert.pem> <key.pem> <attr.der>"
12    exit(1)
13
14# load the ID and its key
15id = None
16try:
17    id = ID(argv[1])
18    id.id_load_privkey_file(argv[2])
19except Exception, e:
20    print "Problem loading cert: %s" % e
21    exit(1)
22
23# load the id into the context
24ctxt.load_id_chunks(id.id_cert_chunk(), id.id_privkey_chunk())
25# another way to load the id into the context
26# ctxt.load_id(id)
27
28# create an attribute cert
29head= Role(id.id_keyid(),"delicious")
30tail= Role(id.id_keyid())
31
32attr = Attribute(head, 1800)
33print "making it..."
34attr.attribute_add_tail(tail)
35attr.attribute_bake()
36
37# load attribute cert into the context
38ctxt.load_attribute_chunk(attr.cert_chunk())
39
40# another way to load the attribute cert into the context,
41# ctxt.load_attribute(attr)
42
43# yet another way to load the attribute cert into the context,
44attr.attribute_write_cert(argv[3])
45# ctxt.load_attribute_file(argv[3])
46
47# what is in prolog db
48# ctxt.dump_yap_db()
49
50# run a proof
51role = Role(id.id_keyid(),"delicious")
52p=Role(id.id_keyid())
53
54out = ctxt.query(role, p)
55for c in out[1]:
56    print "%s <- %s" % (c.head_string(), c.tail_string())
57
Note: See TracBrowser for help on using the repository browser.