5675cd9905b93e1b994e3685b2f785c0231717be
[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    * Public key of the subject this credential was issued to
83    */
84   struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
85   
86   /**
87    * Public key of the issuer
88    */
89   struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
90
91   /**
92    * Flags for this credential
93    */
94   uint32_t credential_flags GNUNET_PACKED;
95
96   /**
97    * Expiration time of this credential
98    */
99   uint64_t expiration GNUNET_PACKED;
100   
101   /**
102    * The signature for this credential by the issuer
103    */
104   struct GNUNET_CRYPTO_EcdsaSignature sig;
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
130 GNUNET_NETWORK_STRUCT_END
131
132
133
134 /**
135  * Initialize the connection with the Credential service.
136  *
137  * @param cfg configuration to use
138  * @return handle to the Credential service, or NULL on error
139  */
140 struct GNUNET_CREDENTIAL_Handle *
141 GNUNET_CREDENTIAL_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
142
143
144 /**
145  * Shutdown connection with the Credentail service.
146  *
147  * @param handle connection to shut down
148  */
149 void
150 GNUNET_CREDENTIAL_disconnect (struct GNUNET_CREDENTIAL_Handle *handle);
151
152
153 /**
154  * Iterator called on obtained result for an attribute verification.
155  *
156  * @param cls closure
157  * @param issuer the issuer of the attribute NULL if verification failed
158  * @param result the result of the verification
159  * @param rd the records in reply
160  */
161 typedef void (*GNUNET_CREDENTIAL_VerifyResultProcessor) (void *cls,
162                                                   struct GNUNET_CRYPTO_EcdsaPublicKey *issuer,
163               uint32_t result);
164
165 /**
166  * Iterator called on obtained result for an attribute issuance.
167  *
168  * @param cls closure
169  * @param result the record data that can be handed to the subject
170  */
171 typedef void (*GNUNET_CREDENTIAL_IssueResultProcessor) (void *cls,
172                                                   struct GNUNET_CREDENTIAL_AttributeRecordData *data);
173
174 /**
175  * Iterator called on obtained result for an attribute delegation.
176  *
177  * @param cls closure
178  * @param success GNUNET_YES if successful
179  * @param result the record data that can be handed to the subject
180  */
181 typedef void (*GNUNET_CREDENTIAL_DelegateResultProcessor) (void *cls,
182                                                   uint32_t success);
183
184 /**
185  * Iterator called on obtained result for an attribute delegation removal.
186  *
187  * @param cls closure
188  * @param success GNUNET_YES if successful
189  * @param result the record data that can be handed to the subject
190  */
191 typedef void (*GNUNET_CREDENTIAL_RemoveDelegateResultProcessor) (void *cls,
192                                                   uint32_t success);
193
194
195
196
197 /**
198  * Performs attribute verification.
199  * Checks if there is a delegation chain from
200  * attribute ``issuer_attribute'' issued by the issuer
201  * with public key ``issuer_key'' maps to the attribute
202  * ``subject_attribute'' claimed by the subject with key
203  * ``subject_key''
204  *
205  * @param handle handle to the Credential service
206  * @param issuer_key the issuer public key
207  * @param issuer_attribute the issuer attribute
208  * @param subject_key the subject public key
209  * @param subject_attribute the attribute claimed by the subject
210  * @param proc function to call on result
211  * @param proc_cls closure for processor
212  * @return handle to the queued request
213  */
214 struct GNUNET_CREDENTIAL_Request*
215 GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle,
216                           const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
217                           const char *issuer_attribute,
218                           const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key,
219                           const char *subject_attribute,
220                           GNUNET_CREDENTIAL_VerifyResultProcessor proc,
221                           void *proc_cls);
222
223 /**
224  * Delegate an attribute
225  *
226  * @param handle handle to the Credential service
227  * @param issuer the ego that should be used to delegate the attribute
228  * @param attribute the name of the attribute to delegate
229  * @param subject the subject of the delegation
230  * @param delegated_attribute the name of the attribute that is delegated to
231  * @return handle to the queued request
232  */
233 struct GNUNET_CREDENTIAL_Request *
234 GNUNET_CREDENTIAL_add_delegation (struct GNUNET_CREDENTIAL_Handle *handle,
235                                   struct GNUNET_IDENTITY_Ego *issuer,
236                                   const char *attribute,
237                                   struct GNUNET_CRYPTO_EcdsaPublicKey *subject,
238                                   const char *delegated_attribute,
239                                   GNUNET_CREDENTIAL_DelegateResultProcessor proc,
240                                   void *proc_cls);
241
242 /**
243  * Remove a delegation
244  *
245  * @param handle handle to the Credential service
246  * @param issuer the ego that was used to delegate the attribute
247  * @param attribute the name of the attribute that is delegated
248  * @return handle to the queued request
249  */
250 struct GNUNET_CREDENTIAL_Request *
251 GNUNET_CREDENTIAL_remove_delegation (struct GNUNET_CREDENTIAL_Handle *handle,
252                                   struct GNUNET_IDENTITY_Ego *issuer,
253                                   const char *attribute,
254                                   GNUNET_CREDENTIAL_RemoveDelegateResultProcessor proc,
255                                   void *proc_cls);
256
257
258
259 /**
260  * Issue an attribute to a subject
261  *
262  * @param handle handle to the Credential service
263  * @param issuer the ego that should be used to issue the attribute
264  * @param subject the subject of the attribute
265  * @param attribute the name of the attribute
266  * @return handle to the queued request
267  */
268 struct GNUNET_CREDENTIAL_Request *
269 GNUNET_CREDENTIAL_issue (struct GNUNET_CREDENTIAL_Handle *handle,
270                          struct GNUNET_IDENTITY_Ego *issuer,
271                          struct GNUNET_CRYPTO_EcdsaPublicKey *subject,
272                          const char *attribute,
273                          GNUNET_CREDENTIAL_IssueResultProcessor proc,
274                          void *proc_cls);
275
276
277 /**
278  * Remove a credential
279  *
280  * @param handle handle to the Credential service
281  * @param issuer the identity that issued the credential
282  * @param subject the subject of the credential
283  * @param credential the name of the credential
284  * @return handle to the queued request
285  */
286 /**
287   struct GNUNET_CREDENTIAL_IssueRequest *
288   GNUNET_CREDENTIAL_remove (struct GNUNET_CREDENTIAL_Handle *handle,
289   struct GNUNET_IDENTITY_Ego *issuer,
290   struct GNUNET_IDENTITY_Ego *subject,
291   const char *credential,
292   GNUNET_CREDENTIAL_IssueResultProcessor proc,
293   void *proc_cls);
294   */
295
296
297 /**
298  * Cancel pending lookup request
299  *
300  * @param lr the lookup request to cancel
301  */
302 void
303 GNUNET_CREDENTIAL_verify_cancel (struct GNUNET_CREDENTIAL_Request *vr);
304
305
306 #if 0                           /* keep Emacsens' auto-indent happy */
307 {
308 #endif
309 #ifdef __cplusplus
310 }
311 #endif
312
313 #endif
314
315 /** @} */  /* end of group */