55deb786e15e9ba10290d91a53504b68b43be0ae
[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   uint32_t max_delegation_depth GNUNET_PACKED;
91 };
92
93 GNUNET_NETWORK_STRUCT_END
94
95
96
97 /**
98  * Initialize the connection with the Credential service.
99  *
100  * @param cfg configuration to use
101  * @return handle to the Credential service, or NULL on error
102  */
103 struct GNUNET_CREDENTIAL_Handle *
104 GNUNET_CREDENTIAL_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
105
106
107 /**
108  * Shutdown connection with the Credentail service.
109  *
110  * @param handle connection to shut down
111  */
112 void
113 GNUNET_CREDENTIAL_disconnect (struct GNUNET_CREDENTIAL_Handle *handle);
114
115
116 /**
117  * Iterator called on obtained result for a Credential lookup.
118  *
119  * @param cls closure
120  * @param issuer the issuer chain
121  * @param issuer_len length of issuer chain
122  * @param rd the records in reply
123  */
124 typedef void (*GNUNET_CREDENTIAL_LookupResultProcessor) (void *cls,
125                                                   struct GNUNET_IDENTITY_Ego *issuer,
126               uint16_t issuer_len,
127                                                   const struct GNUNET_CREDENTIAL_RecordData *data);
128
129
130 /**
131  * Perform an asynchronous lookup operation for a credential.
132  *
133  * @param handle handle to the Credential service
134  * @param credential the credential to look up
135  * @param subject Ego to check the credential for
136  * @param proc function to call on result
137  * @param proc_cls closure for processor
138  * @return handle to the queued request
139  */
140 struct GNUNET_CREDENTIAL_LookupRequest *
141 GNUNET_CREDENTIAL_lookup (struct GNUNET_CREDENTIAL_Handle *handle,
142                    const char *credential,
143                    const struct GNUNET_IDENTITY_Ego *subject,
144        const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key,
145        const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
146        uint32_t credential_flags,
147        uint32_t max_delegation_depth,
148        GNUNET_CREDENTIAL_LookupResultProcessor proc,
149                    void *proc_cls);
150
151
152 /**
153  * Issue a credential to an identity
154  *
155  * @param handle handle to the Credential service
156  * @param issuer the identity that issues the credential
157  * @param subject the subject of the credential
158  * @param credential the name of the credential
159  * @param data the data of the credential
160  * @return handle to the queued request
161  */
162 /**struct GNUNET_CREDENTIAL_IssueRequest *
163 GNUNET_CREDENTIAL_issue (struct GNUNET_CREDENTIAL_Handle *handle,
164                          struct GNUNET_IDENTITY_Ego *issuer,
165                          struct GNUNET_IDENTITY_Ego *subject,
166                          const char *credential,
167                          struct GNUNET_CREDENTIAL_Data *data,
168                          GNUNET_CREDENTIAL_IssueResultProcessor proc,
169                          void *proc_cls);
170 */
171 /**
172  * Remove a credential
173  *
174  * @param handle handle to the Credential service
175  * @param issuer the identity that issued the credential
176  * @param subject the subject of the credential
177  * @param credential the name of the credential
178  * @return handle to the queued request
179  */
180  /**
181 struct GNUNET_CREDENTIAL_IssueRequest *
182 GNUNET_CREDENTIAL_remove (struct GNUNET_CREDENTIAL_Handle *handle,
183                           struct GNUNET_IDENTITY_Ego *issuer,
184                           struct GNUNET_IDENTITY_Ego *subject,
185                           const char *credential,
186                           GNUNET_CREDENTIAL_IssueResultProcessor proc,
187                           void *proc_cls);
188 */
189
190
191 /**
192  * Cancel pending lookup request
193  *
194  * @param lr the lookup request to cancel
195  */
196 void
197 GNUNET_CREDENTIAL_lookup_cancel (struct GNUNET_CREDENTIAL_LookupRequest *lr);
198
199
200 #if 0                           /* keep Emacsens' auto-indent happy */
201 {
202 #endif
203 #ifdef __cplusplus
204 }
205 #endif
206
207 #endif
208
209 /** @} */  /* end of group */