1 | #ifndef __LIBCREDDY_H__ |
---|
2 | #define __LIBCREDDY_H__ |
---|
3 | |
---|
4 | #include <stdio.h> |
---|
5 | |
---|
6 | #define CREDDY_SUCCESS 0 |
---|
7 | #define CREDDY_GENERATE_INVALID_CN -1 |
---|
8 | #define CREDDY_GENERATE_INVALID_VALIDITY -2 |
---|
9 | #define CREDDY_ATTRIBUTE_ISSUER_NOKEY -3 |
---|
10 | #define CREDDY_ATTRIBUTE_INVALID_ROLE -4 |
---|
11 | #define CREDDY_ATTRIBUTE_INVALID_VALIDITY -5 |
---|
12 | |
---|
13 | /** |
---|
14 | * Creddy identifiers. |
---|
15 | */ |
---|
16 | |
---|
17 | typedef struct _creddy_id_t creddy_id_t; |
---|
18 | |
---|
19 | // create an ID from an X.509 certificate |
---|
20 | creddy_id_t *creddy_id_from_file(char *filename); |
---|
21 | |
---|
22 | // load an X.509 private key for an from a file |
---|
23 | // handles keys with a password |
---|
24 | int creddy_id_load_privkey(creddy_id_t *id, char *filename); |
---|
25 | |
---|
26 | // generate an ID |
---|
27 | // returns one of CREDDY_SUCCESS or CREDDY_GENERATE_* (see top) |
---|
28 | int creddy_id_generate(creddy_id_t **ret, char *cn, int validity); |
---|
29 | |
---|
30 | // get the SHA1 keyid, pointer is valid for the lifetime of the object |
---|
31 | char *creddy_id_keyid(creddy_id_t *id); |
---|
32 | |
---|
33 | // default filename for the cert: ${CN}_ID.pem |
---|
34 | // caller must free the returned string |
---|
35 | char *creddy_id_cert_filename(creddy_id_t *id); |
---|
36 | |
---|
37 | // write the cert fo an open file pointer |
---|
38 | void creddy_id_write_cert(creddy_id_t *id, FILE *out); |
---|
39 | |
---|
40 | // default filename for the private key: ${CN}_key.pem |
---|
41 | // caller must free the return value |
---|
42 | char *creddy_id_privkey_filename(creddy_id_t *id); |
---|
43 | |
---|
44 | // write the private key to a file |
---|
45 | // it is recommended that you open this file mode 0600 |
---|
46 | void creddy_id_write_privkey(creddy_id_t *id, FILE *out); |
---|
47 | |
---|
48 | // destroy the id |
---|
49 | void creddy_id_free(creddy_id_t *id); |
---|
50 | |
---|
51 | /** |
---|
52 | * Attribute cert |
---|
53 | */ |
---|
54 | typedef struct _creddy_attribute_t creddy_attribute_t; |
---|
55 | |
---|
56 | // |
---|
57 | // Here's the skinny: |
---|
58 | // Attribute cert objects don't contain an actual cert until they're baked. |
---|
59 | // First you construct the object using creddy_attribute_create, then you add |
---|
60 | // subjects to it using creddy_attribute_{principal,role,linking_role}. |
---|
61 | // Finally you bake it. Once you've done that, you can access the DER encoding |
---|
62 | // or write it to a file. |
---|
63 | // |
---|
64 | |
---|
65 | // create an attribute cert |
---|
66 | // validity is in days |
---|
67 | // returns one of CREDDY_SUCCESS or CREDDY_ATTRIBUTE_* (see top) |
---|
68 | int creddy_attribute_create(creddy_attribute_t **attr, creddy_id_t *issuer, char *role, int validity); |
---|
69 | |
---|
70 | // add a principal subject to the cert |
---|
71 | int creddy_attribute_principal(creddy_attribute_t *attr, char *keyid); |
---|
72 | |
---|
73 | // add a role subject |
---|
74 | int creddy_attribute_role(creddy_attribute_t *attr, char *keyid, char *role); |
---|
75 | |
---|
76 | // add a linking role subject |
---|
77 | int creddy_attribute_linking_role(creddy_attribute_t *attr, char *keyid, char *role, char *linked); |
---|
78 | |
---|
79 | // create the attribute cert once all the subjects have been added |
---|
80 | // can return 0 if there are no subjects or there's a problem building the cert |
---|
81 | int creddy_attribute_bake(creddy_attribute_t *attr); |
---|
82 | |
---|
83 | // destroy the cert |
---|
84 | void creddy_attribute_free(creddy_attribute_t *attr); |
---|
85 | |
---|
86 | #endif /* __LIBCREDDY_H__ */ |
---|