source: examples/example_scripts/c/attr.c @ accd63d

mei_rt2
Last change on this file since accd63d was 2e9455f, checked in by Mei <mei@…>, 11 years ago

1) added namespace
2) tweak ?This,
3) allowing linking role/oset as constraining conditions
4) adding access_tests regression testing that uses GENI's access policy
5) added couple multi contexts regression tests
6) add compression/uncompression calls to abac_encode_string/abac_decode_string
(libstrongwan only allows 512 char for attribute rule storage)
7) add attribute_now option to creddy that takes a whole char string for attribute
rule

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/**
2   attr_abac.c
3
4   To demonstrate how to use ABAC's api in C
5
6   call:   attr_abac IceCream_ID.pem IceCream_private.pem IceCream_attr.der
7
8   pre-condition: generate IceCream_ID.pem and IceCream_private.pem with
9           creddy --generate --cn IceCream
10                  generate Chocolate_ID.pem and Chocolate_private.pem with
11           creddy --generate --cn IceCream
12
13   This program will generate an attribute rule, write it out to an external
14           file and also load it into the context (prolog db)
15           [keyid:IceCream].delicious <- [Keyid:Chocolate]
16
17   Then, a query is made against the context to see if it is populated correctly.
18
19./abac_attr IceCream_ID.pem  IceCream_private.pem IceCream_attr.der Chocolate_ID.pem
20**/
21
22#include <err.h>
23#include <stdio.h>
24#include <assert.h>
25
26#include <abac.h>
27
28extern void abac_print_cred_info(abac_credential_t*, FILE*);
29extern char *abac_id_keyid(abac_id_t *id);
30extern abac_attribute_t *abac_attribute_add_tail(abac_attribute_t *ptr, abac_aspect_t *);
31
32int main(int argc, char **argv) {
33    int i, success=0;
34    abac_credential_t *cred=NULL;
35    abac_credential_t **credentials=NULL;
36    int rc;
37
38    abac_context_t *ctx = abac_context_new();
39
40    /* build up structure */
41    abac_id_t *superK =NULL;
42    abac_id_t *jack =NULL;
43    superK = abac_id_from_file("SuperK_ID.pem");
44    rc=abac_id_load_privkey_file(superK,"SuperK_private.pem");
45
46    jack = abac_id_from_file("Jack_ID.pem");
47    rc=abac_id_load_privkey_file(jack,"Jack_private.pem");
48 
49    abac_context_load_id(ctx,superK);
50    abac_context_load_id(ctx,jack);
51
52    abac_aspect_t *head=abac_role_create(abac_id_keyid(superK),"employee");
53    abac_aspect_t *tail=abac_role_principal_create(abac_id_keyid(jack));
54    abac_attribute_t *attr;
55    rc=abac_attribute_create(&attr, head, NULL, 1800);
56    abac_attribute_add_tail(attr, tail);
57    rc=abac_attribute_bake(attr);
58
59    abac_chunk_t chunk=abac_attribute_cert_chunk(attr);
60    abac_attribute_t *nattr=abac_attribute_from_chunk(chunk);
61    abac_context_load_attribute(ctx,nattr); 
62/*    abac_context_load_attribute(ctx,attr); */ 
63
64    show_yap_db("dump prolog");
65
66    abac_id_free(jack);
67    abac_id_free(superK); 
68    abac_attribute_free(attr);
69    abac_context_free(ctx);
70   
71    return 0;
72}
Note: See TracBrowser for help on using the repository browser.