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