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