-towards type4
[oweals/gnunet.git] / src / include / gnunet_credential_service.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2012-2014 GNUnet e.V.
4
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.
9
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.
14
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.
19  */
20
21 /**
22  * @author Martin Schanzenbach
23  * @author Adnan Husain
24  *
25  * @file
26  * API to the Credential service
27  *
28  * @defgroup credential  Credential service
29  * Credentials
30  *
31  * @{
32  */
33 #ifndef GNUNET_CREDENTIAL_SERVICE_H
34 #define GNUNET_CREDENTIAL_SERVICE_H
35
36 #include "gnunet_util_lib.h"
37 #include "gnunet_gns_service.h"
38 #include "gnunet_identity_service.h"
39
40 #ifdef __cplusplus
41 extern "C"
42 {
43 #if 0                           /* keep Emacsens' auto-indent happy */
44 }
45 #endif
46 #endif
47
48
49 /**
50  * Connection to the Credential service.
51  */
52 struct GNUNET_CREDENTIAL_Handle;
53
54 /**
55  * Handle to control a lookup operation.
56  */
57 struct GNUNET_CREDENTIAL_Request;
58
59 /*
60 * Enum used for checking whether the issuer has the authority to issue credentials or is just a subject
61 */
62 enum GNUNET_CREDENTIAL_CredentialFlags {
63
64   //Subject had credentials before, but have been revoked now
65   GNUNET_CREDENTIAL_FLAG_REVOKED=0,
66
67   //Subject flag indicates that the subject is a holder of this credential and may present it as such
68   GNUNET_CREDENTIAL_FLAG_SUBJECT=1,
69
70   //Issuer flag is used to signify that the subject is allowed to issue this credential and delegate issuance
71   GNUNET_CREDENTIAL_FLAG_ISSUER=2
72
73 };
74
75 GNUNET_NETWORK_STRUCT_BEGIN
76 /**
77  * The credential record 
78  */
79 struct GNUNET_CREDENTIAL_CredentialRecordData {
80   
81   /**
82    * The signature for this credential by the issuer
83    */
84   struct GNUNET_CRYPTO_EcdsaSignature signature;
85   
86   /**
87    * Signature meta
88    */
89   struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
90
91   /**
92    * Public key of the issuer
93    */
94   struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
95   
96   /**
97    * Public key of the subject this credential was issued to
98    */
99   struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
100   
101   /**
102    * Expiration time of this credential
103    */
104   uint64_t expiration GNUNET_PACKED;
105   
106     /**
107    * Followed by the attribute string
108    */
109 };
110
111
112 /**
113  * The attribute delegation record
114 */
115 struct GNUNET_CREDENTIAL_AttributeRecordData {
116   
117   /**
118    * Public key of the subject this attribute was delegated to
119    */
120   struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
121   
122   /**
123    * Followed by the attribute that was delegated to as string
124    * May be empty
125    */
126 };
127
128 /**
129  * The attribute delegation record
130 */
131 struct GNUNET_CREDENTIAL_DelegationRecordData {
132   
133   uint32_t set_count;
134
135   uint64_t data_size;
136
137   char *data;
138   
139   /**
140    * Followed by the attribute that was delegated to as string
141    * May be empty
142    */
143 };
144
145
146
147 /**
148  * The attribute delegation record
149 */
150 struct GNUNET_CREDENTIAL_DelegationSetRecord {
151   
152   /**
153    * Public key of the subject this attribute was delegated to
154    */
155   struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
156
157   uint32_t subject_attribute_len;
158
159   const char *subject_attribute;
160   
161   /**
162    * Followed by the attribute that was delegated to as string
163    * May be empty
164    */
165 };
166
167
168 /**
169  * A delegation
170 */
171 struct GNUNET_CREDENTIAL_Delegation {
172   
173   /**
174    * The issuer of the delegation
175    */
176   struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
177
178   /**
179    * Public key of the subject this attribute was delegated to
180    */
181   struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
182
183   /**
184    * Length of the attribute
185    */
186   uint32_t issuer_attribute_len;
187
188   /**
189    * The attribute
190    */
191   const char *issuer_attribute;
192
193   /**
194    * Length of the attribute
195    */
196   uint32_t subject_attribute_len;
197
198   /**
199    * The attribute
200    */
201   const char *subject_attribute;
202 };
203
204
205 /**
206  * A credential
207 */
208 struct GNUNET_CREDENTIAL_Credential {
209   
210   /**
211    * The issuer of the credential
212    */
213   struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
214
215   /**
216    * Public key of the subject this credential was issued to
217    */
218   struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
219
220   /**
221    * Length of the attribute
222    */
223   uint32_t issuer_attribute_len;
224
225   /**
226    * The attribute
227    */
228   const char *issuer_attribute;
229   
230 };
231
232
233 GNUNET_NETWORK_STRUCT_END
234
235
236
237 /**
238  * Initialize the connection with the Credential service.
239  *
240  * @param cfg configuration to use
241  * @return handle to the Credential service, or NULL on error
242  */
243 struct GNUNET_CREDENTIAL_Handle *
244 GNUNET_CREDENTIAL_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
245
246
247 /**
248  * Shutdown connection with the Credentail service.
249  *
250  * @param handle connection to shut down
251  */
252 void
253 GNUNET_CREDENTIAL_disconnect (struct GNUNET_CREDENTIAL_Handle *handle);
254
255
256 /**
257  * Iterator called on obtained result for an attribute verification.
258  *
259  * @param cls closure
260  * @param issuer the issuer of the attribute NULL if verification failed
261  * @param result the result of the verification
262  * @param rd the records in reply
263  */
264 typedef void (*GNUNET_CREDENTIAL_VerifyResultProcessor) (void *cls,
265                                                          unsigned int d_count,
266                                                          struct GNUNET_CREDENTIAL_Delegation *delegation_chain,
267                                                          struct GNUNET_CREDENTIAL_Credential *credential);
268
269 /**
270  * Iterator called on obtained result for an attribute delegation.
271  *
272  * @param cls closure
273  * @param success GNUNET_YES if successful
274  * @param result the record data that can be handed to the subject
275  */
276 typedef void (*GNUNET_CREDENTIAL_DelegateResultProcessor) (void *cls,
277                                                   uint32_t success);
278
279 /**
280  * Iterator called on obtained result for an attribute delegation removal.
281  *
282  * @param cls closure
283  * @param success GNUNET_YES if successful
284  * @param result the record data that can be handed to the subject
285  */
286 typedef void (*GNUNET_CREDENTIAL_RemoveDelegateResultProcessor) (void *cls,
287                                                   uint32_t success);
288
289
290
291
292 /**
293  * Performs attribute verification.
294  * Checks if there is a delegation chain from
295  * attribute ``issuer_attribute'' issued by the issuer
296  * with public key ``issuer_key'' maps to the attribute
297  * ``subject_attribute'' claimed by the subject with key
298  * ``subject_key''
299  *
300  * @param handle handle to the Credential service
301  * @param issuer_key the issuer public key
302  * @param issuer_attribute the issuer attribute
303  * @param subject_key the subject public key
304  * @param subject_attribute the attribute claimed by the subject
305  * @param proc function to call on result
306  * @param proc_cls closure for processor
307  * @return handle to the queued request
308  */
309 struct GNUNET_CREDENTIAL_Request*
310 GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle,
311                           const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
312                           const char *issuer_attribute,
313                           const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key,
314                           const char *subject_attribute,
315                           GNUNET_CREDENTIAL_VerifyResultProcessor proc,
316                           void *proc_cls);
317
318 /**
319  * Delegate an attribute
320  *
321  * @param handle handle to the Credential service
322  * @param issuer the ego that should be used to delegate the attribute
323  * @param attribute the name of the attribute to delegate
324  * @param subject the subject of the delegation
325  * @param delegated_attribute the name of the attribute that is delegated to
326  * @return handle to the queued request
327  */
328 struct GNUNET_CREDENTIAL_Request *
329 GNUNET_CREDENTIAL_add_delegation (struct GNUNET_CREDENTIAL_Handle *handle,
330                                   struct GNUNET_IDENTITY_Ego *issuer,
331                                   const char *attribute,
332                                   struct GNUNET_CRYPTO_EcdsaPublicKey *subject,
333                                   const char *delegated_attribute,
334                                   GNUNET_CREDENTIAL_DelegateResultProcessor proc,
335                                   void *proc_cls);
336
337 /**
338  * Remove a delegation
339  *
340  * @param handle handle to the Credential service
341  * @param issuer the ego that was used to delegate the attribute
342  * @param attribute the name of the attribute that is delegated
343  * @return handle to the queued request
344  */
345 struct GNUNET_CREDENTIAL_Request *
346 GNUNET_CREDENTIAL_remove_delegation (struct GNUNET_CREDENTIAL_Handle *handle,
347                                   struct GNUNET_IDENTITY_Ego *issuer,
348                                   const char *attribute,
349                                   GNUNET_CREDENTIAL_RemoveDelegateResultProcessor proc,
350                                   void *proc_cls);
351
352
353
354 /**
355  * Issue an attribute to a subject
356  *
357  * @param handle handle to the Credential service
358  * @param issuer the ego that should be used to issue the attribute
359  * @param subject the subject of the attribute
360  * @param attribute the name of the attribute
361  * @param expiration the TTL of the credential
362  * @return handle to the queued request
363  */
364 struct GNUNET_CREDENTIAL_CredentialRecordData *
365 GNUNET_CREDENTIAL_issue (struct GNUNET_CREDENTIAL_Handle *handle,
366                          const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
367                          struct GNUNET_CRYPTO_EcdsaPublicKey *subject,
368                          const char *attribute,
369                          struct GNUNET_TIME_Absolute *expiration);
370
371
372 /**
373  * Remove a credential
374  *
375  * @param handle handle to the Credential service
376  * @param issuer the identity that issued the credential
377  * @param subject the subject of the credential
378  * @param credential the name of the credential
379  * @return handle to the queued request
380  */
381 /**
382   struct GNUNET_CREDENTIAL_IssueRequest *
383   GNUNET_CREDENTIAL_remove (struct GNUNET_CREDENTIAL_Handle *handle,
384   struct GNUNET_IDENTITY_Ego *issuer,
385   struct GNUNET_IDENTITY_Ego *subject,
386   const char *credential,
387   GNUNET_CREDENTIAL_IssueResultProcessor proc,
388   void *proc_cls);
389   */
390
391
392 /**
393  * Cancel pending lookup request
394  *
395  * @param lr the lookup request to cancel
396  */
397 void
398 GNUNET_CREDENTIAL_verify_cancel (struct GNUNET_CREDENTIAL_Request *vr);
399
400
401 #if 0                           /* keep Emacsens' auto-indent happy */
402 {
403 #endif
404 #ifdef __cplusplus
405 }
406 #endif
407
408 #endif
409
410 /** @} */  /* end of group */