source: creddy/creddy.h @ 405bba3

abac0-leakabac0-meicompt_changesgec13mei-idmei-rt0-nmei_rt0mei_rt2mei_rt2_fix_1meiyap-rt1meiyap1rt2tvf-new-xml
Last change on this file since 405bba3 was 405bba3, checked in by Mike Ryan <mikeryan@…>, 13 years ago

show cert validity period
see #17

  • Property mode set to 100644
File size: 3.7 KB
Line 
1#ifndef __LIBCREDDY_H__
2#define __LIBCREDDY_H__
3
4#include <stdio.h>
5#include <time.h> // for time_t
6
7#include <abac_common.h>
8
9#define CREDDY_SUCCESS                      0
10#define CREDDY_GENERATE_INVALID_CN          -1
11#define CREDDY_GENERATE_INVALID_VALIDITY    -2
12#define CREDDY_ATTRIBUTE_ISSUER_NOKEY       -3
13#define CREDDY_ATTRIBUTE_INVALID_ROLE       -4
14#define CREDDY_ATTRIBUTE_INVALID_VALIDITY   -5
15
16/**
17 * Creddy identifiers.
18 */
19
20typedef struct _creddy_id_t creddy_id_t;
21
22// create an ID from an X.509 certificate
23creddy_id_t *creddy_id_from_file(char *filename);
24
25// load an X.509 private key for an from a file
26// handles keys with a password
27int creddy_id_load_privkey(creddy_id_t *id, char *filename);
28
29// generate an ID
30// returns one of CREDDY_SUCCESS or CREDDY_GENERATE_* (see top)
31int creddy_id_generate(creddy_id_t **ret, char *cn, int validity);
32
33// get the SHA1 keyid, pointer is valid for the lifetime of the object
34char *creddy_id_keyid(creddy_id_t *id);
35
36// get the name of the issuer
37// caller must free the returned string
38char *creddy_id_issuer(creddy_id_t *id);
39
40// get the validity period of the cert
41void creddy_id_validity(creddy_id_t *id, time_t *not_before, time_t *not_after);
42
43// default filename for the cert: ${CN}_ID.pem
44// caller must free the returned string
45char *creddy_id_cert_filename(creddy_id_t *id);
46
47// write the cert fo an open file pointer
48void creddy_id_write_cert(creddy_id_t *id, FILE *out);
49
50// default filename for the private key: ${CN}_key.pem
51// caller must free the return value
52char *creddy_id_privkey_filename(creddy_id_t *id);
53
54// write the private key to a file
55// it is recommended that you open this file mode 0600
56// returns false if there's no private key loaded
57int creddy_id_write_privkey(creddy_id_t *id, FILE *out);
58
59// get a chunk representing the cert
60// you must free the ptr of the chunk when done
61abac_chunk_t creddy_id_cert_chunk(creddy_id_t *id);
62
63// dup an ID (increases its refcount)
64creddy_id_t *creddy_id_dup(creddy_id_t *id);
65
66// destroy the id
67// decreases refcount and destroys when it hits 0
68void creddy_id_free(creddy_id_t *id);
69
70/**
71 * Attribute cert
72 */
73typedef struct _creddy_attribute_t creddy_attribute_t;
74
75//
76// Here's the skinny:
77//  Attribute cert objects don't contain an actual cert until they're baked.
78//  First you construct the object using creddy_attribute_create, then you add
79//  subjects to it using creddy_attribute_{principal,role,linking_role}.
80//  Finally you bake it. Once you've done that, you can access the DER encoding
81//  or write it to a file.
82//
83
84// create an attribute cert
85// validity is in days
86// returns one of CREDDY_SUCCESS or CREDDY_ATTRIBUTE_* (see top)
87int creddy_attribute_create(creddy_attribute_t **attr, creddy_id_t *issuer, char *role, int validity);
88
89// add a principal subject to the cert
90int creddy_attribute_principal(creddy_attribute_t *attr, char *keyid);
91
92// add a role subject
93int creddy_attribute_role(creddy_attribute_t *attr, char *keyid, char *role);
94
95// add a linking role subject
96int creddy_attribute_linking_role(creddy_attribute_t *attr, char *keyid, char *role, char *linked);
97
98// create the attribute cert once all the subjects have been added
99// can return 0 if there are no subjects or there's a problem building the cert
100int creddy_attribute_bake(creddy_attribute_t *attr);
101
102// returns true iff the cert's been baked
103int creddy_attribute_baked(creddy_attribute_t *attr);
104
105// write the cert to a file. returns 0 if the cert hasn't been baked
106int creddy_attribute_write(creddy_attribute_t *attr, FILE *out);
107
108// get the DER-encoded cert
109// returns 0 if the cert isn't baked
110int creddy_attribute_cert_chunk(creddy_attribute_t *attr, abac_chunk_t *chunk);
111
112// destroy the cert
113void creddy_attribute_free(creddy_attribute_t *attr);
114
115#endif /* __LIBCREDDY_H__ */
Note: See TracBrowser for help on using the repository browser.