Added a certificate validation hook to the credential manager
[strongswan.git] / src / libstrongswan / credentials / credential_manager.h
1 /*
2 * Copyright (C) 2007-2009 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 credential_manager credential_manager
18 * @{ @ingroup credentials
19 */
20
21 #ifndef CREDENTIAL_MANAGER_H_
22 #define CREDENTIAL_MANAGER_H_
23
24 typedef struct credential_manager_t credential_manager_t;
25
26 #include <utils/identification.h>
27 #include <utils/enumerator.h>
28 #include <credentials/auth_cfg.h>
29 #include <credentials/credential_set.h>
30 #include <credentials/keys/private_key.h>
31 #include <credentials/keys/shared_key.h>
32 #include <credentials/certificates/certificate.h>
33 #include <credentials/cert_validator.h>
34
35 /**
36 * Manages credentials using credential_sets.
37 *
38 * The credential manager is the entry point of the credential framework. It
39 * uses so called "sets" to access credentials in a modular fashion, these
40 * are implemented through the credential_set_t interface.
41 * The manager additionally does trust chain verification and trust status
42 * chaching. A set may call the managers methods if it needs credentials itself,
43 * the manager uses recursive locking.
44 *
45 * @verbatim
46
47 +-------+ +----------------+
48 | A | | | +------------------+
49 | u | -----> | | ------> | +------------------+
50 | t | | credential- | | | +------------------+
51 | h | -----> | manager | ------> +--| | credential- | => IPC
52 | e | | | +--| sets |
53 | n | +--> | | ------> +------------------+
54 | t | | | | |
55 | i | | | | |
56 | c | | +----------------+ |
57 | a | | |
58 | t | +----------------------------------------------+
59 | o | may be recursive
60 | r |
61 +-------+
62
63 @endverbatim
64 *
65 * The credential manager uses rwlocks for performance reasons, credential
66 * sets must be fully thread save.
67 */
68 struct credential_manager_t {
69
70 /**
71 * Create an enumerator over all certificates.
72 *
73 * @param cert kind of certificate
74 * @param key kind of key in certificate
75 * @param id subject this certificate belongs to
76 * @param trusted TRUE to list trusted certificates only
77 * @return enumerator over the certificates
78 */
79 enumerator_t *(*create_cert_enumerator)(credential_manager_t *this,
80 certificate_type_t cert, key_type_t key,
81 identification_t *id, bool trusted);
82 /**
83 * Create an enumerator over all shared keys.
84 *
85 * The enumerator enumerates over:
86 * shared_key_t*, id_match_t me, id_match_t other
87 * But must accepts values for the id_matches.
88 *
89 * @param type kind of requested shared key
90 * @param first first subject between key is shared
91 * @param second second subject between key is shared
92 * @return enumerator over shared keys
93 */
94 enumerator_t *(*create_shared_enumerator)(credential_manager_t *this,
95 shared_key_type_t type,
96 identification_t *first, identification_t *second);
97 /**
98 * Create an enumerator over all Certificate Distribution Points.
99 *
100 * @param type kind of certificate the point distributes
101 * @param id identification of the distributed certificate
102 * @return enumerator of CDPs as char*
103 */
104 enumerator_t *(*create_cdp_enumerator)(credential_manager_t *this,
105 certificate_type_t type, identification_t *id);
106 /**
107 * Get a trusted or untrusted certificate.
108 *
109 * @param cert kind of certificate
110 * @param key kind of key in certificate
111 * @param id subject this certificate belongs to
112 * @param trusted TRUE to get a trusted certificate only
113 * @return certificate, if found, NULL otherwise
114 */
115 certificate_t *(*get_cert)(credential_manager_t *this,
116 certificate_type_t cert, key_type_t key,
117 identification_t *id, bool trusted);
118 /**
119 * Get the best matching shared key for two IDs.
120 *
121 * @param type kind of requested shared key
122 * @param me own identity
123 * @param other peers identity
124 * @return shared_key_t, NULL if none found
125 */
126 shared_key_t *(*get_shared)(credential_manager_t *this, shared_key_type_t type,
127 identification_t *me, identification_t *other);
128 /**
129 * Get a private key to create a signature.
130 *
131 * The get_private() method gets a secret private key identified by either
132 * the keyid itself or an id the key belongs to.
133 * The auth parameter contains additional information, such as receipients
134 * trusted CA certs. Auth gets filled with subject and CA certificates
135 * needed to validate a created signature.
136 *
137 * @param type type of the key to get
138 * @param id identification the key belongs to
139 * @param auth auth config, including trusted CA certificates
140 * @return private_key_t, NULL if none found
141 */
142 private_key_t* (*get_private)(credential_manager_t *this, key_type_t type,
143 identification_t *id, auth_cfg_t *auth);
144
145 /**
146 * Create an enumerator over trusted public keys.
147 *
148 * This method gets a an enumerator over trusted public keys to verify a
149 * signature created by id. The auth parameter contains additional
150 * authentication infos, e.g. peer and intermediate certificates.
151 * The resulting enumerator enumerates over public_key_t *, auth_cfg_t *,
152 * where the auth config helper contains rules for constraint checks.
153 *
154 * @param type type of the key to get
155 * @param id owner of the key, signer of the signature
156 * @param auth authentication infos
157 * @return enumerator
158 */
159 enumerator_t* (*create_public_enumerator)(credential_manager_t *this,
160 key_type_t type, identification_t *id, auth_cfg_t *auth);
161
162 /**
163 * Cache a certificate by invoking cache_cert() on all registerd sets.
164 *
165 * @param cert certificate to cache
166 */
167 void (*cache_cert)(credential_manager_t *this, certificate_t *cert);
168
169 /**
170 * Flush the certificate cache.
171 *
172 * Only the managers local cache is flushed, but not the sets cache filled
173 * by the cache_cert() method.
174 *
175 * @param type type of certificate to flush, or CERT_ANY
176 */
177 void (*flush_cache)(credential_manager_t *this, certificate_type_t type);
178
179 /**
180 * Register a credential set to the manager.
181 *
182 * @param set set to register
183 */
184 void (*add_set)(credential_manager_t *this, credential_set_t *set);
185
186 /**
187 * Unregister a credential set from the manager.
188 *
189 * @param set set to unregister
190 */
191 void (*remove_set)(credential_manager_t *this, credential_set_t *set);
192
193 /**
194 * Register a certificate validator to the manager.
195 *
196 * @param vdtr validator to register
197 */
198 void (*add_validator)(credential_manager_t *this, cert_validator_t *vdtr);
199
200 /**
201 * Remove a certificate validator from the manager.
202 *
203 * @param vdtr validator to unregister
204 */
205 void (*remove_validator)(credential_manager_t *this, cert_validator_t *vdtr);
206
207 /**
208 * Destroy a credential_manager instance.
209 */
210 void (*destroy)(credential_manager_t *this);
211 };
212
213 /**
214 * Create a credential_manager instance.
215 */
216 credential_manager_t *credential_manager_create();
217
218 #endif /** CREDENTIAL_MANAGER_H_ @}*/