source: libabac/abac.h @ afcafea

abac0-leakabac0-meitvf-new-xml
Last change on this file since afcafea was afcafea, checked in by Ted Faber <faber@…>, 11 years ago

Outputs names with bake(Context)

  • Property mode set to 100644
File size: 11.1 KB
RevLine 
[90d20f0]1#ifndef __ABAC_H__
2#define __ABAC_H__
3
[461541a]4#include <time.h>  // for struct tm
5#include <stdio.h> // for FILE
[11e3eb7]6
[390f749]7typedef struct _abac_context_t abac_context_t;
[401a054]8typedef struct _abac_credential_t abac_credential_t;
[bec30b5]9typedef struct _abac_id_cert_t abac_id_cert_t;
[1743825]10typedef struct _abac_role_t abac_role_t;
[90d20f0]11
[461541a]12typedef struct _abac_id_t abac_id_t;
13typedef struct _abac_attribute_t abac_attribute_t;
14
[4721618]15typedef struct _abac_list_t ABAC_LIST_T;
16
[461541a]17typedef struct _abac_chunk_t {
18    unsigned char *ptr;
19    int len;
20} abac_chunk_t;
21
[94605f2]22
23typedef struct abac_keyid_mapping_t abac_keyid_mapping_t;
24typedef struct abac_keyid_map_t abac_keyid_map_t;
25
[0bf0e67]26/*
27 * ABAC functions, operating on an ABAC context.
28 */
[390f749]29abac_context_t *abac_context_new(void);
30abac_context_t *abac_context_dup(abac_context_t *ctx);
31void abac_context_free(abac_context_t *ctx);
[90d20f0]32
[0779c99]33/* see the bottom of the file for possible return codes */
[390f749]34int abac_context_load_id_file(abac_context_t *ctx, char *filename);
35int abac_context_load_id_chunk(abac_context_t *ctx, abac_chunk_t cert);
36int abac_context_load_attribute_file(abac_context_t *ctx, char *filename);
37int abac_context_load_attribute_chunk(abac_context_t *ctx, abac_chunk_t cert);
[90d20f0]38
[03b3293]39/* load an entire directory full of certs */
[390f749]40void abac_context_load_directory(abac_context_t *ctx, char *path);
[03b3293]41
[401a054]42/* abac query, returns a NULL-terminated array of credentials on success, NULL on fail */
[4e426c9]43abac_credential_t **abac_context_query(abac_context_t *ctx, char *role, char *principal, int *success);
[3c4fd68]44
45/* get all the credentials from the context, returns a NULL-terminated array of credentials */
46abac_credential_t **abac_context_credentials(abac_context_t *ctx);
47
[13b087a]48/* get all the principals from the context, returns a NULL-terminated array of credentials */
49abac_id_cert_t **abac_context_principals(abac_context_t *ctx);
50
[3c4fd68]51/* use this to free the results of either of the previous two functions */
52void abac_context_credentials_free(abac_credential_t **credentials);
[94605f2]53/* Used to pretty print */
54char *abac_context_expand_key(abac_context_t *ctxt, char *s );
55char *abac_context_expand_nickname(abac_context_t *ctxt, char *s );
[afcafea]56abac_keyid_map_t *abac_context_get_keyid_map(abac_context_t *ctxt);
[90d20f0]57
[0bf0e67]58/*
[401a054]59 * Operations on credentials
[0bf0e67]60 */
[401a054]61abac_role_t *abac_credential_head(abac_credential_t *cred);
62abac_role_t *abac_credential_tail(abac_credential_t *cred);
63abac_chunk_t abac_credential_attribute_cert(abac_credential_t *cred);
64abac_chunk_t abac_credential_issuer_cert(abac_credential_t *cred);
[0bf0e67]65
[401a054]66abac_credential_t *abac_credential_dup(abac_credential_t *cred);
67void abac_credential_free(abac_credential_t *cred);
[13b087a]68char *abac_id_cert_keyid(abac_id_cert_t *);
[0bf0e67]69
70/*
71 * Operations on roles.
72 */
[dcc1a8e]73abac_role_t *abac_role_principal_new(char *principal);
74abac_role_t *abac_role_role_new(char *principal, char *abac_role_name);
75abac_role_t *abac_role_linking_new(char *principal, char *linked_role, char *abac_role_name);
[0bf0e67]76
[dcc1a8e]77void abac_role_free(abac_role_t *role);
[0bf0e67]78
[dcc1a8e]79abac_role_t *abac_role_from_string(char *string);
80abac_role_t *abac_role_dup(abac_role_t *role);
[0bf0e67]81
[dcc1a8e]82int abac_role_is_principal(abac_role_t *role);
83int abac_role_is_role(abac_role_t *role);
84int abac_role_is_linking(abac_role_t *role);
[9a411d7]85int abac_role_is_intersection(abac_role_t *role);
[0bf0e67]86
[dcc1a8e]87char *abac_role_string(abac_role_t *role);
[94605f2]88char *abac_role_short_string(abac_role_t *role, abac_context_t *ctxt);
[dcc1a8e]89char *abac_role_linked_role(abac_role_t *role);
[e50f807]90char *abac_role_linking_role(abac_role_t *role);
[dcc1a8e]91char *abac_role_role_name(abac_role_t *role);
92char *abac_role_principal(abac_role_t *role);
[0bf0e67]93
[dcc1a8e]94char *abac_role_attr_key(abac_role_t *head_role, abac_role_t *tail_role);
[0bf0e67]95
[461541a]96/*
97 * Operations on ID
98 */
99// create an ID from an X.509 certificate
100abac_id_t *abac_id_from_file(char *);
101
102// create an ID from a X.509 certificate PEM chunk
103abac_id_t *abac_id_from_chunk(abac_chunk_t chunk);
104
105// load an X.509 private key from a file
106int abac_id_privkey_from_file(abac_id_t *id, char *filename);
107
[a02c849]108// load an X.509 private key from a chunk
109int abac_id_privkey_from_chunk(abac_id_t *id, abac_chunk_t chunk);
110
[461541a]111// generate an ID
112// returns one of ABAC_SUCCESS or ABAC_GENERATE_* (see top)
113int abac_id_generate(abac_id_t **ret, char *cn, long validity);
114
[9e063cb]115// generate an ID using supplied private key
116// returns one of ABAC_SUCCESS or ABAC_GENERATE_* (see top)
117int abac_id_generate_with_key(abac_id_t **ret, char *cn, long validity, char *keyfile);
118
[461541a]119// get the SHA1 keyid, pointer is valid for the lifetime of the object
120char *abac_id_keyid(abac_id_t *id);
121
122// get the name of the issuer
123// caller must free the returned string
124char *abac_id_issuer(abac_id_t *id);
125
126// get the DN of the subject
127// caller must free the returned string
128char *abac_id_subject(abac_id_t *id);
129
130// check if the cert is still valid
131int abac_id_still_valid(abac_id_t *id);
132
133// check if the principal cert's keyid is specified
134int abac_id_has_keyid(abac_id_t *id, char *);
135
136// check if the cert is has a private key
137int abac_id_has_privkey(abac_id_t *id);
138
139// get the validity period of the cert
140int abac_id_validity(abac_id_t *id, struct tm *not_before, struct tm *not_after);
141
142// default filename for the cert: ${CN}_ID.pem
143// caller must free the returned string
144char *abac_id_cert_filename(abac_id_t *id);
145
146// write the cert fo an open file pointer
147int abac_id_write_cert(abac_id_t *id, FILE *out);
148
149// default filename for the private key: ${CN}_key.pem
150// caller must free the return value
151char *abac_id_privkey_filename(abac_id_t *id);
152
153// write the private key to a file
154// it is recommended that you open this file mode 0600
155// returns false if there's no private key loaded
156int abac_id_write_privkey(abac_id_t *id, FILE *out);
157
158// get a chunk representing the cert
159// you must free the ptr of the chunk when done
160abac_chunk_t abac_id_cert_chunk(abac_id_t *id);
161
[92661b4]162// get a chunk representing the private key of the id
163abac_chunk_t abac_id_privkey_chunk(abac_id_t *id);
164
[461541a]165// dup an ID (increases its refcount)
166abac_id_t *abac_id_dup(abac_id_t *id);
167
168// destroy the id
169// decreases refcount and destroys when it hits 0
170void abac_id_free(abac_id_t *id);
171
172/*
173 * Operations on Attribute
174 */
175//
176// Here's the skinny:
177//  Attribute cert objects don't contain an actual cert until they're baked.
178//  First you construct the object using abac_attribute_create, then you add
179//  subjects to it using abac_attribute_{principal,role,linking_role}.
180//  Finally you bake it. Once you've done that, you can keep it as XML chunk
181//  or write it to a file.
182//
183
184// create an attribute cert
185// validity is in days
186// returns one of CREDDY_SUCCESS or CREDDY_ATTRIBUTE_* (see top)
187int abac_attribute_create(abac_attribute_t **attr, abac_id_t *issuer, char *role, long validity);
188
189// add a head string to the cert
190void abac_attribute_set_head(abac_attribute_t *attr, char *string);
191
192// return the head string of the attribute
193char *abac_attribute_get_head(abac_attribute_t *);
194
195// add a principal subject to the cert
196int abac_attribute_principal(abac_attribute_t *attr, char *keyid);
197
198// add a role subject
199int abac_attribute_role(abac_attribute_t *attr, char *keyid, char *role);
200
201// add a linking role subject
202int abac_attribute_linking_role(abac_attribute_t *attr, char *keyid, char *role, char *linked);
203
204// create the attribute cert once all the subjects have been added
205// can return 0 if there are no subjects or there's a problem building the cert
206int abac_attribute_bake(abac_attribute_t *attr);
[afcafea]207int abac_attribute_bake_context(abac_attribute_t *attr, abac_context_t *ctxt);
[461541a]208
209// returns true iff the cert's been baked
210int abac_attribute_baked(abac_attribute_t *attr);
211
212// write the cert to a file. returns 0 if the cert hasn't been baked
213int abac_attribute_write(abac_attribute_t *attr, FILE *out);
[4721618]214int abac_attribute_write_file(abac_attribute_t *attr, const char *fname);
[461541a]215
[e50f807]216/*
217 * Return the number of tail strings
218 */
219int abac_attribute_get_ntails(abac_attribute_t *a);
220
221/*
222 * Return the nth tail string or NULL if it is undefined
223 */
224char *abac_attribute_get_tail_n(abac_attribute_t *a, int n);
225
[461541a]226// get chunked cert
227// returns 0 if the cert isn't baked
[4721618]228abac_chunk_t abac_attribute_cert_chunk(abac_attribute_t *);
[461541a]229
230// destroy the cert
231void abac_attribute_free(abac_attribute_t *);
232
233// load a list of attr cert from file (aborts on fail)
[bec30b5]234ABAC_LIST_T *abac_attribute_certs_from_file(ABAC_LIST_T *,char *);
[461541a]235
236// load a list of attr cert from chunk (aborts on fail)
[bec30b5]237ABAC_LIST_T *abac_attribute_certs_from_chunk(ABAC_LIST_T *,abac_chunk_t);
[461541a]238
[9e063cb]239        // get the attribute role string
[461541a]240char *abac_attribute_role_string(abac_attribute_t *attr);
241
242// get the issuer id of an attribute
243abac_id_t *abac_attribute_issuer_id(abac_attribute_t *ptr);
244
[bc12f3d]245// get the attribute output format (internal)
246char *abac_attribute_get_output_format(abac_attribute_t *);
247
248// set the attribute output format
249// Valid formats GENIv1.0, GENIv1.1
250void abac_attribute_set_output_format(abac_attribute_t *, char *);
251
[461541a]252// get the validity period of the attribute cert
253int abac_attribute_validity(abac_attribute_t *attr, struct tm *not_before, struct tm *not_after);
[d2b198c]254abac_keyid_map_t *abac_attribute_get_keyid_map(abac_attribute_t *);
[461541a]255
256// return the principal from an attribute's role string
257// callee must free the space
258char *abac_attribute_get_principal(abac_attribute_t *attr);
259
260// check if the attribute cert is still valid
261int abac_attribute_still_valid(abac_attribute_t *attr);
262
[94605f2]263/* abac name mappings.  These are used internally, mostly */
264abac_keyid_mapping_t *abac_keyid_mapping_new(char *k, char *v);
265void abac_keyid_mapping_free(abac_keyid_mapping_t *m);
266abac_keyid_map_t *abac_keyid_map_new();
267abac_keyid_map_t *abac_keyid_map_dup(abac_keyid_map_t *);
[d2b198c]268abac_keyid_map_t *abac_keyid_map_clone(abac_keyid_map_t *);
[94605f2]269void abac_keyid_map_free(abac_keyid_map_t *m); 
270char *abac_keyid_map_key_to_nickname(abac_keyid_map_t *m, char *key);
271char *abac_keyid_map_nickname_to_key(abac_keyid_map_t *m, char *nick); 
272int abac_keyid_map_remove_keyid(abac_keyid_map_t *m, char *key); 
273int abac_keyid_map_add_nickname(abac_keyid_map_t *m, char *key, char *nick);
[d2b198c]274void abac_keyid_map_merge(abac_keyid_map_t *d, abac_keyid_map_t *s, 
275        int overwrite);
[94605f2]276char *abac_keyid_map_expand_key(abac_keyid_map_t *m, char *s); 
277char *abac_keyid_map_expand_nickname(abac_keyid_map_t *m, char *s);
[9e063cb]278/*
279 * Return code for libabac
280 */
281#define ABAC_RC_SUCCESS                0
282#define ABAC_RC_FAILURE                1
[461541a]283
[0779c99]284/*
285 * Error codes for loading certificates.
286 */
287#define ABAC_CERT_SUCCESS           0   // certificate loaded, all is well
288#define ABAC_CERT_INVALID           -1  // invalid format; also file not found
289#define ABAC_CERT_BAD_SIG           -2  // invalid signature
290#define ABAC_CERT_MISSING_ISSUER    -3  // missing ID cert that issued the attribute cert
[461541a]291#define ABAC_CERT_BAD_PRINCIPAL     -4  // Principal of attribute cert issuer has mismatch keyid
292#define ABAC_CERT_INVALID_ISSUER    -5  // Issuer of attribute cert is invalid
293#define ABAC_CERT_SIGNER_NOKEY      -6  // Signer of attribute cert is missing private key
294
295/*
296 * Error codes for IDs and Attributes
297 */
298#define ABAC_SUCCESS                          0
299#define ABAC_FAILURE                          1 /* catch all */
300#define ABAC_GENERATE_INVALID_CN             -1
301#define ABAC_GENERATE_INVALID_VALIDITY       -2
302#define ABAC_ATTRIBUTE_ISSUER_NOKEY          -3
303#define ABAC_ATTRIBUTE_INVALID_ROLE          -4
304#define ABAC_ATTRIBUTE_INVALID_VALIDITY      -5
305#define ABAC_ATTRIBUTE_INVALID_ISSUER        -6
306
307
[0779c99]308
[90d20f0]309#endif /* __ABAC_H__ */
Note: See TracBrowser for help on using the repository browser.