source: doc/API @ 7211a95

mei_rt2mei_rt2_fix_1
Last change on this file since 7211a95 was 5d06689, checked in by Mei <mei@…>, 13 years ago

1) modify abac.hh and added abac_c.c to unify the c and c++ api

interface (almost)

2) add new API
3) tweak the tests
4) filling missing code for abac_verifier_load_attribute_cert_attribute

  • Property mode set to 100644
File size: 18.0 KB
Line 
1C++ API
2
3(see bottom for notes on C, Perl, and Python.)
4
5ABAC::abac_chunk_t
6   Structure, represents a blob of memory
7   used to load/return DER-encoded X509 certificates
8     -unsigned char *data
9     -int len
10
11ABAC::Constraint
12   Constraint on a data term.
13   There are 3 types:
14     - Role constraint on a principal
15     - Oset constraint on a principal, or a data object
16     - Range/List constraint on a data object
17   It holds a ptr to a abac_condition_t structure
18
19   Constraint()
20     default constructor, do not use, for swig only
21
22   Constraint(const Constraint &)
23     copy constructor, used for cloning a constraint
24
25   ~Constraint()
26     default destructor
27
28   Constraint(Role &)
29     constructor that takes a constraining role
30       [role:?R[{role-constraint}]
31     (c:abac_constraint_from_role)
32
33   Constraint(Oset &)
34     constructor that takes a constraining oset
35       [oset:?O[{oset-constraint}]
36       [urn:?F[keyid:$alpha_keyid].oset:documents([string:?P])]
37     (c:abac_constraint_from_oset)
38
39   Constraint(char *)
40     constructor that takes one of following string
41     as its vartype to set up a range constraint:
42       "integer"
43       "urn"
44       "float"
45       "boolean"
46       "time"
47       "string"
48     it should be followed with one or many of following utility
49     calls.
50     (C:abac_condition_create)
51
52   void constraint_add_integer_max(int)
53     (c:abac_constraint_add_integer_max)
54   void constraint_add_integer_min(int)
55     utility routines to setup a integer range constraint
56       [integer:?I[10 .. 20]]
57     (c:abac_constraint_add_integer_min)
58
59   void constraint_add_integer_target(int)
60     utility routine to setup a integer list constraint
61       [integer:?I[10,20]]
62     (c:abac_constraint_add_integer_target)
63
64   void constraint_add_float_max(float)
65   void constraint_add_float_min(float)
66     utility routines to setup a float range constraint
67       [float:?F[1.0 .. 2.5]]
68
69   void constraint_add_float_target(float)
70     utility routine to setup a float list constraint
71       [float:?F[0.5, 2.5]]
72
73   void constraint_add_time_max(char*)
74   void constraint_add_time_min(char*)
75     utility routines to setup a time range constraint,
76     takes quoted string values, beyond T is optional
77       [time:?F["20120228T" .. "20120228T090000"]]
78
79   void constraint_add_time_target(char*)
80     utility routine to setup a time list constraint
81       [time:?M["20201101T182930","20201101T"]]
82
83   void constraint_add_urn_target(char*)
84     utility routine to setup a an urn list constraint
85       [urn:?U["fileA","http://fileB"]]
86
87   void constraint_add_string_target(char*)
88     utility routine to setup a a string list constraint
89       [string:?S["abc",'efg',"hij"]]
90
91   void constraint_add_boolean_target(char*)
92     utility routine to setup a a boolean list constraint
93       [boolean:?B['true']]
94
95   char *string() const
96     returns literal string of the constraint
97     (c:abac_condition_string)
98
99   char *typed_string() const
100     returns typed literal string of the constraint
101     (c:abac_condition_typed_string)
102
103ABAC::DataTerm
104   A data term is associated with Role or Oset as a parameter that
105   maybe be instantiated, or uninstantiated but being constrained,
106   or as a principal oset term (standalone right handside of an oset
107   policy rule).  It holds a pointer to a abac_term_t structure and
108   an optional constraint that may be imposed on this data term if it
109   is indeed an unistantiated variable.
110
111   DataTerm()
112     default constructor, do not use, for swig only
113
114   DataTerm(const DataTerm &)
115     copy constructor, used for cloning a data term
116
117   ~DataTerm()
118     default destructor
119
120   DataTerm(char*)
121     constructor to make named principal data term for the oset RHS
122     (C: abac_term_named_create)
123
124   DataTerm(char*, char*, Constraint*)
125     constructor for making a variable data term
126     (C: abac_term_create)
127
128   DataTerm(char*, char*)
129     constructor for making an instantiated data term
130     (C: abac_term_create)
131
132   char *string() const
133     returns literal string of the data term
134     (c:abac_term_string)
135
136   char *typed_string() const
137     returns typed literal string of the data term
138     (c:abac_term_typed_string)
139
140   bool term_is_time() const
141   bool term_is_string() const
142   bool term_is_urn() const
143   bool term_is_integer() const
144     returns true if data term is of certain type
145
146   int term_add_constraint(Contraint&)
147     utiltiy routine to add a constraint to this data term
148
149   int term_type() const
150     returns subtype of the data term
151
152   char *term_name() const
153     returns the name of the data term
154
155ABAC::Role
156   A Role is role specification of a set of entitities for a principal
157
158   Role()
159     default constructor, do not use, for swig only
160
161   Role(const Role &)
162     copy constructor, used for cloning a role
163
164   ~Role()
165     default destructor
166
167   Role(char*)
168     constructor that builds a bare bone role with just principal's name
169     (c:abac_role_principal_create)
170
171   Role(char*, char*)
172     constructor that builds a bare bone role with just principal's name
173     and a role name
174     (c:abac_role_create)
175
176   bool role_is_principal() const
177     return true if the role is a principal object(made from
178     a data term), the right hand side of,
179       [keyid:A].role:r <- [keyid:B]
180
181   bool role_is_linking() const
182     returns true if the role is a linking role like
183     the right hand side of,
184       [keyid:A].role:r1 <- [keyid:B].role:r2.role:r3
185
186   char *string() const
187     returns literal string of the role
188     (c:abac_aspect_string)
189
190   char *typed_string() const
191     returns typed literal string of the role
192     (c:abac_aspect_typed_string)
193
194   char *role_linked_role() const
195     returns linked part of a linking role, for
196       [keyid:A].role:r1.role:r2, it returns r1
197
198   char *role_name() const
199     returns the role name of any role (the part after the last dot)
200       [keyid:A].role.r1.role:r2, it returns r2
201       [keyid:A].role.r1, it returns r1
202
203   char *role_principal() const
204     returns the principal of role (the part before the first dot)
205       [keyid:A].role.r1, it returns A
206
207   void role_add_data_term(DataTerm&)
208     add a data term to the role
209
210   std::vector<DataTerm> get_data_terms(bool &)
211     return the data terms bound to this role.
212
213   void role_add_linked_data_term(DataTerm&)
214     add a data term to the linking role
215
216   std::vector<DataTerm> get_linked_data_terms(bool &)
217     return the data terms bound to this role's linking role.
218
219ABAC::Oset
220   An Oset is oset specification of a set of entitities for a principal
221
222   Oset()
223     default constructor, do not use, for swig only
224
225   Oset(const Oset &)
226     copy constructor, used for cloning an oset
227
228   ~Oset()
229     default destructor
230
231   Oset(char *)
232     constructor that makes a principal oset, ie [keyid:B]
233     (c:abac_role_principal_create)
234
235   Oset(char *, char *)
236     constructor that makes a regular oset, ie. [keyid:B].oset:o
237     (c:abac_role_create)
238
239   Oset(DataTerm&)
240     constructor that makes an object oset, ie. [urn:'file/fileA']
241
242   bool oset_is_object(), ie <- [integer:10]
243     return ture if this oset is an object oset
244
245   bool oset_is_principal() const
246     return true if the oset is a principal object(made from
247     a data term), the right hand side of,
248       [keyid:A].oset:o <- [keyid:B]
249
250   bool oset_is_linking() const
251     returns true if the oset is a linking oset like
252     the right hand side of,
253       [keyid:A].oset:o1 <- [keyid:B].role:r1.oset:o2
254
255   char *string() const
256     returns literal string of the oset
257     (c:abac_aspect_string)
258
259   char *typed_string() const
260     returns typed literal string of the oset
261     (c:abac_aspect_typed_string)
262
263   char *oset_linked_role() const
264     returns linked part of a linking oset, for
265       [keyid:A].role:r1.oset:o1, it returns r1
266
267   char *oset_name() const
268     returns oset name,
269       [keyid:A].role:r1.oset:o1, it returns o1
270       [keyid:A].oset:o1, it returns o1
271
272   char *oset_principal() const
273     returns principal name,
274       [keyid:A].role:r1.oset:o1, it returns A
275
276   char *oset_object() const
277     returns object's name when the oset is a principal object
278       [keyid:A].oset:values <- [integer:10], it returns 10
279
280   void add_data_term(DataTerm&)
281     add a data term to this oset's parameter set
282
283   std::vector<DataTerm> get_data_terms(bool &)
284     returns the data terms bound to this oset. 
285
286   void oset_add_linked_data_term(DataTerm&)
287     add a data term to this oset's linking role's parameter set.
288
289   std::vector<DataTerm> get_linked_data_terms(bool &)
290     returns the data terms bound to this oset's linking role. 
291
292ABAC::ID
293   An ID holds a principal credential. It maybe imported from an existing
294   ID credential via external files, constructed from a streaming chunk,
295   or instantiated on the fly 
296
297   ID()
298     default constructor, do not use, for swig only
299
300   ID(const ID &)
301     copy constructor, used for cloning an ID
302
303   ~ID()
304     default destructor
305
306   ID(char *)
307     load an ID cert from a file, will throw an exception
308     if the cert cannot be loaded
309     (c:abac_id_from_file)
310
311   ID(char *,int)
312     generates a new ID with the supplied CN and validity period
313     - CN must be alphanumeric and begin with a letter
314     - validity must be at least one second
315     will throw an exception if either of the above is violated
316     (c:abac_id_generate)
317
318   void id_load_privkey_file(char *)
319     loads the private key associated with the ID credential
320     will throw an exception if the key cannot be loaded
321
322   char *id_keyid()
323     returns the SHA1 keyid of the id cert
324
325   char *id_name()
326     returns the CN (the parameter passed to the constructor or the
327     CN of the cert).
328     (c:abac_id_cn)
329
330   bool id_has_privkey()
331     returns true if the ID has an associated private key
332
333   void id_write_cert(FILE *)
334     writes a PEM-encoded cert to the file handle
335
336   void id_write_cert(char *)
337     writes a PEM-encoded cert to a file named out
338
339   void id_write_privkey(FILE *)
340     writes a PEM-encoded private key to the file handle
341     throws an exception if no private key is loaded
342
343   void id_write_privkey(char *)
344      writes a PEM-encoded private key a file named out
345      throws an exception if no private key is loaded
346
347   abac_chunk_t id_cert_chunk()
348     returns a DER-encoded binary representation of the X.509 ID cert
349     associated with this ID.
350     can be passed to libabac's Context::load_id_chunk()
351
352   char *string()
353     returns literal string of the id credential
354     (c:abac_id_string)
355
356ABAC::Attribute
357   This is the attribute representation for the access policy rule
358       LHS <- RHS
359   The sequence of generation is to
360       first, instantiate the object, ie, LHS (head)
361       second, adding subject(s) to it, ie, RHS (tail)
362       and then baking it.
363   Only once it's baked can you access the X.509 cert.
364   Once it's been baked you can no longer add subjects to it
365
366   Attribute()
367     default constructor, do not use, for swig only
368
369   Attribute(const Attribute &)
370     copy constructor, used for cloning an attribute
371
372   ~Attribute()
373     default destructor
374
375   Attribute(Role&, int)
376     constructor that creates an attribute policy to be signed by the issuer
377     with the given role with a specified validity period
378     An exception will be thrown if:
379       - the issuer has no private key
380       - the Head role is invalid
381       - the validity period is invalid (must be >= 1 second)
382     (c:abac_attribute_create)
383
384   Attribute(Oset&, int)
385     constructor that creates an attribute policy to be signed by the issuer
386     with the given oset with a specified validity period
387     An exception will be thrown if:
388       - the issuer has no private key
389       - the Head oset is invalid
390       - the validity period is invalid (must be >= 1 second)
391     (c:abac_attribute_create)
392
393   bool attribute_add_tail(Role&)
394      Add a role tail.  Call multiple times for intersections
395
396   bool attribute_add_tail(Oset&)
397      Add an oset tail.  Call multiple times for intersections
398
399   char *head_string()
400     returns literal string of head of the attribute
401
402   char *tail_string()
403     returns literal string of tail of the attribute
404
405   char *head_typed_string()
406     returns typed literal string of head of the attribute
407
408   char *tail_typed_string()
409     returns typed literal string of tail of the attribute
410
411   char *string()
412     returns literal string of the attribute
413     (c:abac_attribute_string)
414
415   char *typed_string()
416     returns typed literal string of the attribute
417     (c:abac_attribute_typed_string)
418
419   const Role &role_head()
420     returns the head role
421
422   const Oset &oset_head()
423     returns the oset head
424
425   std::vector<Role> role_tails(bool &)
426     retrieve tail role which maybe more than 1 if intersecting
427
428   std::vector<Oset> oset_tails(bool &)
429     retrieve tail oset which maybe more than 1 if intersecting
430
431   bool attribute_bake()
432     Generate the cert. Call this after you've added subjects to your cert.
433     This returns false if there are no subjects
434     This will throw an exception if the cert's already been baked.
435
436   bool attribute_baked()
437     returns true iff the cert has been baked.
438
439   void attribute_write_cert(FILE *)
440     write the DER-encoded X.509 attribute cert to the open file handle
441     Throws an exception if the cert isn't baked
442
443   void attribute_write_cert(char *)
444     write the DER-encoded X.509 attribute cert to a file named out
445     Throws an exception if the cert isn't baked
446
447   abac_chunk_t cert_chunk()
448     returns a DER-encoded binary representation of the X.509 attribute
449     cert associated with this cert
450     Throws an exception if the cert isn't baked
451     the chunk can be passed to libabac's Context::load_attribute_chunk()
452
453ABAC::Context
454    An ABAC Context
455
456   Context()
457     default constructor
458
459   Context(const Context &)
460     copy constructor, used for cloning the context
461
462   ~Context()
463     default destructor
464
465   void dump_yap_db()
466     dump the complete yap prolog database
467     (c:show_yap_db)
468
469   int load_id(ABAC::ID&)
470     load id cert from ID
471     (c:abac_context_load_id)
472
473   int load_id_file(char *)
474     load id cert from an idkey combo file. key retrieval will be attempt
475     but won't fail if not found
476     (c:abac_context_load_id_file)
477
478   int load_id_files(char *, char *)
479     load id cert from an id file and a key file
480     (c:abac_context_load_id_files)
481
482   int load_id_chunk(abac_chunk_t)
483     load id cert from a chunk structure
484     (c:abac_context_load_id_chunk)
485     returns:
486       ABAC_CERT_SUCCESS   successfully loaded
487       ABAC_CERT_INVALID   invalid certificate (or file not found)
488       ABAC_CERT_BAD_SIG   invalid signature
489
490   int load_attribute(ABAC::Attribute&)
491     load attribute credential from attribute structure
492     (c:abac_context_load_attribute)
493
494   int load_attribute_file(char *)
495     load attribute credential from a file
496     (c:abac_context_load_attribute_file)
497
498   int load_attribute_chunk(abac_chunk_t)
499     load attribute credential from a chunk
500     (c:abac_context_load_attribute_chunk)
501
502     returns the same values as above, additionally
503     returns ABAC_CERT_MISSING_ISSUER if the issuer
504     certificate has not been loaded
505
506   void load_directory(char *)
507     load a directory full of certificates:
508
509        first: ${path}/*_ID.{der,pem} as identity certificates
510               implicitly looking for ${path}/*_private.{der,pem} as
511               the private key file
512        then: ${path}/*_IDKEY.{der,pem} as id/key combo certificate
513        last: ${path}/*_attr.der as attribute certificates
514
515   std::vector<Attribute> query(char *, char *, bool &)
516     the string version is for query that is composed by hand with SHA or
517     in non ABAC_CN mode 
518     (c:abac_context_query)
519
520   std::vector<Attribute> query(Role &, Role &, bool &)
521     (c:abac_context_query_with_structure)
522   std::vector<Attribute> query(Oset &, Oset &, bool &)
523     (c:abac_context_query_with_structure)
524     runs the query:
525       role <-?- principal
526       oset <-?- principal/obj
527     returns true/false in success
528     returns a proof upon success,
529     partial proof on failure (not implemented yet)
530
531   std::vector<Attribute> context_credentials(bool &)
532     returns a vector of all the credentials loaded in the context
533     extracted from the internal data structure
534
535   std::vector<Attribute> context_principals(bool &)
536     returns a vector of all the principals loaded in the context
537     extracted from the internal data structure
538
539   char *version()
540     return the version of this interface
541C API
542
543The C API is nearly identical to the C++ API. Due to lack of namespaces,
544all function names are preceeded by abac_. Furthermore, the parameter
545representing the object must be passed explicitly.
546
547Example:
548
549    C++:    ctx.load_attribute_file("test_attr.der");
550    C:      abac_context_load_attribute_file(ctx, "test_attr.der");
551
552Instead of copy constructors, the C API uses _dup. Therefore, to copy a
553role use abac_role_dup(role_t *), to copy a context use
554abac_context_dup(context_t *), and to copy a credential use
555abac_credential_dup(abac_credential_t *).
556
557abac_context_query() and abac_context_credentials() return
558NULL-terminated arrays of Credential objects (abac_credential_t * in C).
559When you are done with them, you must free the whole array at once using
560abac_context_credentials_free().
561
562PERL AND PYTHON API
563
564The Perl and Python APIs are even more similar to the C++ API. The main
565changes are the use of native types instead of C/C++ types.
566
567    - native strings instead of char *
568
569    Perl:
570        - arrayref instead of vector
571        - string instead of chunk_t
572        - Context::query returns a list of two elements:
573            my ($success, $credentials) = $ctx->query($role, $principal);
574            $success is a boolean
575            $credentials is an arrayref of Credential objects
576
577    Python:
578        - tuple instead of vector
579        - bytearray instead of chunk_t (>= 2.6)
580        - string instead of chunk_t (< 2.6)
581        - Context::query returns a tuple with two elements:
582            (success, credentials) = ctx.query(role, principal)
583            success is a boolean
584            credentials is a tuple of Credential objects
Note: See TracBrowser for help on using the repository browser.