739e6fe955da2a570d5b026164c5540b02830a14
[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  *
24  * @file
25  * API to the Credential service
26  *
27  * @defgroup credential  Credential service
28  * Credentials
29  *
30  * @{
31  */
32 #ifndef GNUNET_CREDENTIAL_SERVICE_H
33 #define GNUNET_CREDENTIAL_SERVICE_H
34
35 #include "gnunet_util_lib.h"
36 #include "gnunet_gns_service.h"
37 #include "gnunet_identity_service.h"
38
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #if 0                           /* keep Emacsens' auto-indent happy */
43 }
44 #endif
45 #endif
46
47
48 /**
49  * Connection to the Credential service.
50  */
51 struct GNUNET_CREDENTIAL_Handle;
52
53 /**
54  * Handle to control a lookup operation.
55  */
56 struct GNUNET_CREDENTIAL_LookupRequest;
57
58 /*
59 * Enum used for checking whether the issuer has the authority to issue credentials or is just a subject
60 */
61 enum GNUNET_CREDENTIAL_CredentialFlags {
62
63   //Subject had credentials before, but have been revoked now
64   GNUNET_CREDENTIAL_FLAG_REVOKED=0,
65
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,
68
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
71
72 };
73
74 GNUNET_NETWORK_STRUCT_BEGIN
75 /*
76 * Data stored in the credential record 
77 */
78 struct GNUNET_CREDENTIAL_RecordData {
79   
80   /*
81   * Key of the 
82   */
83   struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
84   
85   struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
86
87
88   uint32_t credential_flags GNUNET_PACKED;
89
90 };
91
92 GNUNET_NETWORK_STRUCT_END
93
94
95
96 /**
97  * Initialize the connection with the Credential service.
98  *
99  * @param cfg configuration to use
100  * @return handle to the Credential service, or NULL on error
101  */
102 struct GNUNET_CREDENTIAL_Handle *
103 GNUNET_CREDENTIAL_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
104
105
106 /**
107  * Shutdown connection with the Credentail service.
108  *
109  * @param handle connection to shut down
110  */
111 void
112 GNUNET_CREDENTIAL_disconnect (struct GNUNET_CREDENTIAL_Handle *handle);
113
114
115 /**
116  * Iterator called on obtained result for a Credential lookup.
117  *
118  * @param cls closure
119  * @param issuer the issuer chain
120  * @param issuer_len length of issuer chain
121  * @param rd the records in reply
122  */
123 typedef void (*GNUNET_CREDENTIAL_VerifyResultProcessor) (void *cls,
124                                                   struct GNUNET_IDENTITY_Ego *issuer,
125               uint16_t issuer_len,
126                                                   const struct GNUNET_CREDENTIAL_RecordData *data);
127
128
129 /**
130  * Perform an asynchronous lookup operation for a credential.
131  *
132  * @param handle handle to the Credential service
133  * @param credential the credential to look up
134  * @param subject Ego to check the credential for
135  * @param proc function to call on result
136  * @param proc_cls closure for processor
137  * @return handle to the queued request
138  */
139 struct GNUNET_CREDENTIAL_VerifyRequest*
140 GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle,
141                           const char *issuer_attribute,
142                           const char *subject_attribute,
143                           const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key,
144                           const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
145                           uint32_t credential_flags,
146                           GNUNET_CREDENTIAL_VerifyResultProcessor proc,
147                           void *proc_cls);
148
149 /**
150  * Issue a credential to an identity
151  *
152  * @param handle handle to the Credential service
153  * @param issuer the identity that issues the credential
154  * @param subject the subject of the credential
155  * @param credential the name of the credential
156  * @param data the data of the credential
157  * @return handle to the queued request
158  */
159 /**struct GNUNET_CREDENTIAL_IssueRequest *
160 GNUNET_CREDENTIAL_issue (struct GNUNET_CREDENTIAL_Handle *handle,
161                          struct GNUNET_IDENTITY_Ego *issuer,
162                          struct GNUNET_IDENTITY_Ego *subject,
163                          const char *credential,
164                          struct GNUNET_CREDENTIAL_Data *data,
165                          GNUNET_CREDENTIAL_IssueResultProcessor proc,
166                          void *proc_cls);
167 */
168 /**
169  * Remove a credential
170  *
171  * @param handle handle to the Credential service
172  * @param issuer the identity that issued the credential
173  * @param subject the subject of the credential
174  * @param credential the name of the credential
175  * @return handle to the queued request
176  */
177  /**
178 struct GNUNET_CREDENTIAL_IssueRequest *
179 GNUNET_CREDENTIAL_remove (struct GNUNET_CREDENTIAL_Handle *handle,
180                           struct GNUNET_IDENTITY_Ego *issuer,
181                           struct GNUNET_IDENTITY_Ego *subject,
182                           const char *credential,
183                           GNUNET_CREDENTIAL_IssueResultProcessor proc,
184                           void *proc_cls);
185 */
186
187
188 /**
189  * Cancel pending lookup request
190  *
191  * @param lr the lookup request to cancel
192  */
193 void
194 GNUNET_CREDENTIAL_verify_cancel (struct GNUNET_CREDENTIAL_VerifyRequest *vr);
195
196
197 #if 0                           /* keep Emacsens' auto-indent happy */
198 {
199 #endif
200 #ifdef __cplusplus
201 }
202 #endif
203
204 #endif
205
206 /** @} */  /* end of group */