renamed BUILD_BLOB_RFC_3110 to BUILD_BLOB_DNSKEY, we potentially support other key...
[strongswan.git] / src / libstrongswan / credentials / builder.h
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup builder builder
18 * @{ @ingroup credentials
19 */
20
21 #ifndef BUILDER_H_
22 #define BUILDER_H_
23
24 typedef struct builder_t builder_t;
25 typedef enum builder_part_t builder_part_t;
26
27 /**
28 * Constructor function which creates a new builder instance.
29 *
30 * @param subtype constructor specific subtype, e.g. certificate_type_t
31 * @return builder to construct a instance of type
32 */
33 typedef builder_t* (*builder_constructor_t)(int subtype);
34
35 #include <library.h>
36
37 /**
38 * Parts to build credentials from.
39 */
40 enum builder_part_t {
41 /** path to a file containing an ASN.1 blob, char* */
42 BUILD_FROM_FILE,
43 /** unix socket of a ssh/pgp agent, char* */
44 BUILD_AGENT_SOCKET,
45 /** DER encoded ASN.1 blob, chunk_t */
46 BUILD_BLOB_ASN1_DER,
47 /** PEM encoded ASN.1/PGP blob, chunk_t */
48 BUILD_BLOB_PEM,
49 /** OpenPGP key blob, chunk_t */
50 BUILD_BLOB_PGP,
51 /** DNS public key blob (RFC 4034, RSA specifc RFC 3110), chunk_t */
52 BUILD_BLOB_DNSKEY,
53 /** passphrase for e.g. PEM decryption, chunk_t */
54 BUILD_PASSPHRASE,
55 /** passphrase callback, chunk_t(*fn)(void *user, int try), void *user.
56 * The callback is invoked until the returned passphrase is accepted, or
57 * a zero-length passphrase is returned. Try starts at 1. */
58 BUILD_PASSPHRASE_CALLBACK,
59 /** key size in bits, as used for key generation, u_int */
60 BUILD_KEY_SIZE,
61 /** private key to use for signing, private_key_t* */
62 BUILD_SIGNING_KEY,
63 /** certificate used for signing, certificate_t* */
64 BUILD_SIGNING_CERT,
65 /** public key to include, public_key_t* */
66 BUILD_PUBLIC_KEY,
67 /** subject for e.g. certificates, identification_t* */
68 BUILD_SUBJECT,
69 /** additional subject name, identification_t* */
70 BUILD_SUBJECT_ALTNAME,
71 /** issuer for e.g. certificates, identification_t* */
72 BUILD_ISSUER,
73 /** additional issuer name, identification_t* */
74 BUILD_ISSUER_ALTNAME,
75 /** notBefore, time_t* */
76 BUILD_NOT_BEFORE_TIME,
77 /** notAfter, time_t* */
78 BUILD_NOT_AFTER_TIME,
79 /** a serial number in binary form, chunk_t */
80 BUILD_SERIAL,
81 /** a comma-separated list of ietf group attributes, char* */
82 BUILD_IETF_GROUP_ATTR,
83 /** a ca certificate, certificate_t* */
84 BUILD_CA_CERT,
85 /** a certificate, certificate_t* */
86 BUILD_CERT,
87 /** enforce an additional X509 flag, x509_flag_t */
88 BUILD_X509_FLAG,
89 /** key ID of a key on a smartcard, null terminated char* ([slot:]keyid) */
90 BUILD_SMARTCARD_KEYID,
91 /** pin to access a key on a smartcard, null terminated char* */
92 BUILD_SMARTCARD_PIN,
93 /** modulus (n) of a RSA key, chunk_t */
94 BUILD_RSA_MODULUS,
95 /** public exponent (e) of a RSA key, chunk_t */
96 BUILD_RSA_PUB_EXP,
97 /** private exponent (d) of a RSA key, chunk_t */
98 BUILD_RSA_PRIV_EXP,
99 /** prime 1 (p) of a RSA key, chunk_t */
100 BUILD_RSA_PRIME1,
101 /** prime 2 (q) of a RSA key, chunk_t */
102 BUILD_RSA_PRIME2,
103 /** exponent 1 (exp1) of a RSA key, chunk_t */
104 BUILD_RSA_EXP1,
105 /** exponent 2 (exp1) of a RSA key, chunk_t */
106 BUILD_RSA_EXP2,
107 /** coefficient (coeff) of a RSA key, chunk_t */
108 BUILD_RSA_COEFF,
109 /** end of variable argument builder list */
110 BUILD_END,
111 };
112
113 /**
114 * enum names for build_part_t
115 */
116 extern enum_name_t *builder_part_names;
117
118 /**
119 * Credential construction API.
120 *
121 * The builder allows the construction of credentials in a generic and
122 * flexible way.
123 */
124 struct builder_t {
125
126 /**
127 * Add a part to the construct.
128 *
129 * Any added parts are cloned/refcounted by the builder implementation, a
130 * caller may need to free the passed ressources themself.
131 *
132 * @param part kind of part
133 * @param ... part specific variable argument
134 */
135 void (*add)(builder_t *this, builder_part_t part, ...);
136
137 /**
138 * Build the construct with all supplied parts.
139 *
140 * Once build() is called, the builder gets destroyed.
141 *
142 * @return specific interface, as requested with constructor.
143 */
144 void* (*build)(builder_t *this);
145 };
146
147 /**
148 * Helper macro to cancel a build in a builder
149 */
150 #define builder_cancel(builder) { (builder)->add = (void*)nop; \
151 (builder)->build = (void*)builder_free; }
152
153 /**
154 * Helper function for a cancelled build.
155 */
156 void* builder_free(builder_t *this);
157
158 #endif /** BUILDER_H_ @}*/