2 This file is part of GNUnet
3 Copyright (C) 2012-2014 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @author Martin Schanzenbach
25 * API to the Credential service
27 * @defgroup credential Credential service
32 #ifndef GNUNET_CREDENTIAL_SERVICE_H
33 #define GNUNET_CREDENTIAL_SERVICE_H
35 #include "gnunet_util_lib.h"
36 #include "gnunet_gns_service.h"
37 #include "gnunet_identity_service.h"
42 #if 0 /* keep Emacsens' auto-indent happy */
49 * Connection to the Credential service.
51 struct GNUNET_CREDENTIAL_Handle;
54 * Handle to control a lookup operation.
56 struct GNUNET_CREDENTIAL_Request;
59 * Enum used for checking whether the issuer has the authority to issue credentials or is just a subject
61 enum GNUNET_CREDENTIAL_CredentialFlags {
63 //Subject had credentials before, but have been revoked now
64 GNUNET_CREDENTIAL_FLAG_REVOKED=0,
66 //Subject flag indicates that the subject is a holder of this credential and may present it as such
67 GNUNET_CREDENTIAL_FLAG_SUBJECT=1,
69 //Issuer flag is used to signify that the subject is allowed to issue this credential and delegate issuance
70 GNUNET_CREDENTIAL_FLAG_ISSUER=2
74 GNUNET_NETWORK_STRUCT_BEGIN
76 * The attribute delegation record
78 struct GNUNET_CREDENTIAL_DelegationRecord {
81 * Number of delegation sets in this record
86 * Length of delegation sets
90 * Followed by set_count DelegationSetRecords
96 * The attribute delegation record
98 struct GNUNET_CREDENTIAL_DelegationRecordSet {
101 * Public key of the subject this attribute was delegated to
103 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
106 * Length of attribute, may be 0
108 uint32_t subject_attribute_len;
112 GNUNET_NETWORK_STRUCT_END
115 * The attribute delegation record
117 struct GNUNET_CREDENTIAL_DelegationSet {
120 * Public key of the subject this attribute was delegated to
122 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
124 uint32_t subject_attribute_len;
127 * The subject attribute
129 const char *subject_attribute;
136 struct GNUNET_CREDENTIAL_Delegation {
139 * The issuer of the delegation
141 struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
144 * Public key of the subject this attribute was delegated to
146 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
149 * Length of the attribute
151 uint32_t issuer_attribute_len;
156 const char *issuer_attribute;
159 * Length of the attribute
161 uint32_t subject_attribute_len;
166 const char *subject_attribute;
173 struct GNUNET_CREDENTIAL_Credential {
176 * The issuer of the credential
178 struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
181 * Public key of the subject this credential was issued to
183 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
186 * Signature of this credential
188 struct GNUNET_CRYPTO_EcdsaSignature signature;
191 * Expiration of this credential
193 struct GNUNET_TIME_Absolute expiration;
196 * Length of the attribute
198 uint32_t issuer_attribute_len;
203 const char *issuer_attribute;
210 * Initialize the connection with the Credential service.
212 * @param cfg configuration to use
213 * @return handle to the Credential service, or NULL on error
215 struct GNUNET_CREDENTIAL_Handle *
216 GNUNET_CREDENTIAL_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
220 * Shutdown connection with the Credentail service.
222 * @param handle connection to shut down
225 GNUNET_CREDENTIAL_disconnect (struct GNUNET_CREDENTIAL_Handle *handle);
229 * Iterator called on obtained result for an attribute verification.
232 * @param d_count the number of delegations processed
233 * @param delegation_chain the delegations processed
234 * @param c_count the number of credentials found
235 * @param credential the credentials
237 typedef void (*GNUNET_CREDENTIAL_CredentialResultProcessor) (void *cls,
238 unsigned int d_count,
239 struct GNUNET_CREDENTIAL_Delegation *delegation_chain,
240 unsigned int c_count,
241 struct GNUNET_CREDENTIAL_Credential *credential);
244 * Iterator called on obtained result for an attribute delegation.
247 * @param success GNUNET_YES if successful
248 * @param result the record data that can be handed to the subject
250 typedef void (*GNUNET_CREDENTIAL_DelegateResultProcessor) (void *cls,
254 * Iterator called on obtained result for an attribute delegation removal.
257 * @param success GNUNET_YES if successful
258 * @param result the record data that can be handed to the subject
260 typedef void (*GNUNET_CREDENTIAL_RemoveDelegateResultProcessor) (void *cls,
265 * Performs attribute verification.
266 * Checks if there is a delegation chain from
267 * attribute ``issuer_attribute'' issued by the issuer
268 * with public key ``issuer_key'' maps to the attribute
269 * ``subject_attribute'' claimed by the subject with key
272 * @param handle handle to the Credential service
273 * @param issuer_key the issuer public key
274 * @param issuer_attribute the issuer attribute
275 * @param subject_key the subject public key
276 * @param credential_count number of credentials
277 * @param credentials the subject credentials
278 * @param proc function to call on result
279 * @param proc_cls closure for processor
280 * @return handle to the queued request
282 struct GNUNET_CREDENTIAL_Request*
283 GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle,
284 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
285 const char *issuer_attribute,
286 const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key,
287 uint32_t credential_count,
288 const struct GNUNET_CREDENTIAL_Credential *credentials,
289 GNUNET_CREDENTIAL_CredentialResultProcessor proc,
292 struct GNUNET_CREDENTIAL_Request*
293 GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle,
294 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
295 const char *issuer_attribute,
296 const struct GNUNET_CRYPTO_EcdsaPrivateKey *subject_key,
297 GNUNET_CREDENTIAL_CredentialResultProcessor proc,
301 * Delegate an attribute
303 * @param handle handle to the Credential service
304 * @param issuer the ego that should be used to delegate the attribute
305 * @param attribute the name of the attribute to delegate
306 * @param subject the subject of the delegation
307 * @param delegated_attribute the name of the attribute that is delegated to
308 * @param proc the result callback
309 * @param proc_cls the result closure context
310 * @return handle to the queued request
312 struct GNUNET_CREDENTIAL_Request *
313 GNUNET_CREDENTIAL_add_delegation (struct GNUNET_CREDENTIAL_Handle *handle,
314 struct GNUNET_IDENTITY_Ego *issuer,
315 const char *attribute,
316 struct GNUNET_CRYPTO_EcdsaPublicKey *subject,
317 const char *delegated_attribute,
318 GNUNET_CREDENTIAL_DelegateResultProcessor proc,
322 * Remove a delegation
324 * @param handle handle to the Credential service
325 * @param issuer the ego that was used to delegate the attribute
326 * @param attribute the name of the attribute that is delegated
327 * @param proc the callback
328 * @param proc_cls callback closure
329 * @return handle to the queued request
331 struct GNUNET_CREDENTIAL_Request *
332 GNUNET_CREDENTIAL_remove_delegation (struct GNUNET_CREDENTIAL_Handle *handle,
333 struct GNUNET_IDENTITY_Ego *issuer,
334 const char *attribute,
335 GNUNET_CREDENTIAL_RemoveDelegateResultProcessor proc,
341 * Issue an attribute to a subject
343 * @param issuer the ego that should be used to issue the attribute
344 * @param subject the subject of the attribute
345 * @param attribute the name of the attribute
346 * @param expiration the TTL of the credential
347 * @return handle to the queued request
349 struct GNUNET_CREDENTIAL_Credential*
350 GNUNET_CREDENTIAL_credential_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
351 struct GNUNET_CRYPTO_EcdsaPublicKey *subject,
352 const char *attribute,
353 struct GNUNET_TIME_Absolute *expiration);
358 * Cancel pending lookup request
360 * @param lr the lookup request to cancel
363 GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *lr);
366 #if 0 /* keep Emacsens' auto-indent happy */
375 /** @} */ /* end of group */