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