source: swig/python/abac_attr.py @ 5338995

mei_rt2mei_rt2_fix_1
Last change on this file since 5338995 was 5338995, checked in by Mei <mei@…>, 12 years ago

1) change names for the sample scripts under swig

  • 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# another way to load the attribute cert into the context,
40# ctxt.load_attribute(attr)
41# yet another way to load the attribute cert into the context,
42# attr.attribute_write_cert(argv[3])
43# ctxt.load_attribute_file(argv[3])
44
45# what is in prolog db
46# ctxt.dump_yap_db()
47
48# run a proof
49role = Role(id.id_keyid(),"delicious")
50p=Role(id.id_keyid())
51
52out = ctxt.query(role, p)
53for c in out[1]:
54    print "%s <- %s" % (c.head_string(), c.tail_string())
55
Note: See TracBrowser for help on using the repository browser.