aboutsummaryrefslogtreecommitdiff
path: root/src/credential
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
committerng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
commitd41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch)
tree9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/credential
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
downloadgnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz
gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip
uncrustify as demanded.
Diffstat (limited to 'src/credential')
-rw-r--r--src/credential/credential.h38
-rw-r--r--src/credential/credential_api.c354
-rw-r--r--src/credential/credential_misc.c159
-rw-r--r--src/credential/credential_misc.h6
-rw-r--r--src/credential/credential_serialization.c444
-rw-r--r--src/credential/credential_serialization.h166
-rw-r--r--src/credential/gnunet-credential.c655
-rw-r--r--src/credential/gnunet-service-credential.c1064
-rw-r--r--src/credential/plugin_gnsrecord_credential.c346
-rw-r--r--src/credential/plugin_rest_credential.c1368
10 files changed, 2331 insertions, 2269 deletions
diff --git a/src/credential/credential.h b/src/credential/credential.h
index 23db51e99..fcc81de6c 100644
--- a/src/credential/credential.h
+++ b/src/credential/credential.h
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -32,8 +32,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
32/** 32/**
33 * Message from client to Credential service to collect credentials. 33 * Message from client to Credential service to collect credentials.
34 */ 34 */
35struct CollectMessage 35struct CollectMessage {
36{
37 /** 36 /**
38 * Header of type #GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY 37 * Header of type #GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY
39 */ 38 */
@@ -60,15 +59,13 @@ struct CollectMessage
60 uint32_t id GNUNET_PACKED; 59 uint32_t id GNUNET_PACKED;
61 60
62 /* Followed by the zero-terminated attribute */ 61 /* Followed by the zero-terminated attribute */
63
64}; 62};
65 63
66 64
67/** 65/**
68 * Message from client to Credential service to verify attributes. 66 * Message from client to Credential service to verify attributes.
69 */ 67 */
70struct VerifyMessage 68struct VerifyMessage {
71{
72 /** 69 /**
73 * Header of type #GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY 70 * Header of type #GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY
74 */ 71 */
@@ -100,17 +97,15 @@ struct VerifyMessage
100 uint32_t id GNUNET_PACKED; 97 uint32_t id GNUNET_PACKED;
101 98
102 /* Followed by the zero-terminated attribute and credentials to look up */ 99 /* Followed by the zero-terminated attribute and credentials to look up */
103
104}; 100};
105 101
106 102
107/** 103/**
108 * Message from CREDENTIAL service to client: new results. 104 * Message from CREDENTIAL service to client: new results.
109 */ 105 */
110struct DelegationChainResultMessage 106struct DelegationChainResultMessage {
111{
112 /** 107 /**
113 * Header of type #GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT 108 * Header of type #GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT
114 */ 109 */
115 struct GNUNET_MessageHeader header; 110 struct GNUNET_MessageHeader header;
116 111
@@ -118,7 +113,7 @@ struct DelegationChainResultMessage
118 * Unique identifier for this request (for key collisions). 113 * Unique identifier for this request (for key collisions).
119 */ 114 */
120 uint32_t id GNUNET_PACKED; 115 uint32_t id GNUNET_PACKED;
121 116
122 /** 117 /**
123 * Indicates if credential has been found at all 118 * Indicates if credential has been found at all
124 */ 119 */
@@ -135,16 +130,14 @@ struct DelegationChainResultMessage
135 uint32_t c_count GNUNET_PACKED; 130 uint32_t c_count GNUNET_PACKED;
136 131
137 /* followed by ad_count GNUNET_CREDENTIAL_RecordData structs*/ 132 /* followed by ad_count GNUNET_CREDENTIAL_RecordData structs*/
138
139}; 133};
140 134
141struct DelegationRecordData 135struct DelegationRecordData {
142{
143 /** 136 /**
144 * Subject key 137 * Subject key
145 */ 138 */
146 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key; 139 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
147 140
148 /** 141 /**
149 * Subject attributes 142 * Subject attributes
150 */ 143 */
@@ -152,23 +145,22 @@ struct DelegationRecordData
152}; 145};
153 146
154 147
155struct ChainEntry 148struct ChainEntry {
156{
157 /** 149 /**
158 * Issuer key 150 * Issuer key
159 */ 151 */
160 struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key; 152 struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
161 153
162 /** 154 /**
163 * Subject key 155 * Subject key
164 */ 156 */
165 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key; 157 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
166 158
167 /** 159 /**
168 * Issuer attributes 160 * Issuer attributes
169 */ 161 */
170 uint32_t issuer_attribute_len GNUNET_PACKED; 162 uint32_t issuer_attribute_len GNUNET_PACKED;
171 163
172 /** 164 /**
173 * Subject attributes 165 * Subject attributes
174 */ 166 */
@@ -176,9 +168,7 @@ struct ChainEntry
176}; 168};
177 169
178 170
179struct CredentialEntry 171struct CredentialEntry {
180{
181
182 /** 172 /**
183 * The signature for this credential by the issuer 173 * The signature for this credential by the issuer
184 */ 174 */
@@ -203,7 +193,7 @@ struct CredentialEntry
203 * Expiration time of this credential 193 * Expiration time of this credential
204 */ 194 */
205 uint64_t expiration GNUNET_PACKED; 195 uint64_t expiration GNUNET_PACKED;
206 196
207 /** 197 /**
208 * Issuer attribute length 198 * Issuer attribute length
209 */ 199 */
diff --git a/src/credential/credential_api.c b/src/credential/credential_api.c
index 84c32a724..dc1052484 100644
--- a/src/credential/credential_api.c
+++ b/src/credential/credential_api.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file credential/credential_api.c 21 * @file credential/credential_api.c
22 * @brief library to access the CREDENTIAL service 22 * @brief library to access the CREDENTIAL service
@@ -35,14 +35,12 @@
35#include "gnunet_identity_service.h" 35#include "gnunet_identity_service.h"
36 36
37 37
38#define LOG(kind,...) GNUNET_log_from (kind, "credential-api",__VA_ARGS__) 38#define LOG(kind, ...) GNUNET_log_from(kind, "credential-api", __VA_ARGS__)
39 39
40/** 40/**
41 * Handle to a verify request 41 * Handle to a verify request
42 */ 42 */
43struct GNUNET_CREDENTIAL_Request 43struct GNUNET_CREDENTIAL_Request {
44{
45
46 /** 44 /**
47 * DLL 45 * DLL
48 */ 46 */
@@ -77,16 +75,13 @@ struct GNUNET_CREDENTIAL_Request
77 * request id 75 * request id
78 */ 76 */
79 uint32_t r_id; 77 uint32_t r_id;
80
81}; 78};
82 79
83 80
84/** 81/**
85 * Connection to the CREDENTIAL service. 82 * Connection to the CREDENTIAL service.
86 */ 83 */
87struct GNUNET_CREDENTIAL_Handle 84struct GNUNET_CREDENTIAL_Handle {
88{
89
90 /** 85 /**
91 * Configuration to use. 86 * Configuration to use.
92 */ 87 */
@@ -121,7 +116,6 @@ struct GNUNET_CREDENTIAL_Handle
121 * Request Id generator. Incremented by one for each request. 116 * Request Id generator. Incremented by one for each request.
122 */ 117 */
123 uint32_t r_id_gen; 118 uint32_t r_id_gen;
124
125}; 119};
126 120
127 121
@@ -131,7 +125,7 @@ struct GNUNET_CREDENTIAL_Handle
131 * @param handle the handle to the CREDENTIAL service 125 * @param handle the handle to the CREDENTIAL service
132 */ 126 */
133static void 127static void
134reconnect (struct GNUNET_CREDENTIAL_Handle *handle); 128reconnect(struct GNUNET_CREDENTIAL_Handle *handle);
135 129
136 130
137/** 131/**
@@ -140,12 +134,12 @@ reconnect (struct GNUNET_CREDENTIAL_Handle *handle);
140 * @param cls the handle 134 * @param cls the handle
141 */ 135 */
142static void 136static void
143reconnect_task (void *cls) 137reconnect_task(void *cls)
144{ 138{
145 struct GNUNET_CREDENTIAL_Handle *handle = cls; 139 struct GNUNET_CREDENTIAL_Handle *handle = cls;
146 140
147 handle->reconnect_task = NULL; 141 handle->reconnect_task = NULL;
148 reconnect (handle); 142 reconnect(handle);
149} 143}
150 144
151 145
@@ -155,16 +149,16 @@ reconnect_task (void *cls)
155 * @param handle our handle 149 * @param handle our handle
156 */ 150 */
157static void 151static void
158force_reconnect (struct GNUNET_CREDENTIAL_Handle *handle) 152force_reconnect(struct GNUNET_CREDENTIAL_Handle *handle)
159{ 153{
160 GNUNET_MQ_destroy (handle->mq); 154 GNUNET_MQ_destroy(handle->mq);
161 handle->mq = NULL; 155 handle->mq = NULL;
162 handle->reconnect_backoff 156 handle->reconnect_backoff
163 = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); 157 = GNUNET_TIME_STD_BACKOFF(handle->reconnect_backoff);
164 handle->reconnect_task 158 handle->reconnect_task
165 = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff, 159 = GNUNET_SCHEDULER_add_delayed(handle->reconnect_backoff,
166 &reconnect_task, 160 &reconnect_task,
167 handle); 161 handle);
168} 162}
169 163
170 164
@@ -177,12 +171,12 @@ force_reconnect (struct GNUNET_CREDENTIAL_Handle *handle)
177 * @param error error code 171 * @param error error code
178 */ 172 */
179static void 173static void
180mq_error_handler (void *cls, 174mq_error_handler(void *cls,
181 enum GNUNET_MQ_Error error) 175 enum GNUNET_MQ_Error error)
182{ 176{
183 struct GNUNET_CREDENTIAL_Handle *handle = cls; 177 struct GNUNET_CREDENTIAL_Handle *handle = cls;
184 178
185 force_reconnect (handle); 179 force_reconnect(handle);
186} 180}
187 181
188/** 182/**
@@ -192,8 +186,8 @@ mq_error_handler (void *cls,
192 * @param vr_msg the incoming message 186 * @param vr_msg the incoming message
193 */ 187 */
194static int 188static int
195check_result (void *cls, 189check_result(void *cls,
196 const struct DelegationChainResultMessage *vr_msg) 190 const struct DelegationChainResultMessage *vr_msg)
197{ 191{
198 //TODO 192 //TODO
199 return GNUNET_OK; 193 return GNUNET_OK;
@@ -207,22 +201,22 @@ check_result (void *cls,
207 * @param vr_msg the incoming message 201 * @param vr_msg the incoming message
208 */ 202 */
209static void 203static void
210handle_result (void *cls, 204handle_result(void *cls,
211 const struct DelegationChainResultMessage *vr_msg) 205 const struct DelegationChainResultMessage *vr_msg)
212{ 206{
213 struct GNUNET_CREDENTIAL_Handle *handle = cls; 207 struct GNUNET_CREDENTIAL_Handle *handle = cls;
214 uint32_t r_id = ntohl (vr_msg->id); 208 uint32_t r_id = ntohl(vr_msg->id);
215 struct GNUNET_CREDENTIAL_Request *vr; 209 struct GNUNET_CREDENTIAL_Request *vr;
216 size_t mlen = ntohs (vr_msg->header.size) - sizeof (*vr_msg); 210 size_t mlen = ntohs(vr_msg->header.size) - sizeof(*vr_msg);
217 uint32_t d_count = ntohl (vr_msg->d_count); 211 uint32_t d_count = ntohl(vr_msg->d_count);
218 uint32_t c_count = ntohl (vr_msg->c_count); 212 uint32_t c_count = ntohl(vr_msg->c_count);
219 struct GNUNET_CREDENTIAL_Delegation d_chain[d_count]; 213 struct GNUNET_CREDENTIAL_Delegation d_chain[d_count];
220 struct GNUNET_CREDENTIAL_Credential creds[c_count]; 214 struct GNUNET_CREDENTIAL_Credential creds[c_count];
221 GNUNET_CREDENTIAL_CredentialResultProcessor proc; 215 GNUNET_CREDENTIAL_CredentialResultProcessor proc;
222 void *proc_cls; 216 void *proc_cls;
223 217
224 LOG (GNUNET_ERROR_TYPE_DEBUG, 218 LOG(GNUNET_ERROR_TYPE_DEBUG,
225 "Received verify reply from CREDENTIAL service\n"); 219 "Received verify reply from CREDENTIAL service\n");
226 for (vr = handle->request_head; NULL != vr; vr = vr->next) 220 for (vr = handle->request_head; NULL != vr; vr = vr->next)
227 if (vr->r_id == r_id) 221 if (vr->r_id == r_id)
228 break; 222 break;
@@ -230,32 +224,34 @@ handle_result (void *cls,
230 return; 224 return;
231 proc = vr->verify_proc; 225 proc = vr->verify_proc;
232 proc_cls = vr->proc_cls; 226 proc_cls = vr->proc_cls;
233 GNUNET_CONTAINER_DLL_remove (handle->request_head, 227 GNUNET_CONTAINER_DLL_remove(handle->request_head,
234 handle->request_tail, 228 handle->request_tail,
235 vr); 229 vr);
236 GNUNET_MQ_discard (vr->env); 230 GNUNET_MQ_discard(vr->env);
237 GNUNET_free (vr); 231 GNUNET_free(vr);
238 GNUNET_assert (GNUNET_OK == 232 GNUNET_assert(GNUNET_OK ==
239 GNUNET_CREDENTIAL_delegation_chain_deserialize (mlen, 233 GNUNET_CREDENTIAL_delegation_chain_deserialize(mlen,
240 (const char*) &vr_msg[1], 234 (const char*)&vr_msg[1],
241 d_count, 235 d_count,
242 d_chain, 236 d_chain,
243 c_count, 237 c_count,
244 creds)); 238 creds));
245 if (GNUNET_NO == ntohl (vr_msg->cred_found)) 239 if (GNUNET_NO == ntohl(vr_msg->cred_found))
246 { 240 {
247 proc (proc_cls, 241 proc(proc_cls,
248 0, 242 0,
249 NULL, 243 NULL,
250 0, 244 0,
251 NULL); // TODO 245 NULL); // TODO
252 } else { 246 }
253 proc (proc_cls, 247 else
254 d_count, 248 {
255 d_chain, 249 proc(proc_cls,
256 c_count, 250 d_count,
257 creds); 251 d_chain,
258 } 252 c_count,
253 creds);
254 }
259} 255}
260 256
261 257
@@ -265,34 +261,34 @@ handle_result (void *cls,
265 * @param handle the handle to the CREDENTIAL service 261 * @param handle the handle to the CREDENTIAL service
266 */ 262 */
267static void 263static void
268reconnect (struct GNUNET_CREDENTIAL_Handle *handle) 264reconnect(struct GNUNET_CREDENTIAL_Handle *handle)
269{ 265{
270 struct GNUNET_MQ_MessageHandler handlers[] = { 266 struct GNUNET_MQ_MessageHandler handlers[] = {
271 GNUNET_MQ_hd_var_size (result, 267 GNUNET_MQ_hd_var_size(result,
272 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT, 268 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT,
273 struct DelegationChainResultMessage, 269 struct DelegationChainResultMessage,
274 handle), 270 handle),
275 GNUNET_MQ_hd_var_size (result, 271 GNUNET_MQ_hd_var_size(result,
276 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT_RESULT, 272 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT_RESULT,
277 struct DelegationChainResultMessage, 273 struct DelegationChainResultMessage,
278 handle), 274 handle),
279 GNUNET_MQ_handler_end () 275 GNUNET_MQ_handler_end()
280 }; 276 };
281 struct GNUNET_CREDENTIAL_Request *vr; 277 struct GNUNET_CREDENTIAL_Request *vr;
282 278
283 GNUNET_assert (NULL == handle->mq); 279 GNUNET_assert(NULL == handle->mq);
284 LOG (GNUNET_ERROR_TYPE_DEBUG, 280 LOG(GNUNET_ERROR_TYPE_DEBUG,
285 "Trying to connect to CREDENTIAL\n"); 281 "Trying to connect to CREDENTIAL\n");
286 handle->mq = GNUNET_CLIENT_connect (handle->cfg, 282 handle->mq = GNUNET_CLIENT_connect(handle->cfg,
287 "credential", 283 "credential",
288 handlers, 284 handlers,
289 &mq_error_handler, 285 &mq_error_handler,
290 handle); 286 handle);
291 if (NULL == handle->mq) 287 if (NULL == handle->mq)
292 return; 288 return;
293 for (vr = handle->request_head; NULL != vr; vr = vr->next) 289 for (vr = handle->request_head; NULL != vr; vr = vr->next)
294 GNUNET_MQ_send_copy (handle->mq, 290 GNUNET_MQ_send_copy(handle->mq,
295 vr->env); 291 vr->env);
296} 292}
297 293
298 294
@@ -303,18 +299,18 @@ reconnect (struct GNUNET_CREDENTIAL_Handle *handle)
303 * @return handle to the CREDENTIAL service, or NULL on error 299 * @return handle to the CREDENTIAL service, or NULL on error
304 */ 300 */
305struct GNUNET_CREDENTIAL_Handle * 301struct GNUNET_CREDENTIAL_Handle *
306GNUNET_CREDENTIAL_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) 302GNUNET_CREDENTIAL_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
307{ 303{
308 struct GNUNET_CREDENTIAL_Handle *handle; 304 struct GNUNET_CREDENTIAL_Handle *handle;
309 305
310 handle = GNUNET_new (struct GNUNET_CREDENTIAL_Handle); 306 handle = GNUNET_new(struct GNUNET_CREDENTIAL_Handle);
311 handle->cfg = cfg; 307 handle->cfg = cfg;
312 reconnect (handle); 308 reconnect(handle);
313 if (NULL == handle->mq) 309 if (NULL == handle->mq)
314 { 310 {
315 GNUNET_free (handle); 311 GNUNET_free(handle);
316 return NULL; 312 return NULL;
317 } 313 }
318 return handle; 314 return handle;
319} 315}
320 316
@@ -325,20 +321,20 @@ GNUNET_CREDENTIAL_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
325 * @param handle handle of the CREDENTIAL connection to stop 321 * @param handle handle of the CREDENTIAL connection to stop
326 */ 322 */
327void 323void
328GNUNET_CREDENTIAL_disconnect (struct GNUNET_CREDENTIAL_Handle *handle) 324GNUNET_CREDENTIAL_disconnect(struct GNUNET_CREDENTIAL_Handle *handle)
329{ 325{
330 if (NULL != handle->mq) 326 if (NULL != handle->mq)
331 { 327 {
332 GNUNET_MQ_destroy (handle->mq); 328 GNUNET_MQ_destroy(handle->mq);
333 handle->mq = NULL; 329 handle->mq = NULL;
334 } 330 }
335 if (NULL != handle->reconnect_task) 331 if (NULL != handle->reconnect_task)
336 { 332 {
337 GNUNET_SCHEDULER_cancel (handle->reconnect_task); 333 GNUNET_SCHEDULER_cancel(handle->reconnect_task);
338 handle->reconnect_task = NULL; 334 handle->reconnect_task = NULL;
339 } 335 }
340 GNUNET_assert (NULL == handle->request_head); 336 GNUNET_assert(NULL == handle->request_head);
341 GNUNET_free (handle); 337 GNUNET_free(handle);
342} 338}
343 339
344 340
@@ -348,21 +344,21 @@ GNUNET_CREDENTIAL_disconnect (struct GNUNET_CREDENTIAL_Handle *handle)
348 * @param lr the verify request to cancel 344 * @param lr the verify request to cancel
349 */ 345 */
350void 346void
351GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *lr) 347GNUNET_CREDENTIAL_request_cancel(struct GNUNET_CREDENTIAL_Request *lr)
352{ 348{
353 struct GNUNET_CREDENTIAL_Handle *handle = lr->credential_handle; 349 struct GNUNET_CREDENTIAL_Handle *handle = lr->credential_handle;
354 350
355 GNUNET_CONTAINER_DLL_remove (handle->request_head, 351 GNUNET_CONTAINER_DLL_remove(handle->request_head,
356 handle->request_tail, 352 handle->request_tail,
357 lr); 353 lr);
358 GNUNET_MQ_discard (lr->env); 354 GNUNET_MQ_discard(lr->env);
359 GNUNET_free (lr); 355 GNUNET_free(lr);
360} 356}
361 357
362 358
363/** 359/**
364 * Performs attribute collection. 360 * Performs attribute collection.
365 * Collects all credentials of subject to fulfill the 361 * Collects all credentials of subject to fulfill the
366 * attribute, if possible 362 * attribute, if possible
367 * 363 *
368 * @param handle handle to the Credential service 364 * @param handle handle to the Credential service
@@ -374,12 +370,12 @@ GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *lr)
374 * @return handle to the queued request 370 * @return handle to the queued request
375 */ 371 */
376struct GNUNET_CREDENTIAL_Request* 372struct GNUNET_CREDENTIAL_Request*
377GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle, 373GNUNET_CREDENTIAL_collect(struct GNUNET_CREDENTIAL_Handle *handle,
378 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, 374 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
379 const char *issuer_attribute, 375 const char *issuer_attribute,
380 const struct GNUNET_CRYPTO_EcdsaPrivateKey *subject_key, 376 const struct GNUNET_CRYPTO_EcdsaPrivateKey *subject_key,
381 GNUNET_CREDENTIAL_CredentialResultProcessor proc, 377 GNUNET_CREDENTIAL_CredentialResultProcessor proc,
382 void *proc_cls) 378 void *proc_cls)
383{ 379{
384 /* IPC to shorten credential names, return shorten_handle */ 380 /* IPC to shorten credential names, return shorten_handle */
385 struct CollectMessage *c_msg; 381 struct CollectMessage *c_msg;
@@ -387,42 +383,42 @@ GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle,
387 size_t nlen; 383 size_t nlen;
388 384
389 if (NULL == issuer_attribute) 385 if (NULL == issuer_attribute)
390 { 386 {
391 GNUNET_break (0); 387 GNUNET_break(0);
392 return NULL; 388 return NULL;
393 } 389 }
394 390
395 //DEBUG LOG 391 //DEBUG LOG
396 LOG (GNUNET_ERROR_TYPE_DEBUG, 392 LOG(GNUNET_ERROR_TYPE_DEBUG,
397 "Trying to collect `%s' in CREDENTIAL\n", 393 "Trying to collect `%s' in CREDENTIAL\n",
398 issuer_attribute); 394 issuer_attribute);
399 nlen = strlen (issuer_attribute) + 1; 395 nlen = strlen(issuer_attribute) + 1;
400 if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*vr)) 396 if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*vr))
401 { 397 {
402 GNUNET_break (0); 398 GNUNET_break(0);
403 return NULL; 399 return NULL;
404 } 400 }
405 vr = GNUNET_new (struct GNUNET_CREDENTIAL_Request); 401 vr = GNUNET_new(struct GNUNET_CREDENTIAL_Request);
406 vr->credential_handle = handle; 402 vr->credential_handle = handle;
407 vr->verify_proc = proc; 403 vr->verify_proc = proc;
408 vr->proc_cls = proc_cls; 404 vr->proc_cls = proc_cls;
409 vr->r_id = handle->r_id_gen++; 405 vr->r_id = handle->r_id_gen++;
410 vr->env = GNUNET_MQ_msg_extra (c_msg, 406 vr->env = GNUNET_MQ_msg_extra(c_msg,
411 nlen, 407 nlen,
412 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT); 408 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT);
413 c_msg->id = htonl (vr->r_id); 409 c_msg->id = htonl(vr->r_id);
414 c_msg->subject_key = *subject_key; 410 c_msg->subject_key = *subject_key;
415 c_msg->issuer_key = *issuer_key; 411 c_msg->issuer_key = *issuer_key;
416 c_msg->issuer_attribute_len = htons(strlen(issuer_attribute)); 412 c_msg->issuer_attribute_len = htons(strlen(issuer_attribute));
417 GNUNET_memcpy (&c_msg[1], 413 GNUNET_memcpy(&c_msg[1],
418 issuer_attribute, 414 issuer_attribute,
419 strlen (issuer_attribute)); 415 strlen(issuer_attribute));
420 GNUNET_CONTAINER_DLL_insert (handle->request_head, 416 GNUNET_CONTAINER_DLL_insert(handle->request_head,
421 handle->request_tail, 417 handle->request_tail,
422 vr); 418 vr);
423 if (NULL != handle->mq) 419 if (NULL != handle->mq)
424 GNUNET_MQ_send_copy (handle->mq, 420 GNUNET_MQ_send_copy(handle->mq,
425 vr->env); 421 vr->env);
426 return vr; 422 return vr;
427} 423}
428/** 424/**
@@ -444,14 +440,14 @@ GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle,
444 * @return handle to the queued request 440 * @return handle to the queued request
445 */ 441 */
446struct GNUNET_CREDENTIAL_Request* 442struct GNUNET_CREDENTIAL_Request*
447GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle, 443GNUNET_CREDENTIAL_verify(struct GNUNET_CREDENTIAL_Handle *handle,
448 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, 444 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
449 const char *issuer_attribute, 445 const char *issuer_attribute,
450 const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key, 446 const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key,
451 uint32_t credential_count, 447 uint32_t credential_count,
452 const struct GNUNET_CREDENTIAL_Credential *credentials, 448 const struct GNUNET_CREDENTIAL_Credential *credentials,
453 GNUNET_CREDENTIAL_CredentialResultProcessor proc, 449 GNUNET_CREDENTIAL_CredentialResultProcessor proc,
454 void *proc_cls) 450 void *proc_cls)
455{ 451{
456 /* IPC to shorten credential names, return shorten_handle */ 452 /* IPC to shorten credential names, return shorten_handle */
457 struct VerifyMessage *v_msg; 453 struct VerifyMessage *v_msg;
@@ -460,51 +456,51 @@ GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle,
460 size_t clen; 456 size_t clen;
461 457
462 if (NULL == issuer_attribute || NULL == credentials) 458 if (NULL == issuer_attribute || NULL == credentials)
463 { 459 {
464 GNUNET_break (0); 460 GNUNET_break(0);
465 return NULL; 461 return NULL;
466 } 462 }
467 463
468 clen = GNUNET_CREDENTIAL_credentials_get_size (credential_count, 464 clen = GNUNET_CREDENTIAL_credentials_get_size(credential_count,
469 credentials); 465 credentials);
470 466
471 //DEBUG LOG 467 //DEBUG LOG
472 LOG (GNUNET_ERROR_TYPE_DEBUG, 468 LOG(GNUNET_ERROR_TYPE_DEBUG,
473 "Trying to verify `%s' in CREDENTIAL\n", 469 "Trying to verify `%s' in CREDENTIAL\n",
474 issuer_attribute); 470 issuer_attribute);
475 nlen = strlen (issuer_attribute) + 1 + clen; 471 nlen = strlen(issuer_attribute) + 1 + clen;
476 if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*vr)) 472 if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*vr))
477 { 473 {
478 GNUNET_break (0); 474 GNUNET_break(0);
479 return NULL; 475 return NULL;
480 } 476 }
481 vr = GNUNET_new (struct GNUNET_CREDENTIAL_Request); 477 vr = GNUNET_new(struct GNUNET_CREDENTIAL_Request);
482 vr->credential_handle = handle; 478 vr->credential_handle = handle;
483 vr->verify_proc = proc; 479 vr->verify_proc = proc;
484 vr->proc_cls = proc_cls; 480 vr->proc_cls = proc_cls;
485 vr->r_id = handle->r_id_gen++; 481 vr->r_id = handle->r_id_gen++;
486 vr->env = GNUNET_MQ_msg_extra (v_msg, 482 vr->env = GNUNET_MQ_msg_extra(v_msg,
487 nlen, 483 nlen,
488 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY); 484 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY);
489 v_msg->id = htonl (vr->r_id); 485 v_msg->id = htonl(vr->r_id);
490 v_msg->subject_key = *subject_key; 486 v_msg->subject_key = *subject_key;
491 v_msg->c_count = htonl(credential_count); 487 v_msg->c_count = htonl(credential_count);
492 v_msg->issuer_key = *issuer_key; 488 v_msg->issuer_key = *issuer_key;
493 v_msg->issuer_attribute_len = htons(strlen(issuer_attribute)); 489 v_msg->issuer_attribute_len = htons(strlen(issuer_attribute));
494 GNUNET_memcpy (&v_msg[1], 490 GNUNET_memcpy(&v_msg[1],
495 issuer_attribute, 491 issuer_attribute,
496 strlen (issuer_attribute)); 492 strlen(issuer_attribute));
497 GNUNET_CREDENTIAL_credentials_serialize (credential_count, 493 GNUNET_CREDENTIAL_credentials_serialize(credential_count,
498 credentials, 494 credentials,
499 clen, 495 clen,
500 ((char*)&v_msg[1]) 496 ((char*)&v_msg[1])
501 + strlen (issuer_attribute) + 1); 497 + strlen(issuer_attribute) + 1);
502 GNUNET_CONTAINER_DLL_insert (handle->request_head, 498 GNUNET_CONTAINER_DLL_insert(handle->request_head,
503 handle->request_tail, 499 handle->request_tail,
504 vr); 500 vr);
505 if (NULL != handle->mq) 501 if (NULL != handle->mq)
506 GNUNET_MQ_send_copy (handle->mq, 502 GNUNET_MQ_send_copy(handle->mq,
507 vr->env); 503 vr->env);
508 return vr; 504 return vr;
509} 505}
510 506
diff --git a/src/credential/credential_misc.c b/src/credential/credential_misc.c
index ae208f31f..be6d124a6 100644
--- a/src/credential/credential_misc.c
+++ b/src/credential/credential_misc.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21 21
22/** 22/**
@@ -34,7 +34,7 @@
34#include <inttypes.h> 34#include <inttypes.h>
35 35
36char* 36char*
37GNUNET_CREDENTIAL_credential_to_string (const struct GNUNET_CREDENTIAL_Credential *cred) 37GNUNET_CREDENTIAL_credential_to_string(const struct GNUNET_CREDENTIAL_Credential *cred)
38{ 38{
39 char *cred_str; 39 char *cred_str;
40 char *subject_pkey; 40 char *subject_pkey;
@@ -42,29 +42,30 @@ GNUNET_CREDENTIAL_credential_to_string (const struct GNUNET_CREDENTIAL_Credentia
42 char *signature; 42 char *signature;
43 43
44 44
45 subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key); 45 subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->subject_key);
46 issuer_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key); 46 issuer_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->issuer_key);
47 GNUNET_STRINGS_base64_encode ((char*)&cred->signature, 47 GNUNET_STRINGS_base64_encode((char*)&cred->signature,
48 sizeof (struct GNUNET_CRYPTO_EcdsaSignature), 48 sizeof(struct GNUNET_CRYPTO_EcdsaSignature),
49 &signature); 49 &signature);
50 GNUNET_asprintf (&cred_str, 50 GNUNET_asprintf(&cred_str,
51 "%s.%s -> %s | %s | %"SCNu64, 51 "%s.%s -> %s | %s | %" SCNu64,
52 issuer_pkey, 52 issuer_pkey,
53 cred->issuer_attribute, 53 cred->issuer_attribute,
54 subject_pkey, 54 subject_pkey,
55 signature, 55 signature,
56 cred->expiration.abs_value_us); 56 cred->expiration.abs_value_us);
57 GNUNET_free (subject_pkey); 57 GNUNET_free(subject_pkey);
58 GNUNET_free (issuer_pkey); 58 GNUNET_free(issuer_pkey);
59 GNUNET_free (signature); 59 GNUNET_free(signature);
60 return cred_str; 60 return cred_str;
61} 61}
62 62
63struct GNUNET_CREDENTIAL_Credential* 63struct GNUNET_CREDENTIAL_Credential*
64GNUNET_CREDENTIAL_credential_from_string (const char* s) 64GNUNET_CREDENTIAL_credential_from_string(const char* s)
65{ 65{
66 struct GNUNET_CREDENTIAL_Credential *cred; 66 struct GNUNET_CREDENTIAL_Credential *cred;
67 size_t enclen = (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8; 67 size_t enclen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
68
68 if (enclen % 5 > 0) 69 if (enclen % 5 > 0)
69 enclen += 5 - enclen % 5; 70 enclen += 5 - enclen % 5;
70 enclen /= 5; /* 260/5 = 52 */ 71 enclen /= 5; /* 260/5 = 52 */
@@ -76,36 +77,36 @@ GNUNET_CREDENTIAL_credential_from_string (const char* s)
76 struct GNUNET_CRYPTO_EcdsaSignature *sig; 77 struct GNUNET_CRYPTO_EcdsaSignature *sig;
77 struct GNUNET_TIME_Absolute etime_abs; 78 struct GNUNET_TIME_Absolute etime_abs;
78 79
79 if (5 != SSCANF (s, 80 if (5 != SSCANF(s,
80 "%52s.%253s -> %52s | %s | %"SCNu64, 81 "%52s.%253s -> %52s | %s | %" SCNu64,
81 issuer_pkey, 82 issuer_pkey,
82 name, 83 name,
83 subject_pkey, 84 subject_pkey,
84 signature, 85 signature,
85 &etime_abs.abs_value_us)) 86 &etime_abs.abs_value_us))
86 { 87 {
87 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 88 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
88 _("Unable to parse CRED record string `%s'\n"), 89 _("Unable to parse CRED record string `%s'\n"),
89 s); 90 s);
90 return NULL; 91 return NULL;
91 } 92 }
92 cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + strlen (name) + 1); 93 cred = GNUNET_malloc(sizeof(struct GNUNET_CREDENTIAL_Credential) + strlen(name) + 1);
93 GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, 94 GNUNET_CRYPTO_ecdsa_public_key_from_string(subject_pkey,
94 strlen (subject_pkey), 95 strlen(subject_pkey),
95 &cred->subject_key); 96 &cred->subject_key);
96 GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_pkey, 97 GNUNET_CRYPTO_ecdsa_public_key_from_string(issuer_pkey,
97 strlen (issuer_pkey), 98 strlen(issuer_pkey),
98 &cred->issuer_key); 99 &cred->issuer_key);
99 GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EcdsaSignature) == GNUNET_STRINGS_base64_decode (signature, 100 GNUNET_assert(sizeof(struct GNUNET_CRYPTO_EcdsaSignature) == GNUNET_STRINGS_base64_decode(signature,
100 strlen (signature), 101 strlen(signature),
101 (char**)&sig)); 102 (char**)&sig));
102 cred->signature = *sig; 103 cred->signature = *sig;
103 cred->expiration = etime_abs; 104 cred->expiration = etime_abs;
104 GNUNET_free (sig); 105 GNUNET_free(sig);
105 GNUNET_memcpy (&cred[1], 106 GNUNET_memcpy(&cred[1],
106 name, 107 name,
107 strlen (name)+1); 108 strlen(name) + 1);
108 cred->issuer_attribute_len = strlen ((char*)&cred[1]); 109 cred->issuer_attribute_len = strlen((char*)&cred[1]);
109 cred->issuer_attribute = (char*)&cred[1]; 110 cred->issuer_attribute = (char*)&cred[1];
110 return cred; 111 return cred;
111} 112}
@@ -119,50 +120,50 @@ GNUNET_CREDENTIAL_credential_from_string (const char* s)
119 * @return handle to the queued request 120 * @return handle to the queued request
120 */ 121 */
121struct GNUNET_CREDENTIAL_Credential * 122struct GNUNET_CREDENTIAL_Credential *
122GNUNET_CREDENTIAL_credential_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, 123GNUNET_CREDENTIAL_credential_issue(const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
123 struct GNUNET_CRYPTO_EcdsaPublicKey *subject, 124 struct GNUNET_CRYPTO_EcdsaPublicKey *subject,
124 const char *attribute, 125 const char *attribute,
125 struct GNUNET_TIME_Absolute *expiration) 126 struct GNUNET_TIME_Absolute *expiration)
126{ 127{
127 struct CredentialEntry *crd; 128 struct CredentialEntry *crd;
128 struct GNUNET_CREDENTIAL_Credential *cred; 129 struct GNUNET_CREDENTIAL_Credential *cred;
129 size_t size; 130 size_t size;
130 131
131 size = sizeof (struct CredentialEntry) + strlen (attribute) + 1; 132 size = sizeof(struct CredentialEntry) + strlen(attribute) + 1;
132 crd = GNUNET_malloc (size); 133 crd = GNUNET_malloc(size);
133 cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + strlen (attribute) + 1); 134 cred = GNUNET_malloc(sizeof(struct GNUNET_CREDENTIAL_Credential) + strlen(attribute) + 1);
134 crd->purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); 135 crd->purpose.size = htonl(size - sizeof(struct GNUNET_CRYPTO_EcdsaSignature));
135 136
136 crd->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); 137 crd->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_CREDENTIAL);
137 GNUNET_CRYPTO_ecdsa_key_get_public (issuer, 138 GNUNET_CRYPTO_ecdsa_key_get_public(issuer,
138 &crd->issuer_key); 139 &crd->issuer_key);
139 crd->subject_key = *subject; 140 crd->subject_key = *subject;
140 crd->expiration = GNUNET_htonll (expiration->abs_value_us); 141 crd->expiration = GNUNET_htonll(expiration->abs_value_us);
141 crd->issuer_attribute_len = htonl (strlen (attribute)+1); 142 crd->issuer_attribute_len = htonl(strlen(attribute) + 1);
142 GNUNET_memcpy ((char*)&crd[1], 143 GNUNET_memcpy((char*)&crd[1],
143 attribute, 144 attribute,
144 strlen (attribute)+1); 145 strlen(attribute) + 1);
145 if (GNUNET_OK != 146 if (GNUNET_OK !=
146 GNUNET_CRYPTO_ecdsa_sign (issuer, 147 GNUNET_CRYPTO_ecdsa_sign(issuer,
147 &crd->purpose, 148 &crd->purpose,
148 &crd->signature)) 149 &crd->signature))
149 { 150 {
150 GNUNET_break (0); 151 GNUNET_break(0);
151 GNUNET_free (crd); 152 GNUNET_free(crd);
152 GNUNET_free (cred); 153 GNUNET_free(cred);
153 return NULL; 154 return NULL;
154 } 155 }
155 cred->signature = crd->signature; 156 cred->signature = crd->signature;
156 cred->expiration = *expiration; 157 cred->expiration = *expiration;
157 GNUNET_CRYPTO_ecdsa_key_get_public (issuer, 158 GNUNET_CRYPTO_ecdsa_key_get_public(issuer,
158 &cred->issuer_key); 159 &cred->issuer_key);
159 160
160 cred->subject_key = *subject; 161 cred->subject_key = *subject;
161 GNUNET_memcpy (&cred[1], 162 GNUNET_memcpy(&cred[1],
162 attribute, 163 attribute,
163 strlen (attribute)+1); 164 strlen(attribute) + 1);
164 cred->issuer_attribute = (char*)&cred[1]; 165 cred->issuer_attribute = (char*)&cred[1];
165 GNUNET_free (crd); 166 GNUNET_free(crd);
166 return cred; 167 return cred;
167} 168}
168 169
diff --git a/src/credential/credential_misc.h b/src/credential/credential_misc.h
index b06ee98cf..0411f0af3 100644
--- a/src/credential/credential_misc.h
+++ b/src/credential/credential_misc.h
@@ -27,10 +27,10 @@
27#include "gnunet_credential_service.h" 27#include "gnunet_credential_service.h"
28 28
29char * 29char *
30GNUNET_CREDENTIAL_credential_to_string ( 30GNUNET_CREDENTIAL_credential_to_string(
31 const struct GNUNET_CREDENTIAL_Credential *cred); 31 const struct GNUNET_CREDENTIAL_Credential *cred);
32 32
33struct GNUNET_CREDENTIAL_Credential * 33struct GNUNET_CREDENTIAL_Credential *
34GNUNET_CREDENTIAL_credential_from_string (const char *str); 34GNUNET_CREDENTIAL_credential_from_string(const char *str);
35 35
36#endif 36#endif
diff --git a/src/credential/credential_serialization.c b/src/credential/credential_serialization.c
index 5ee3cfb07..eac310272 100644
--- a/src/credential/credential_serialization.c
+++ b/src/credential/credential_serialization.c
@@ -11,17 +11,17 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21 21
22/** 22/**
23 * @file credential/credential_serialization.c 23 * @file credential/credential_serialization.c
24 * @brief API to serialize and deserialize delegation chains 24 * @brief API to serialize and deserialize delegation chains
25 * and credentials 25 * and credentials
26 * @author Martin Schanzenbach 26 * @author Martin Schanzenbach
27 */ 27 */
@@ -41,19 +41,19 @@
41 * @return the required size to serialize 41 * @return the required size to serialize
42 */ 42 */
43size_t 43size_t
44GNUNET_CREDENTIAL_delegation_set_get_size (unsigned int ds_count, 44GNUNET_CREDENTIAL_delegation_set_get_size(unsigned int ds_count,
45 const struct GNUNET_CREDENTIAL_DelegationSet *dsr) 45 const struct GNUNET_CREDENTIAL_DelegationSet *dsr)
46{ 46{
47 unsigned int i; 47 unsigned int i;
48 size_t ret; 48 size_t ret;
49 49
50 ret = sizeof (struct DelegationRecordData) * (ds_count); 50 ret = sizeof(struct DelegationRecordData) * (ds_count);
51 51
52 for (i=0; i<ds_count;i++) 52 for (i = 0; i < ds_count; i++)
53 { 53 {
54 GNUNET_assert ((ret + dsr[i].subject_attribute_len) >= ret); 54 GNUNET_assert((ret + dsr[i].subject_attribute_len) >= ret);
55 ret += dsr[i].subject_attribute_len; 55 ret += dsr[i].subject_attribute_len;
56 } 56 }
57 return ret; 57 return ret;
58} 58}
59 59
@@ -67,35 +67,35 @@ GNUNET_CREDENTIAL_delegation_set_get_size (unsigned int ds_count,
67 * @return the size of the data, -1 on failure 67 * @return the size of the data, -1 on failure
68 */ 68 */
69ssize_t 69ssize_t
70GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count, 70GNUNET_CREDENTIAL_delegation_set_serialize(unsigned int d_count,
71 const struct GNUNET_CREDENTIAL_DelegationSet *dsr, 71 const struct GNUNET_CREDENTIAL_DelegationSet *dsr,
72 size_t dest_size, 72 size_t dest_size,
73 char *dest) 73 char *dest)
74{ 74{
75 struct DelegationRecordData rec; 75 struct DelegationRecordData rec;
76 unsigned int i; 76 unsigned int i;
77 size_t off; 77 size_t off;
78 78
79 off = 0; 79 off = 0;
80 for (i=0;i<d_count;i++) 80 for (i = 0; i < d_count; i++)
81 { 81 {
82 rec.subject_attribute_len = htonl ((uint32_t) dsr[i].subject_attribute_len); 82 rec.subject_attribute_len = htonl((uint32_t)dsr[i].subject_attribute_len);
83 rec.subject_key = dsr[i].subject_key; 83 rec.subject_key = dsr[i].subject_key;
84 if (off + sizeof (rec) > dest_size) 84 if (off + sizeof(rec) > dest_size)
85 return -1; 85 return -1;
86 GNUNET_memcpy (&dest[off], 86 GNUNET_memcpy(&dest[off],
87 &rec, 87 &rec,
88 sizeof (rec)); 88 sizeof(rec));
89 off += sizeof (rec); 89 off += sizeof(rec);
90 if (0 == dsr[i].subject_attribute_len) 90 if (0 == dsr[i].subject_attribute_len)
91 continue; 91 continue;
92 if (off + dsr[i].subject_attribute_len > dest_size) 92 if (off + dsr[i].subject_attribute_len > dest_size)
93 return -1; 93 return -1;
94 GNUNET_memcpy (&dest[off], 94 GNUNET_memcpy(&dest[off],
95 dsr[i].subject_attribute, 95 dsr[i].subject_attribute,
96 dsr[i].subject_attribute_len); 96 dsr[i].subject_attribute_len);
97 off += dsr[i].subject_attribute_len; 97 off += dsr[i].subject_attribute_len;
98 } 98 }
99 return off; 99 return off;
100} 100}
101 101
@@ -110,29 +110,29 @@ GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count,
110 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 110 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
111 */ 111 */
112int 112int
113GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len, 113GNUNET_CREDENTIAL_delegation_set_deserialize(size_t len,
114 const char *src, 114 const char *src,
115 unsigned int d_count, 115 unsigned int d_count,
116 struct GNUNET_CREDENTIAL_DelegationSet *dsr) 116 struct GNUNET_CREDENTIAL_DelegationSet *dsr)
117{ 117{
118 struct DelegationRecordData rec; 118 struct DelegationRecordData rec;
119 unsigned int i; 119 unsigned int i;
120 size_t off; 120 size_t off;
121 121
122 off = 0; 122 off = 0;
123 for (i=0;i<d_count;i++) 123 for (i = 0; i < d_count; i++)
124 { 124 {
125 if (off + sizeof (rec) > len) 125 if (off + sizeof(rec) > len)
126 return GNUNET_SYSERR; 126 return GNUNET_SYSERR;
127 GNUNET_memcpy (&rec, &src[off], sizeof (rec)); 127 GNUNET_memcpy(&rec, &src[off], sizeof(rec));
128 dsr[i].subject_key = rec.subject_key; 128 dsr[i].subject_key = rec.subject_key;
129 off += sizeof (rec); 129 off += sizeof(rec);
130 dsr[i].subject_attribute_len = ntohl ((uint32_t) rec.subject_attribute_len); 130 dsr[i].subject_attribute_len = ntohl((uint32_t)rec.subject_attribute_len);
131 if (off + dsr[i].subject_attribute_len > len) 131 if (off + dsr[i].subject_attribute_len > len)
132 return GNUNET_SYSERR; 132 return GNUNET_SYSERR;
133 dsr[i].subject_attribute = (char*)&src[off]; 133 dsr[i].subject_attribute = (char*)&src[off];
134 off += dsr[i].subject_attribute_len; 134 off += dsr[i].subject_attribute_len;
135 } 135 }
136 return GNUNET_OK; 136 return GNUNET_OK;
137} 137}
138 138
@@ -146,19 +146,19 @@ GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len,
146 * @return the required size to serialize 146 * @return the required size to serialize
147 */ 147 */
148size_t 148size_t
149GNUNET_CREDENTIAL_credentials_get_size (unsigned int c_count, 149GNUNET_CREDENTIAL_credentials_get_size(unsigned int c_count,
150 const struct GNUNET_CREDENTIAL_Credential *cd) 150 const struct GNUNET_CREDENTIAL_Credential *cd)
151{ 151{
152 unsigned int i; 152 unsigned int i;
153 size_t ret; 153 size_t ret;
154 154
155 ret = sizeof (struct CredentialEntry) * (c_count); 155 ret = sizeof(struct CredentialEntry) * (c_count);
156 156
157 for (i=0; i<c_count;i++) 157 for (i = 0; i < c_count; i++)
158 { 158 {
159 GNUNET_assert ((ret + cd[i].issuer_attribute_len) >= ret); 159 GNUNET_assert((ret + cd[i].issuer_attribute_len) >= ret);
160 ret += cd[i].issuer_attribute_len; 160 ret += cd[i].issuer_attribute_len;
161 } 161 }
162 return ret; 162 return ret;
163} 163}
164/** 164/**
@@ -171,38 +171,38 @@ GNUNET_CREDENTIAL_credentials_get_size (unsigned int c_count,
171 * @return the size of the data, -1 on failure 171 * @return the size of the data, -1 on failure
172 */ 172 */
173ssize_t 173ssize_t
174GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, 174GNUNET_CREDENTIAL_credentials_serialize(unsigned int c_count,
175 const struct GNUNET_CREDENTIAL_Credential *cd, 175 const struct GNUNET_CREDENTIAL_Credential *cd,
176 size_t dest_size, 176 size_t dest_size,
177 char *dest) 177 char *dest)
178{ 178{
179 struct CredentialEntry c_rec; 179 struct CredentialEntry c_rec;
180 unsigned int i; 180 unsigned int i;
181 size_t off; 181 size_t off;
182 182
183 off = 0; 183 off = 0;
184 for (i=0;i<c_count;i++) 184 for (i = 0; i < c_count; i++)
185 { 185 {
186 c_rec.issuer_attribute_len = htonl ((uint32_t) cd[i].issuer_attribute_len); 186 c_rec.issuer_attribute_len = htonl((uint32_t)cd[i].issuer_attribute_len);
187 c_rec.issuer_key = cd[i].issuer_key; 187 c_rec.issuer_key = cd[i].issuer_key;
188 c_rec.subject_key = cd[i].subject_key; 188 c_rec.subject_key = cd[i].subject_key;
189 c_rec.signature = cd[i].signature; 189 c_rec.signature = cd[i].signature;
190 c_rec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); 190 c_rec.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_CREDENTIAL);
191 c_rec.purpose.size = htonl ((sizeof (struct CredentialEntry) + cd[i].issuer_attribute_len) - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); 191 c_rec.purpose.size = htonl((sizeof(struct CredentialEntry) + cd[i].issuer_attribute_len) - sizeof(struct GNUNET_CRYPTO_EcdsaSignature));
192 c_rec.expiration = GNUNET_htonll (cd[i].expiration.abs_value_us); 192 c_rec.expiration = GNUNET_htonll(cd[i].expiration.abs_value_us);
193 if (off + sizeof (c_rec) > dest_size) 193 if (off + sizeof(c_rec) > dest_size)
194 return -1; 194 return -1;
195 GNUNET_memcpy (&dest[off], 195 GNUNET_memcpy(&dest[off],
196 &c_rec, 196 &c_rec,
197 sizeof (c_rec)); 197 sizeof(c_rec));
198 off += sizeof (c_rec); 198 off += sizeof(c_rec);
199 if (off + cd[i].issuer_attribute_len > dest_size) 199 if (off + cd[i].issuer_attribute_len > dest_size)
200 return -1; 200 return -1;
201 GNUNET_memcpy (&dest[off], 201 GNUNET_memcpy(&dest[off],
202 cd[i].issuer_attribute, 202 cd[i].issuer_attribute,
203 cd[i].issuer_attribute_len); 203 cd[i].issuer_attribute_len);
204 off += cd[i].issuer_attribute_len; 204 off += cd[i].issuer_attribute_len;
205 } 205 }
206 206
207 return off; 207 return off;
208} 208}
@@ -219,32 +219,32 @@ GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count,
219 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 219 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
220 */ 220 */
221int 221int
222GNUNET_CREDENTIAL_credentials_deserialize (size_t len, 222GNUNET_CREDENTIAL_credentials_deserialize(size_t len,
223 const char *src, 223 const char *src,
224 unsigned int c_count, 224 unsigned int c_count,
225 struct GNUNET_CREDENTIAL_Credential *cd) 225 struct GNUNET_CREDENTIAL_Credential *cd)
226{ 226{
227 struct CredentialEntry c_rec; 227 struct CredentialEntry c_rec;
228 unsigned int i; 228 unsigned int i;
229 size_t off; 229 size_t off;
230 230
231 off = 0; 231 off = 0;
232 for (i=0;i<c_count;i++) 232 for (i = 0; i < c_count; i++)
233 { 233 {
234 if (off + sizeof (c_rec) > len) 234 if (off + sizeof(c_rec) > len)
235 return GNUNET_SYSERR; 235 return GNUNET_SYSERR;
236 GNUNET_memcpy (&c_rec, &src[off], sizeof (c_rec)); 236 GNUNET_memcpy(&c_rec, &src[off], sizeof(c_rec));
237 cd[i].issuer_attribute_len = ntohl ((uint32_t) c_rec.issuer_attribute_len); 237 cd[i].issuer_attribute_len = ntohl((uint32_t)c_rec.issuer_attribute_len);
238 cd[i].issuer_key = c_rec.issuer_key; 238 cd[i].issuer_key = c_rec.issuer_key;
239 cd[i].subject_key = c_rec.subject_key; 239 cd[i].subject_key = c_rec.subject_key;
240 cd[i].signature = c_rec.signature; 240 cd[i].signature = c_rec.signature;
241 cd[i].expiration.abs_value_us = GNUNET_ntohll(c_rec.expiration); 241 cd[i].expiration.abs_value_us = GNUNET_ntohll(c_rec.expiration);
242 off += sizeof (c_rec); 242 off += sizeof(c_rec);
243 if (off + cd[i].issuer_attribute_len > len) 243 if (off + cd[i].issuer_attribute_len > len)
244 return GNUNET_SYSERR; 244 return GNUNET_SYSERR;
245 cd[i].issuer_attribute = &src[off]; 245 cd[i].issuer_attribute = &src[off];
246 off += cd[i].issuer_attribute_len; 246 off += cd[i].issuer_attribute_len;
247 } 247 }
248 return GNUNET_OK; 248 return GNUNET_OK;
249} 249}
250 250
@@ -261,24 +261,24 @@ GNUNET_CREDENTIAL_credentials_deserialize (size_t len,
261 * @return the required size to serialize 261 * @return the required size to serialize
262 */ 262 */
263size_t 263size_t
264GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count, 264GNUNET_CREDENTIAL_delegation_chain_get_size(unsigned int d_count,
265 const struct GNUNET_CREDENTIAL_Delegation *dd, 265 const struct GNUNET_CREDENTIAL_Delegation *dd,
266 unsigned int c_count, 266 unsigned int c_count,
267 const struct GNUNET_CREDENTIAL_Credential *cd) 267 const struct GNUNET_CREDENTIAL_Credential *cd)
268{ 268{
269 unsigned int i; 269 unsigned int i;
270 size_t ret; 270 size_t ret;
271 271
272 ret = sizeof (struct ChainEntry) * (d_count); 272 ret = sizeof(struct ChainEntry) * (d_count);
273 273
274 for (i=0; i<d_count;i++) 274 for (i = 0; i < d_count; i++)
275 { 275 {
276 GNUNET_assert ((ret + 276 GNUNET_assert((ret +
277 dd[i].issuer_attribute_len + 277 dd[i].issuer_attribute_len +
278 dd[i].subject_attribute_len) >= ret); 278 dd[i].subject_attribute_len) >= ret);
279 ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len; 279 ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len;
280 } 280 }
281 return ret+GNUNET_CREDENTIAL_credentials_get_size(c_count, cd); 281 return ret + GNUNET_CREDENTIAL_credentials_get_size(c_count, cd);
282} 282}
283 283
284/** 284/**
@@ -293,49 +293,49 @@ GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count,
293 * @return the size of the data, -1 on failure 293 * @return the size of the data, -1 on failure
294 */ 294 */
295ssize_t 295ssize_t
296GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count, 296GNUNET_CREDENTIAL_delegation_chain_serialize(unsigned int d_count,
297 const struct GNUNET_CREDENTIAL_Delegation *dd, 297 const struct GNUNET_CREDENTIAL_Delegation *dd,
298 unsigned int c_count, 298 unsigned int c_count,
299 const struct GNUNET_CREDENTIAL_Credential *cd, 299 const struct GNUNET_CREDENTIAL_Credential *cd,
300 size_t dest_size, 300 size_t dest_size,
301 char *dest) 301 char *dest)
302{ 302{
303 struct ChainEntry rec; 303 struct ChainEntry rec;
304 unsigned int i; 304 unsigned int i;
305 size_t off; 305 size_t off;
306 306
307 off = 0; 307 off = 0;
308 for (i=0;i<d_count;i++) 308 for (i = 0; i < d_count; i++)
309 { 309 {
310 rec.issuer_attribute_len = htonl ((uint32_t) dd[i].issuer_attribute_len); 310 rec.issuer_attribute_len = htonl((uint32_t)dd[i].issuer_attribute_len);
311 rec.subject_attribute_len = htonl ((uint32_t) dd[i].subject_attribute_len); 311 rec.subject_attribute_len = htonl((uint32_t)dd[i].subject_attribute_len);
312 rec.issuer_key = dd[i].issuer_key; 312 rec.issuer_key = dd[i].issuer_key;
313 rec.subject_key = dd[i].subject_key; 313 rec.subject_key = dd[i].subject_key;
314 if (off + sizeof (rec) > dest_size) 314 if (off + sizeof(rec) > dest_size)
315 return -1; 315 return -1;
316 GNUNET_memcpy (&dest[off], 316 GNUNET_memcpy(&dest[off],
317 &rec, 317 &rec,
318 sizeof (rec)); 318 sizeof(rec));
319 off += sizeof (rec); 319 off += sizeof(rec);
320 if (off + dd[i].issuer_attribute_len > dest_size) 320 if (off + dd[i].issuer_attribute_len > dest_size)
321 return -1; 321 return -1;
322 GNUNET_memcpy (&dest[off], 322 GNUNET_memcpy(&dest[off],
323 dd[i].issuer_attribute, 323 dd[i].issuer_attribute,
324 dd[i].issuer_attribute_len); 324 dd[i].issuer_attribute_len);
325 off += dd[i].issuer_attribute_len; 325 off += dd[i].issuer_attribute_len;
326 if (0 == dd[i].subject_attribute_len) 326 if (0 == dd[i].subject_attribute_len)
327 continue; 327 continue;
328 if (off + dd[i].subject_attribute_len > dest_size) 328 if (off + dd[i].subject_attribute_len > dest_size)
329 return -1; 329 return -1;
330 GNUNET_memcpy (&dest[off], 330 GNUNET_memcpy(&dest[off],
331 dd[i].subject_attribute, 331 dd[i].subject_attribute,
332 dd[i].subject_attribute_len); 332 dd[i].subject_attribute_len);
333 off += dd[i].subject_attribute_len; 333 off += dd[i].subject_attribute_len;
334 } 334 }
335 return off+GNUNET_CREDENTIAL_credentials_serialize (c_count, 335 return off + GNUNET_CREDENTIAL_credentials_serialize(c_count,
336 cd, 336 cd,
337 dest_size-off, 337 dest_size - off,
338 &dest[off]); 338 &dest[off]);
339} 339}
340 340
341 341
@@ -351,107 +351,107 @@ GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count,
351 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 351 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
352 */ 352 */
353int 353int
354GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len, 354GNUNET_CREDENTIAL_delegation_chain_deserialize(size_t len,
355 const char *src, 355 const char *src,
356 unsigned int d_count, 356 unsigned int d_count,
357 struct GNUNET_CREDENTIAL_Delegation *dd, 357 struct GNUNET_CREDENTIAL_Delegation *dd,
358 unsigned int c_count, 358 unsigned int c_count,
359 struct GNUNET_CREDENTIAL_Credential *cd) 359 struct GNUNET_CREDENTIAL_Credential *cd)
360{ 360{
361 struct ChainEntry rec; 361 struct ChainEntry rec;
362 unsigned int i; 362 unsigned int i;
363 size_t off; 363 size_t off;
364 364
365 off = 0; 365 off = 0;
366 for (i=0;i<d_count;i++) 366 for (i = 0; i < d_count; i++)
367 { 367 {
368 if (off + sizeof (rec) > len) 368 if (off + sizeof(rec) > len)
369 return GNUNET_SYSERR; 369 return GNUNET_SYSERR;
370 GNUNET_memcpy (&rec, &src[off], sizeof (rec)); 370 GNUNET_memcpy(&rec, &src[off], sizeof(rec));
371 dd[i].issuer_attribute_len = ntohl ((uint32_t) rec.issuer_attribute_len); 371 dd[i].issuer_attribute_len = ntohl((uint32_t)rec.issuer_attribute_len);
372 dd[i].issuer_key = rec.issuer_key; 372 dd[i].issuer_key = rec.issuer_key;
373 dd[i].subject_key = rec.subject_key; 373 dd[i].subject_key = rec.subject_key;
374 off += sizeof (rec); 374 off += sizeof(rec);
375 if (off + dd[i].issuer_attribute_len > len) 375 if (off + dd[i].issuer_attribute_len > len)
376 return GNUNET_SYSERR; 376 return GNUNET_SYSERR;
377 dd[i].issuer_attribute = &src[off]; 377 dd[i].issuer_attribute = &src[off];
378 off += dd[i].issuer_attribute_len; 378 off += dd[i].issuer_attribute_len;
379 dd[i].subject_attribute_len = ntohl ((uint32_t) rec.subject_attribute_len); 379 dd[i].subject_attribute_len = ntohl((uint32_t)rec.subject_attribute_len);
380 if (off + dd[i].subject_attribute_len > len) 380 if (off + dd[i].subject_attribute_len > len)
381 return GNUNET_SYSERR; 381 return GNUNET_SYSERR;
382 dd[i].subject_attribute = &src[off]; 382 dd[i].subject_attribute = &src[off];
383 off += dd[i].subject_attribute_len; 383 off += dd[i].subject_attribute_len;
384 } 384 }
385 return GNUNET_CREDENTIAL_credentials_deserialize (len-off, 385 return GNUNET_CREDENTIAL_credentials_deserialize(len - off,
386 &src[off], 386 &src[off],
387 c_count, 387 c_count,
388 cd); 388 cd);
389} 389}
390int 390int
391GNUNET_CREDENTIAL_credential_serialize (struct GNUNET_CREDENTIAL_Credential *cred, 391GNUNET_CREDENTIAL_credential_serialize(struct GNUNET_CREDENTIAL_Credential *cred,
392 char **data) 392 char **data)
393{ 393{
394 size_t size; 394 size_t size;
395 struct CredentialEntry *cdata; 395 struct CredentialEntry *cdata;
396 396
397 size = sizeof (struct CredentialEntry) + strlen (cred->issuer_attribute) + 1; 397 size = sizeof(struct CredentialEntry) + strlen(cred->issuer_attribute) + 1;
398 *data = GNUNET_malloc (size); 398 *data = GNUNET_malloc(size);
399 cdata = (struct CredentialEntry*)*data; 399 cdata = (struct CredentialEntry*)*data;
400 cdata->subject_key = cred->subject_key; 400 cdata->subject_key = cred->subject_key;
401 cdata->issuer_key = cred->issuer_key; 401 cdata->issuer_key = cred->issuer_key;
402 cdata->expiration = GNUNET_htonll (cred->expiration.abs_value_us); 402 cdata->expiration = GNUNET_htonll(cred->expiration.abs_value_us);
403 cdata->signature = cred->signature; 403 cdata->signature = cred->signature;
404 cdata->issuer_attribute_len = htonl (strlen (cred->issuer_attribute) + 1); 404 cdata->issuer_attribute_len = htonl(strlen(cred->issuer_attribute) + 1);
405 cdata->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); 405 cdata->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_CREDENTIAL);
406 cdata->purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); 406 cdata->purpose.size = htonl(size - sizeof(struct GNUNET_CRYPTO_EcdsaSignature));
407 GNUNET_memcpy (&cdata[1], 407 GNUNET_memcpy(&cdata[1],
408 cred->issuer_attribute, 408 cred->issuer_attribute,
409 strlen (cred->issuer_attribute)); 409 strlen(cred->issuer_attribute));
410 410
411 if(GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, 411 if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_CREDENTIAL,
412 &cdata->purpose, 412 &cdata->purpose,
413 &cdata->signature, 413 &cdata->signature,
414 &cdata->issuer_key)) 414 &cdata->issuer_key))
415 { 415 {
416 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 416 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
417 "Invalid credential\n"); 417 "Invalid credential\n");
418 //return NULL; 418 //return NULL;
419 } 419 }
420 return size; 420 return size;
421} 421}
422 422
423struct GNUNET_CREDENTIAL_Credential* 423struct GNUNET_CREDENTIAL_Credential*
424GNUNET_CREDENTIAL_credential_deserialize (const char* data, 424GNUNET_CREDENTIAL_credential_deserialize(const char* data,
425 size_t data_size) 425 size_t data_size)
426{ 426{
427 struct GNUNET_CREDENTIAL_Credential *cred; 427 struct GNUNET_CREDENTIAL_Credential *cred;
428 struct CredentialEntry *cdata; 428 struct CredentialEntry *cdata;
429 char *issuer_attribute; 429 char *issuer_attribute;
430 430
431 if (data_size < sizeof (struct CredentialEntry)) 431 if (data_size < sizeof(struct CredentialEntry))
432 return NULL; 432 return NULL;
433 cdata = (struct CredentialEntry*)data; 433 cdata = (struct CredentialEntry*)data;
434 if(GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, 434 if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_CREDENTIAL,
435 &cdata->purpose, 435 &cdata->purpose,
436 &cdata->signature, 436 &cdata->signature,
437 &cdata->issuer_key)) 437 &cdata->issuer_key))
438 { 438 {
439 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 439 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
440 "Invalid credential\n"); 440 "Invalid credential\n");
441 //return NULL; 441 //return NULL;
442 } 442 }
443 issuer_attribute = (char*)&cdata[1]; 443 issuer_attribute = (char*)&cdata[1];
444 444
445 cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + ntohl(cdata->issuer_attribute_len)); 445 cred = GNUNET_malloc(sizeof(struct GNUNET_CREDENTIAL_Credential) + ntohl(cdata->issuer_attribute_len));
446 446
447 cred->issuer_key = cdata->issuer_key; 447 cred->issuer_key = cdata->issuer_key;
448 cred->subject_key = cdata->subject_key; 448 cred->subject_key = cdata->subject_key;
449 GNUNET_memcpy (&cred[1], 449 GNUNET_memcpy(&cred[1],
450 issuer_attribute, 450 issuer_attribute,
451 ntohl (cdata->issuer_attribute_len)); 451 ntohl(cdata->issuer_attribute_len));
452 cred->signature = cdata->signature; 452 cred->signature = cdata->signature;
453 cred->issuer_attribute = (char*)&cred[1]; 453 cred->issuer_attribute = (char*)&cred[1];
454 cred->expiration.abs_value_us = GNUNET_ntohll (cdata->expiration); 454 cred->expiration.abs_value_us = GNUNET_ntohll(cdata->expiration);
455 return cred; 455 return cred;
456} 456}
457 457
diff --git a/src/credential/credential_serialization.h b/src/credential/credential_serialization.h
index 90ec0f56f..426034164 100644
--- a/src/credential/credential_serialization.h
+++ b/src/credential/credential_serialization.h
@@ -11,17 +11,17 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21 21
22/** 22/**
23 * @file credential/credential_serialization.h 23 * @file credential/credential_serialization.h
24 * @brief API to serialize and deserialize delegation chains 24 * @brief API to serialize and deserialize delegation chains
25 * and credentials 25 * and credentials
26 * @author Martin Schanzenbach 26 * @author Martin Schanzenbach
27 */ 27 */
@@ -42,8 +42,8 @@
42 * @return the required size to serialize 42 * @return the required size to serialize
43 */ 43 */
44size_t 44size_t
45GNUNET_CREDENTIAL_delegation_set_get_size (unsigned int ds_count, 45GNUNET_CREDENTIAL_delegation_set_get_size(unsigned int ds_count,
46 const struct GNUNET_CREDENTIAL_DelegationSet *dsr); 46 const struct GNUNET_CREDENTIAL_DelegationSet *dsr);
47 47
48/** 48/**
49 * Serizalize the given delegation record entries 49 * Serizalize the given delegation record entries
@@ -55,10 +55,10 @@ GNUNET_CREDENTIAL_delegation_set_get_size (unsigned int ds_count,
55 * @return the size of the data, -1 on failure 55 * @return the size of the data, -1 on failure
56 */ 56 */
57ssize_t 57ssize_t
58GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count, 58GNUNET_CREDENTIAL_delegation_set_serialize(unsigned int d_count,
59 const struct GNUNET_CREDENTIAL_DelegationSet *dsr, 59 const struct GNUNET_CREDENTIAL_DelegationSet *dsr,
60 size_t dest_size, 60 size_t dest_size,
61 char *dest); 61 char *dest);
62 62
63 63
64/** 64/**
@@ -71,89 +71,89 @@ GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count,
71 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 71 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
72 */ 72 */
73int 73int
74GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len, 74GNUNET_CREDENTIAL_delegation_set_deserialize(size_t len,
75 const char *src, 75 const char *src,
76 unsigned int d_count, 76 unsigned int d_count,
77 struct GNUNET_CREDENTIAL_DelegationSet *dsr); 77 struct GNUNET_CREDENTIAL_DelegationSet *dsr);
78 78
79 /** 79/**
80 * Calculate how many bytes we will need to serialize 80 * Calculate how many bytes we will need to serialize
81 * the given delegation chain and credential 81 * the given delegation chain and credential
82 * 82 *
83 * @param d_count number of delegation chain entries 83 * @param d_count number of delegation chain entries
84 * @param dd array of #GNUNET_CREDENTIAL_Delegation 84 * @param dd array of #GNUNET_CREDENTIAL_Delegation
85 * @param c_count number of credential entries 85 * @param c_count number of credential entries
86 * @param cd a #GNUNET_CREDENTIAL_Credential 86 * @param cd a #GNUNET_CREDENTIAL_Credential
87 * @return the required size to serialize 87 * @return the required size to serialize
88 */ 88 */
89 size_t 89size_t
90 GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count, 90GNUNET_CREDENTIAL_delegation_chain_get_size(unsigned int d_count,
91 const struct GNUNET_CREDENTIAL_Delegation *dd, 91 const struct GNUNET_CREDENTIAL_Delegation *dd,
92 unsigned int c_count, 92 unsigned int c_count,
93 const struct GNUNET_CREDENTIAL_Credential *cd); 93 const struct GNUNET_CREDENTIAL_Credential *cd);
94 94
95 /** 95/**
96 * Serizalize the given delegation chain entries and credential 96 * Serizalize the given delegation chain entries and credential
97 * 97 *
98 * @param d_count number of delegation chain entries 98 * @param d_count number of delegation chain entries
99 * @param dd array of #GNUNET_CREDENTIAL_Delegation 99 * @param dd array of #GNUNET_CREDENTIAL_Delegation
100 * @param c_count number of credential entries 100 * @param c_count number of credential entries
101 * @param cd a #GNUNET_CREDENTIAL_Credential 101 * @param cd a #GNUNET_CREDENTIAL_Credential
102 * @param dest_size size of the destination 102 * @param dest_size size of the destination
103 * @param dest where to store the result 103 * @param dest where to store the result
104 * @return the size of the data, -1 on failure 104 * @return the size of the data, -1 on failure
105 */ 105 */
106 ssize_t 106ssize_t
107 GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count, 107GNUNET_CREDENTIAL_delegation_chain_serialize(unsigned int d_count,
108 const struct GNUNET_CREDENTIAL_Delegation *dd, 108 const struct GNUNET_CREDENTIAL_Delegation *dd,
109 unsigned int c_count, 109 unsigned int c_count,
110 const struct GNUNET_CREDENTIAL_Credential *cd, 110 const struct GNUNET_CREDENTIAL_Credential *cd,
111 size_t dest_size, 111 size_t dest_size,
112 char *dest); 112 char *dest);
113 113
114 114
115 /** 115/**
116 * Deserialize the given destination 116 * Deserialize the given destination
117 * 117 *
118 * @param len size of the serialized delegation chain and cred 118 * @param len size of the serialized delegation chain and cred
119 * @param src the serialized data 119 * @param src the serialized data
120 * @param d_count the number of delegation chain entries 120 * @param d_count the number of delegation chain entries
121 * @param dd where to put the delegation chain entries 121 * @param dd where to put the delegation chain entries
122 * @param c_count number of credential entries 122 * @param c_count number of credential entries
123 * @param cd where to put the credential data 123 * @param cd where to put the credential data
124 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 124 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
125 */ 125 */
126 int 126int
127 GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len, 127GNUNET_CREDENTIAL_delegation_chain_deserialize(size_t len,
128 const char *src, 128 const char *src,
129 unsigned int d_count, 129 unsigned int d_count,
130 struct GNUNET_CREDENTIAL_Delegation *dd, 130 struct GNUNET_CREDENTIAL_Delegation *dd,
131 unsigned int c_count, 131 unsigned int c_count,
132 struct GNUNET_CREDENTIAL_Credential *cd); 132 struct GNUNET_CREDENTIAL_Credential *cd);
133 size_t 133size_t
134 GNUNET_CREDENTIAL_credentials_get_size (unsigned int c_count, 134GNUNET_CREDENTIAL_credentials_get_size(unsigned int c_count,
135 const struct GNUNET_CREDENTIAL_Credential *cd); 135 const struct GNUNET_CREDENTIAL_Credential *cd);
136 136
137ssize_t 137ssize_t
138GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, 138GNUNET_CREDENTIAL_credentials_serialize(unsigned int c_count,
139 const struct GNUNET_CREDENTIAL_Credential *cd, 139 const struct GNUNET_CREDENTIAL_Credential *cd,
140 size_t dest_size, 140 size_t dest_size,
141 char *dest); 141 char *dest);
142 142
143 143
144int 144int
145GNUNET_CREDENTIAL_credentials_deserialize (size_t len, 145GNUNET_CREDENTIAL_credentials_deserialize(size_t len,
146 const char *src, 146 const char *src,
147 unsigned int c_count, 147 unsigned int c_count,
148 struct GNUNET_CREDENTIAL_Credential *cd); 148 struct GNUNET_CREDENTIAL_Credential *cd);
149 149
150 150
151int 151int
152GNUNET_CREDENTIAL_credential_serialize (struct GNUNET_CREDENTIAL_Credential *cred, 152GNUNET_CREDENTIAL_credential_serialize(struct GNUNET_CREDENTIAL_Credential *cred,
153 char **data); 153 char **data);
154 154
155struct GNUNET_CREDENTIAL_Credential* 155struct GNUNET_CREDENTIAL_Credential*
156GNUNET_CREDENTIAL_credential_deserialize (const char* data, 156GNUNET_CREDENTIAL_credential_deserialize(const char* data,
157 size_t data_size); 157 size_t data_size);
158#endif 158#endif
159/* end of credential_serialization.h */ 159/* end of credential_serialization.h */
diff --git a/src/credential/gnunet-credential.c b/src/credential/gnunet-credential.c
index 7873e4230..415525e9a 100644
--- a/src/credential/gnunet-credential.c
+++ b/src/credential/gnunet-credential.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file gnunet-credential.c 21 * @file gnunet-credential.c
22 * @brief command line tool to access command line Credential service 22 * @brief command line tool to access command line Credential service
@@ -126,23 +126,23 @@ static int collect;
126 * @param cls unused 126 * @param cls unused
127 */ 127 */
128static void 128static void
129do_shutdown (void *cls) 129do_shutdown(void *cls)
130{ 130{
131 if (NULL != verify_request) 131 if (NULL != verify_request)
132 { 132 {
133 GNUNET_CREDENTIAL_request_cancel (verify_request); 133 GNUNET_CREDENTIAL_request_cancel(verify_request);
134 verify_request = NULL; 134 verify_request = NULL;
135 } 135 }
136 if (NULL != credential) 136 if (NULL != credential)
137 { 137 {
138 GNUNET_CREDENTIAL_disconnect (credential); 138 GNUNET_CREDENTIAL_disconnect(credential);
139 credential = NULL; 139 credential = NULL;
140 } 140 }
141 if (NULL != tt) 141 if (NULL != tt)
142 { 142 {
143 GNUNET_SCHEDULER_cancel (tt); 143 GNUNET_SCHEDULER_cancel(tt);
144 tt = NULL; 144 tt = NULL;
145 } 145 }
146} 146}
147 147
148 148
@@ -152,14 +152,14 @@ do_shutdown (void *cls)
152 * @param cls unused 152 * @param cls unused
153 */ 153 */
154static void 154static void
155do_timeout (void *cls) 155do_timeout(void *cls)
156{ 156{
157 tt = NULL; 157 tt = NULL;
158 GNUNET_SCHEDULER_shutdown (); 158 GNUNET_SCHEDULER_shutdown();
159} 159}
160 160
161static void 161static void
162handle_collect_result (void *cls, 162handle_collect_result(void *cls,
163 unsigned int d_count, 163 unsigned int d_count,
164 struct GNUNET_CREDENTIAL_Delegation *dc, 164 struct GNUNET_CREDENTIAL_Delegation *dc,
165 unsigned int c_count, 165 unsigned int c_count,
@@ -170,27 +170,27 @@ handle_collect_result (void *cls,
170 170
171 verify_request = NULL; 171 verify_request = NULL;
172 if (NULL != cred) 172 if (NULL != cred)
173 {
174 for (i=0;i<c_count;i++)
175 { 173 {
176 line = GNUNET_CREDENTIAL_credential_to_string (&cred[i]); 174 for (i = 0; i < c_count; i++)
177 printf ("%s\n", 175 {
178 line); 176 line = GNUNET_CREDENTIAL_credential_to_string(&cred[i]);
179 GNUNET_free (line); 177 printf("%s\n",
178 line);
179 GNUNET_free(line);
180 }
180 } 181 }
181 }
182 182
183 183
184 GNUNET_SCHEDULER_shutdown (); 184 GNUNET_SCHEDULER_shutdown();
185} 185}
186 186
187 187
188static void 188static void
189handle_verify_result (void *cls, 189handle_verify_result(void *cls,
190 unsigned int d_count, 190 unsigned int d_count,
191 struct GNUNET_CREDENTIAL_Delegation *dc, 191 struct GNUNET_CREDENTIAL_Delegation *dc,
192 unsigned int c_count, 192 unsigned int c_count,
193 struct GNUNET_CREDENTIAL_Credential *cred) 193 struct GNUNET_CREDENTIAL_Credential *cred)
194{ 194{
195 int i; 195 int i;
196 char* iss_key; 196 char* iss_key;
@@ -198,44 +198,45 @@ handle_verify_result (void *cls,
198 198
199 verify_request = NULL; 199 verify_request = NULL;
200 if (NULL == cred) 200 if (NULL == cred)
201 printf ("Failed.\n"); 201 printf("Failed.\n");
202 else 202 else
203 {
204 printf("Delegation Chain:\n");
205 for (i=0;i<d_count;i++)
206 { 203 {
207 iss_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&dc[i].issuer_key); 204 printf("Delegation Chain:\n");
208 sub_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&dc[i].subject_key); 205 for (i = 0; i < d_count; i++)
209 if (0 != dc[i].subject_attribute_len) 206 {
210 { 207 iss_key = GNUNET_CRYPTO_ecdsa_public_key_to_string(&dc[i].issuer_key);
211 printf ("(%d) %s.%s <- %s.%s\n", i, 208 sub_key = GNUNET_CRYPTO_ecdsa_public_key_to_string(&dc[i].subject_key);
212 iss_key, dc[i].issuer_attribute, 209 if (0 != dc[i].subject_attribute_len)
213 sub_key, dc[i].subject_attribute); 210 {
214 } else { 211 printf("(%d) %s.%s <- %s.%s\n", i,
215 printf ("(%d) %s.%s <- %s\n", i, 212 iss_key, dc[i].issuer_attribute,
216 iss_key, dc[i].issuer_attribute, 213 sub_key, dc[i].subject_attribute);
217 sub_key); 214 }
218 } 215 else
219 GNUNET_free (iss_key); 216 {
220 GNUNET_free (sub_key); 217 printf("(%d) %s.%s <- %s\n", i,
218 iss_key, dc[i].issuer_attribute,
219 sub_key);
220 }
221 GNUNET_free(iss_key);
222 GNUNET_free(sub_key);
223 }
224 printf("\nCredentials:\n");
225 for (i = 0; i < c_count; i++)
226 {
227 iss_key = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred[i].issuer_key);
228 sub_key = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred[i].subject_key);
229 printf("%s.%s <- %s\n",
230 iss_key, cred[i].issuer_attribute,
231 sub_key);
232 GNUNET_free(iss_key);
233 GNUNET_free(sub_key);
234 }
235 printf("Successful.\n");
221 } 236 }
222 printf("\nCredentials:\n");
223 for (i=0;i<c_count;i++)
224 {
225 iss_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred[i].issuer_key);
226 sub_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred[i].subject_key);
227 printf ("%s.%s <- %s\n",
228 iss_key, cred[i].issuer_attribute,
229 sub_key);
230 GNUNET_free (iss_key);
231 GNUNET_free (sub_key);
232 237
233 }
234 printf ("Successful.\n");
235 }
236 238
237 239 GNUNET_SCHEDULER_shutdown();
238 GNUNET_SCHEDULER_shutdown ();
239} 240}
240 241
241/** 242/**
@@ -246,8 +247,8 @@ handle_verify_result (void *cls,
246 * @param ego an ego known to identity service, or NULL 247 * @param ego an ego known to identity service, or NULL
247 */ 248 */
248static void 249static void
249identity_cb (void *cls, 250identity_cb(void *cls,
250 const struct GNUNET_IDENTITY_Ego *ego) 251 const struct GNUNET_IDENTITY_Ego *ego)
251{ 252{
252 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; 253 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
253 struct GNUNET_CREDENTIAL_Credential *crd; 254 struct GNUNET_CREDENTIAL_Credential *crd;
@@ -257,76 +258,77 @@ identity_cb (void *cls,
257 258
258 el = NULL; 259 el = NULL;
259 if (NULL == ego) 260 if (NULL == ego)
260 {
261 if (NULL != ego_name)
262 { 261 {
263 fprintf (stderr, 262 if (NULL != ego_name)
264 _("Ego `%s' not known to identity service\n"), 263 {
265 ego_name); 264 fprintf(stderr,
265 _("Ego `%s' not known to identity service\n"),
266 ego_name);
267 }
268 GNUNET_SCHEDULER_shutdown();
269 return;
266 } 270 }
267 GNUNET_SCHEDULER_shutdown ();
268 return;
269 }
270 271
271 if (GNUNET_YES == collect) 272 if (GNUNET_YES == collect)
272 {
273
274 if (GNUNET_OK !=
275 GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_key,
276 strlen (issuer_key),
277 &issuer_pkey))
278 { 273 {
279 fprintf (stderr, 274 if (GNUNET_OK !=
280 _("Issuer public key `%s' is not well-formed\n"), 275 GNUNET_CRYPTO_ecdsa_public_key_from_string(issuer_key,
281 issuer_key); 276 strlen(issuer_key),
282 GNUNET_SCHEDULER_shutdown (); 277 &issuer_pkey))
278 {
279 fprintf(stderr,
280 _("Issuer public key `%s' is not well-formed\n"),
281 issuer_key);
282 GNUNET_SCHEDULER_shutdown();
283 }
284 privkey = GNUNET_IDENTITY_ego_get_private_key(ego);
285
286 collect_request = GNUNET_CREDENTIAL_collect(credential,
287 &issuer_pkey,
288 issuer_attr, //TODO argument
289 privkey,
290 &handle_collect_result,
291 NULL);
292 return;
283 } 293 }
284 privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
285
286 collect_request = GNUNET_CREDENTIAL_collect(credential,
287 &issuer_pkey,
288 issuer_attr, //TODO argument
289 privkey,
290 &handle_collect_result,
291 NULL);
292 return;
293 }
294 294
295 //Else issue 295 //Else issue
296 296
297 if (NULL == expiration) 297 if (NULL == expiration)
298 { 298 {
299 fprintf (stderr, 299 fprintf(stderr,
300 "Please specify a TTL\n"); 300 "Please specify a TTL\n");
301 GNUNET_SCHEDULER_shutdown (); 301 GNUNET_SCHEDULER_shutdown();
302 return; 302 return;
303 } else if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative (expiration, 303 }
304 &etime_rel)) 304 else if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative(expiration,
305 { 305 &etime_rel))
306 etime_abs = GNUNET_TIME_relative_to_absolute (etime_rel); 306 {
307 } else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (expiration, 307 etime_abs = GNUNET_TIME_relative_to_absolute(etime_rel);
308 &etime_abs)) 308 }
309 { 309 else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute(expiration,
310 fprintf (stderr, 310 &etime_abs))
311 "%s is not a valid ttl!\n", 311 {
312 expiration); 312 fprintf(stderr,
313 GNUNET_SCHEDULER_shutdown (); 313 "%s is not a valid ttl!\n",
314 return; 314 expiration);
315 } 315 GNUNET_SCHEDULER_shutdown();
316 316 return;
317 317 }
318 privkey = GNUNET_IDENTITY_ego_get_private_key (ego); 318
319 GNUNET_free_non_null (ego_name); 319
320 privkey = GNUNET_IDENTITY_ego_get_private_key(ego);
321 GNUNET_free_non_null(ego_name);
320 ego_name = NULL; 322 ego_name = NULL;
321 crd = GNUNET_CREDENTIAL_credential_issue (privkey, 323 crd = GNUNET_CREDENTIAL_credential_issue(privkey,
322 &subject_pkey, 324 &subject_pkey,
323 issuer_attr, 325 issuer_attr,
324 &etime_abs); 326 &etime_abs);
325 327
326 res = GNUNET_CREDENTIAL_credential_to_string (crd); 328 res = GNUNET_CREDENTIAL_credential_to_string(crd);
327 GNUNET_free (crd); 329 GNUNET_free(crd);
328 printf ("%s\n", res); 330 printf("%s\n", res);
329 GNUNET_SCHEDULER_shutdown (); 331 GNUNET_SCHEDULER_shutdown();
330} 332}
331 333
332 334
@@ -341,181 +343,180 @@ identity_cb (void *cls,
341 * @param c configuration 343 * @param c configuration
342 */ 344 */
343static void 345static void
344run (void *cls, 346run(void *cls,
345 char *const *args, 347 char *const *args,
346 const char *cfgfile, 348 const char *cfgfile,
347 const struct GNUNET_CONFIGURATION_Handle *c) 349 const struct GNUNET_CONFIGURATION_Handle *c)
348{ 350{
349
350 cfg = c; 351 cfg = c;
351 352
352 353
353 tt = GNUNET_SCHEDULER_add_delayed (timeout, 354 tt = GNUNET_SCHEDULER_add_delayed(timeout,
354 &do_timeout, NULL); 355 &do_timeout, NULL);
355 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 356 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
356
357 if (GNUNET_YES == collect) {
358 if (NULL == issuer_key)
359 {
360 fprintf (stderr,
361 _("Issuer public key not well-formed\n"));
362 GNUNET_SCHEDULER_shutdown ();
363 return;
364 357
365 } 358 if (GNUNET_YES == collect)
366
367 credential = GNUNET_CREDENTIAL_connect (cfg);
368
369 if (NULL == credential)
370 {
371 fprintf (stderr,
372 _("Failed to connect to CREDENTIAL\n"));
373 GNUNET_SCHEDULER_shutdown ();
374 return;
375 }
376 if (NULL == issuer_attr)
377 {
378 fprintf (stderr,
379 _("You must provide issuer the attribute\n"));
380 GNUNET_SCHEDULER_shutdown ();
381 return;
382 }
383
384 if (NULL == ego_name)
385 { 359 {
386 fprintf (stderr, 360 if (NULL == issuer_key)
387 _("ego required\n")); 361 {
388 GNUNET_SCHEDULER_shutdown (); 362 fprintf(stderr,
363 _("Issuer public key not well-formed\n"));
364 GNUNET_SCHEDULER_shutdown();
365 return;
366 }
367
368 credential = GNUNET_CREDENTIAL_connect(cfg);
369
370 if (NULL == credential)
371 {
372 fprintf(stderr,
373 _("Failed to connect to CREDENTIAL\n"));
374 GNUNET_SCHEDULER_shutdown();
375 return;
376 }
377 if (NULL == issuer_attr)
378 {
379 fprintf(stderr,
380 _("You must provide issuer the attribute\n"));
381 GNUNET_SCHEDULER_shutdown();
382 return;
383 }
384
385 if (NULL == ego_name)
386 {
387 fprintf(stderr,
388 _("ego required\n"));
389 GNUNET_SCHEDULER_shutdown();
390 return;
391 }
392 el = GNUNET_IDENTITY_ego_lookup(cfg,
393 ego_name,
394 &identity_cb,
395 (void *)cfg);
389 return; 396 return;
390
391 } 397 }
392 el = GNUNET_IDENTITY_ego_lookup (cfg,
393 ego_name,
394 &identity_cb,
395 (void *) cfg);
396 return;
397
398 }
399 398
400 if (NULL == subject_key) 399 if (NULL == subject_key)
401 {
402 fprintf (stderr,
403 _("Subject public key needed\n"));
404 GNUNET_SCHEDULER_shutdown ();
405 return;
406
407 }
408 if (GNUNET_OK !=
409 GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_key,
410 strlen (subject_key),
411 &subject_pkey))
412 {
413 fprintf (stderr,
414 _("Subject public key `%s' is not well-formed\n"),
415 subject_key);
416 GNUNET_SCHEDULER_shutdown ();
417 return;
418 }
419 if (GNUNET_YES == verify) {
420 if (NULL == issuer_key)
421 {
422 fprintf (stderr,
423 _("Issuer public key not well-formed\n"));
424 GNUNET_SCHEDULER_shutdown ();
425 return;
426
427 }
428 if (GNUNET_OK !=
429 GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_key,
430 strlen (issuer_key),
431 &issuer_pkey))
432 { 400 {
433 fprintf (stderr, 401 fprintf(stderr,
434 _("Issuer public key `%s' is not well-formed\n"), 402 _("Subject public key needed\n"));
435 issuer_key); 403 GNUNET_SCHEDULER_shutdown();
436 GNUNET_SCHEDULER_shutdown ();
437 return; 404 return;
438 } 405 }
439 credential = GNUNET_CREDENTIAL_connect (cfg); 406 if (GNUNET_OK !=
440 407 GNUNET_CRYPTO_ecdsa_public_key_from_string(subject_key,
441 if (NULL == credential) 408 strlen(subject_key),
409 &subject_pkey))
442 { 410 {
443 fprintf (stderr, 411 fprintf(stderr,
444 _("Failed to connect to CREDENTIAL\n")); 412 _("Subject public key `%s' is not well-formed\n"),
445 GNUNET_SCHEDULER_shutdown (); 413 subject_key);
414 GNUNET_SCHEDULER_shutdown();
446 return; 415 return;
447 } 416 }
448 if (NULL == issuer_attr || NULL == subject_credential) 417 if (GNUNET_YES == verify)
449 { 418 {
450 fprintf (stderr, 419 if (NULL == issuer_key)
451 _("You must provide issuer and subject attributes\n")); 420 {
452 GNUNET_SCHEDULER_shutdown (); 421 fprintf(stderr,
453 return; 422 _("Issuer public key not well-formed\n"));
423 GNUNET_SCHEDULER_shutdown();
424 return;
425 }
426 if (GNUNET_OK !=
427 GNUNET_CRYPTO_ecdsa_public_key_from_string(issuer_key,
428 strlen(issuer_key),
429 &issuer_pkey))
430 {
431 fprintf(stderr,
432 _("Issuer public key `%s' is not well-formed\n"),
433 issuer_key);
434 GNUNET_SCHEDULER_shutdown();
435 return;
436 }
437 credential = GNUNET_CREDENTIAL_connect(cfg);
438
439 if (NULL == credential)
440 {
441 fprintf(stderr,
442 _("Failed to connect to CREDENTIAL\n"));
443 GNUNET_SCHEDULER_shutdown();
444 return;
445 }
446 if (NULL == issuer_attr || NULL == subject_credential)
447 {
448 fprintf(stderr,
449 _("You must provide issuer and subject attributes\n"));
450 GNUNET_SCHEDULER_shutdown();
451 return;
452 }
453
454 //Subject credentials are comma separated
455 char *tmp = GNUNET_strdup(subject_credential);
456 char *tok = strtok(tmp, ",");
457 if (NULL == tok)
458 {
459 fprintf(stderr,
460 "Invalid subject credentials\n");
461 GNUNET_free(tmp);
462 GNUNET_SCHEDULER_shutdown();
463 return;
464 }
465 int count = 1;
466 int i;
467 while (NULL != (tok = strtok(NULL, ",")))
468 count++;
469 struct GNUNET_CREDENTIAL_Credential credentials[count];
470 struct GNUNET_CREDENTIAL_Credential *cred;
471 GNUNET_free(tmp);
472 tmp = GNUNET_strdup(subject_credential);
473 tok = strtok(tmp, ",");
474 for (i = 0; i < count; i++)
475 {
476 cred = GNUNET_CREDENTIAL_credential_from_string(tok);
477 GNUNET_memcpy(&credentials[i],
478 cred,
479 sizeof(struct GNUNET_CREDENTIAL_Credential));
480 credentials[i].issuer_attribute = GNUNET_strdup(cred->issuer_attribute);
481 tok = strtok(NULL, ",");
482 GNUNET_free(cred);
483 }
484
485 verify_request = GNUNET_CREDENTIAL_verify(credential,
486 &issuer_pkey,
487 issuer_attr, //TODO argument
488 &subject_pkey,
489 count,
490 credentials,
491 &handle_verify_result,
492 NULL);
493 for (i = 0; i < count; i++)
494 {
495 GNUNET_free((char*)credentials[i].issuer_attribute);
496 }
497 GNUNET_free(tmp);
454 } 498 }
455 499 else if (GNUNET_YES == create_cred)
456 //Subject credentials are comma separated
457 char *tmp = GNUNET_strdup (subject_credential);
458 char *tok = strtok (tmp, ",");
459 if (NULL == tok)
460 { 500 {
461 fprintf (stderr, 501 if (NULL == ego_name)
462 "Invalid subject credentials\n"); 502 {
463 GNUNET_free (tmp); 503 fprintf(stderr,
464 GNUNET_SCHEDULER_shutdown (); 504 _("Issuer ego required\n"));
505 GNUNET_SCHEDULER_shutdown();
506 return;
507 }
508 el = GNUNET_IDENTITY_ego_lookup(cfg,
509 ego_name,
510 &identity_cb,
511 (void *)cfg);
465 return; 512 return;
466 } 513 }
467 int count = 1; 514 else
468 int i;
469 while (NULL != (tok = strtok(NULL, ",")))
470 count++;
471 struct GNUNET_CREDENTIAL_Credential credentials[count];
472 struct GNUNET_CREDENTIAL_Credential *cred;
473 GNUNET_free (tmp);
474 tmp = GNUNET_strdup (subject_credential);
475 tok = strtok (tmp, ",");
476 for (i=0;i<count;i++)
477 {
478 cred = GNUNET_CREDENTIAL_credential_from_string (tok);
479 GNUNET_memcpy (&credentials[i],
480 cred,
481 sizeof (struct GNUNET_CREDENTIAL_Credential));
482 credentials[i].issuer_attribute = GNUNET_strdup (cred->issuer_attribute);
483 tok = strtok(NULL, ",");
484 GNUNET_free (cred);
485 }
486
487 verify_request = GNUNET_CREDENTIAL_verify(credential,
488 &issuer_pkey,
489 issuer_attr, //TODO argument
490 &subject_pkey,
491 count,
492 credentials,
493 &handle_verify_result,
494 NULL);
495 for (i=0;i<count;i++)
496 {
497 GNUNET_free ((char*)credentials[i].issuer_attribute);
498 }
499 GNUNET_free (tmp);
500 } else if (GNUNET_YES == create_cred) {
501 if (NULL == ego_name)
502 { 515 {
503 fprintf (stderr, 516 fprintf(stderr,
504 _("Issuer ego required\n")); 517 _("Please specify name to lookup, subject key and issuer key!\n"));
505 GNUNET_SCHEDULER_shutdown (); 518 GNUNET_SCHEDULER_shutdown();
506 return;
507
508 } 519 }
509 el = GNUNET_IDENTITY_ego_lookup (cfg,
510 ego_name,
511 &identity_cb,
512 (void *) cfg);
513 return;
514 } else {
515 fprintf (stderr,
516 _("Please specify name to lookup, subject key and issuer key!\n"));
517 GNUNET_SCHEDULER_shutdown ();
518 }
519 return; 520 return;
520} 521}
521 522
@@ -528,67 +529,67 @@ run (void *cls,
528 * @return 0 ok, 1 on error 529 * @return 0 ok, 1 on error
529 */ 530 */
530int 531int
531main (int argc, char *const *argv) 532main(int argc, char *const *argv)
532{ 533{
533 struct GNUNET_GETOPT_CommandLineOption options[] = { 534 struct GNUNET_GETOPT_CommandLineOption options[] = {
534 GNUNET_GETOPT_option_flag ('I', 535 GNUNET_GETOPT_option_flag('I',
535 "issue", 536 "issue",
536 gettext_noop ("create credential"), 537 gettext_noop("create credential"),
537 &create_cred), 538 &create_cred),
538 GNUNET_GETOPT_option_flag ('V', 539 GNUNET_GETOPT_option_flag('V',
539 "verify", 540 "verify",
540 gettext_noop ("verify credential against attribute"), 541 gettext_noop("verify credential against attribute"),
541 &verify), 542 &verify),
542 GNUNET_GETOPT_option_string ('s', 543 GNUNET_GETOPT_option_string('s',
543 "subject", 544 "subject",
544 "PKEY", 545 "PKEY",
545 gettext_noop ("The public key of the subject to lookup the credential for"), 546 gettext_noop("The public key of the subject to lookup the credential for"),
546 &subject_key), 547 &subject_key),
547 GNUNET_GETOPT_option_string ('b', 548 GNUNET_GETOPT_option_string('b',
548 "credential", 549 "credential",
549 "CRED", 550 "CRED",
550 gettext_noop ("The name of the credential presented by the subject"), 551 gettext_noop("The name of the credential presented by the subject"),
551 &subject_credential), 552 &subject_credential),
552 GNUNET_GETOPT_option_string ('i', 553 GNUNET_GETOPT_option_string('i',
553 "issuer", 554 "issuer",
554 "PKEY", 555 "PKEY",
555 gettext_noop ("The public key of the authority to verify the credential against"), 556 gettext_noop("The public key of the authority to verify the credential against"),
556 &issuer_key), 557 &issuer_key),
557 GNUNET_GETOPT_option_string ('e', 558 GNUNET_GETOPT_option_string('e',
558 "ego", 559 "ego",
559 "EGO", 560 "EGO",
560 gettext_noop ("The ego to use"), 561 gettext_noop("The ego to use"),
561 &ego_name), 562 &ego_name),
562 GNUNET_GETOPT_option_string ('a', 563 GNUNET_GETOPT_option_string('a',
563 "attribute", 564 "attribute",
564 "ATTR", 565 "ATTR",
565 gettext_noop ("The issuer attribute to verify against or to issue"), 566 gettext_noop("The issuer attribute to verify against or to issue"),
566 &issuer_attr), 567 &issuer_attr),
567 GNUNET_GETOPT_option_string ('T', 568 GNUNET_GETOPT_option_string('T',
568 "ttl", 569 "ttl",
569 "EXP", 570 "EXP",
570 gettext_noop ("The time to live for the credential"), 571 gettext_noop("The time to live for the credential"),
571 &expiration), 572 &expiration),
572 GNUNET_GETOPT_option_flag ('g', 573 GNUNET_GETOPT_option_flag('g',
573 "collect", 574 "collect",
574 gettext_noop ("collect credentials"), 575 gettext_noop("collect credentials"),
575 &collect), 576 &collect),
576 GNUNET_GETOPT_OPTION_END 577 GNUNET_GETOPT_OPTION_END
577 }; 578 };
578 int ret; 579 int ret;
579 580
580 timeout = GNUNET_TIME_UNIT_FOREVER_REL; 581 timeout = GNUNET_TIME_UNIT_FOREVER_REL;
581 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 582 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
582 return 2; 583 return 2;
583 584
584 GNUNET_log_setup ("gnunet-credential", "WARNING", NULL); 585 GNUNET_log_setup("gnunet-credential", "WARNING", NULL);
585 ret = 586 ret =
586 (GNUNET_OK == 587 (GNUNET_OK ==
587 GNUNET_PROGRAM_run (argc, argv, "gnunet-credential", 588 GNUNET_PROGRAM_run(argc, argv, "gnunet-credential",
588 _("GNUnet credential resolver tool"), 589 _("GNUnet credential resolver tool"),
589 options, 590 options,
590 &run, NULL)) ? 0 : 1; 591 &run, NULL)) ? 0 : 1;
591 GNUNET_free ((void*) argv); 592 GNUNET_free((void*)argv);
592 return ret; 593 return ret;
593} 594}
594 595
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c
index 75711265d..4c001af1b 100644
--- a/src/credential/gnunet-service-credential.c
+++ b/src/credential/gnunet-service-credential.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file credential/gnunet-service-credential.c 21 * @file credential/gnunet-service-credential.c
22 * @brief GNUnet Credential Service (main service) 22 * @brief GNUnet Credential Service (main service)
@@ -46,8 +46,7 @@ struct VerifyRequestHandle;
46struct DelegationSetQueueEntry; 46struct DelegationSetQueueEntry;
47 47
48 48
49struct DelegationChainEntry 49struct DelegationChainEntry {
50{
51 /** 50 /**
52 * DLL 51 * DLL
53 */ 52 */
@@ -82,8 +81,7 @@ struct DelegationChainEntry
82/** 81/**
83 * DLL for record 82 * DLL for record
84 */ 83 */
85struct CredentialRecordEntry 84struct CredentialRecordEntry {
86{
87 /** 85 /**
88 * DLL 86 * DLL
89 */ 87 */
@@ -109,8 +107,7 @@ struct CredentialRecordEntry
109 * DLL used for delegations 107 * DLL used for delegations
110 * Used for OR delegations 108 * Used for OR delegations
111 */ 109 */
112struct DelegationQueueEntry 110struct DelegationQueueEntry {
113{
114 /** 111 /**
115 * DLL 112 * DLL
116 */ 113 */
@@ -146,8 +143,7 @@ struct DelegationQueueEntry
146 * DLL for delegation sets 143 * DLL for delegation sets
147 * Used for AND delegation set 144 * Used for AND delegation set
148 */ 145 */
149struct DelegationSetQueueEntry 146struct DelegationSetQueueEntry {
150{
151 /** 147 /**
152 * DLL 148 * DLL
153 */ 149 */
@@ -223,9 +219,7 @@ struct DelegationSetQueueEntry
223/** 219/**
224 * Handle to a lookup operation from api 220 * Handle to a lookup operation from api
225 */ 221 */
226struct VerifyRequestHandle 222struct VerifyRequestHandle {
227{
228
229 /** 223 /**
230 * We keep these in a DLL. 224 * We keep these in a DLL.
231 */ 225 */
@@ -350,7 +344,7 @@ static struct GNUNET_GNS_Handle *gns;
350static struct GNUNET_NAMESTORE_Handle *namestore; 344static struct GNUNET_NAMESTORE_Handle *namestore;
351 345
352static void 346static void
353cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry) 347cleanup_delegation_set(struct DelegationSetQueueEntry *ds_entry)
354{ 348{
355 struct DelegationQueueEntry *dq_entry; 349 struct DelegationQueueEntry *dq_entry;
356 struct DelegationSetQueueEntry *child; 350 struct DelegationSetQueueEntry *child;
@@ -359,88 +353,99 @@ cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry)
359 return; 353 return;
360 354
361 for (dq_entry = ds_entry->queue_entries_head; NULL != dq_entry; 355 for (dq_entry = ds_entry->queue_entries_head; NULL != dq_entry;
362 dq_entry = ds_entry->queue_entries_head) { 356 dq_entry = ds_entry->queue_entries_head)
363 GNUNET_CONTAINER_DLL_remove (ds_entry->queue_entries_head, 357 {
364 ds_entry->queue_entries_tail, 358 GNUNET_CONTAINER_DLL_remove(ds_entry->queue_entries_head,
365 dq_entry); 359 ds_entry->queue_entries_tail,
366 for (child = dq_entry->set_entries_head; NULL != child; 360 dq_entry);
367 child = dq_entry->set_entries_head) { 361 for (child = dq_entry->set_entries_head; NULL != child;
368 GNUNET_CONTAINER_DLL_remove (dq_entry->set_entries_head, 362 child = dq_entry->set_entries_head)
369 dq_entry->set_entries_tail, 363 {
370 child); 364 GNUNET_CONTAINER_DLL_remove(dq_entry->set_entries_head,
371 cleanup_delegation_set (child); 365 dq_entry->set_entries_tail,
366 child);
367 cleanup_delegation_set(child);
368 }
369 GNUNET_free(dq_entry);
370 }
371 GNUNET_free_non_null(ds_entry->issuer_key);
372 GNUNET_free_non_null(ds_entry->lookup_attribute);
373 GNUNET_free_non_null(ds_entry->issuer_attribute);
374 GNUNET_free_non_null(ds_entry->unresolved_attribute_delegation);
375 GNUNET_free_non_null(ds_entry->attr_trailer);
376 if (NULL != ds_entry->lookup_request)
377 {
378 GNUNET_GNS_lookup_cancel(ds_entry->lookup_request);
379 ds_entry->lookup_request = NULL;
372 } 380 }
373 GNUNET_free (dq_entry); 381 if (NULL != ds_entry->delegation_chain_entry)
374 } 382 {
375 GNUNET_free_non_null (ds_entry->issuer_key); 383 GNUNET_free_non_null(ds_entry->delegation_chain_entry->subject_attribute);
376 GNUNET_free_non_null (ds_entry->lookup_attribute); 384 GNUNET_free_non_null(ds_entry->delegation_chain_entry->issuer_attribute);
377 GNUNET_free_non_null (ds_entry->issuer_attribute); 385 GNUNET_free(ds_entry->delegation_chain_entry);
378 GNUNET_free_non_null (ds_entry->unresolved_attribute_delegation); 386 }
379 GNUNET_free_non_null (ds_entry->attr_trailer); 387 GNUNET_free(ds_entry);
380 if (NULL != ds_entry->lookup_request) {
381 GNUNET_GNS_lookup_cancel (ds_entry->lookup_request);
382 ds_entry->lookup_request = NULL;
383 }
384 if (NULL != ds_entry->delegation_chain_entry) {
385 GNUNET_free_non_null (ds_entry->delegation_chain_entry->subject_attribute);
386 GNUNET_free_non_null (ds_entry->delegation_chain_entry->issuer_attribute);
387 GNUNET_free (ds_entry->delegation_chain_entry);
388 }
389 GNUNET_free (ds_entry);
390} 388}
391 389
392static void 390static void
393cleanup_handle (struct VerifyRequestHandle *vrh) 391cleanup_handle(struct VerifyRequestHandle *vrh)
394{ 392{
395 struct CredentialRecordEntry *cr_entry; 393 struct CredentialRecordEntry *cr_entry;
396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up...\n"); 394
397 if (NULL != vrh->lookup_request) { 395 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up...\n");
398 GNUNET_GNS_lookup_cancel (vrh->lookup_request); 396 if (NULL != vrh->lookup_request)
399 vrh->lookup_request = NULL; 397 {
400 } 398 GNUNET_GNS_lookup_cancel(vrh->lookup_request);
401 cleanup_delegation_set (vrh->root_set); 399 vrh->lookup_request = NULL;
402 GNUNET_free_non_null (vrh->issuer_attribute); 400 }
401 cleanup_delegation_set(vrh->root_set);
402 GNUNET_free_non_null(vrh->issuer_attribute);
403 for (cr_entry = vrh->cred_chain_head; NULL != vrh->cred_chain_head; 403 for (cr_entry = vrh->cred_chain_head; NULL != vrh->cred_chain_head;
404 cr_entry = vrh->cred_chain_head) { 404 cr_entry = vrh->cred_chain_head)
405 GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head, 405 {
406 vrh->cred_chain_tail, 406 GNUNET_CONTAINER_DLL_remove(vrh->cred_chain_head,
407 cr_entry); 407 vrh->cred_chain_tail,
408 GNUNET_free_non_null (cr_entry->credential); 408 cr_entry);
409 GNUNET_free (cr_entry); 409 GNUNET_free_non_null(cr_entry->credential);
410 } 410 GNUNET_free(cr_entry);
411 GNUNET_free (vrh); 411 }
412 GNUNET_free(vrh);
412} 413}
413 414
414static void 415static void
415shutdown_task (void *cls) 416shutdown_task(void *cls)
416{ 417{
417 struct VerifyRequestHandle *vrh; 418 struct VerifyRequestHandle *vrh;
418 419
419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down!\n"); 420 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down!\n");
420 421
421 while (NULL != (vrh = vrh_head)) { 422 while (NULL != (vrh = vrh_head))
422 // CREDENTIAL_resolver_lookup_cancel (clh->lookup); 423 {
423 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); 424 // CREDENTIAL_resolver_lookup_cancel (clh->lookup);
424 cleanup_handle (vrh); 425 GNUNET_CONTAINER_DLL_remove(vrh_head, vrh_tail, vrh);
425 } 426 cleanup_handle(vrh);
426 427 }
427 if (NULL != gns) { 428
428 GNUNET_GNS_disconnect (gns); 429 if (NULL != gns)
429 gns = NULL; 430 {
430 } 431 GNUNET_GNS_disconnect(gns);
431 if (NULL != namestore) { 432 gns = NULL;
432 GNUNET_NAMESTORE_disconnect (namestore); 433 }
433 namestore = NULL; 434 if (NULL != namestore)
434 } 435 {
435 if (NULL != statistics) { 436 GNUNET_NAMESTORE_disconnect(namestore);
436 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); 437 namestore = NULL;
437 statistics = NULL; 438 }
438 } 439 if (NULL != statistics)
440 {
441 GNUNET_STATISTICS_destroy(statistics, GNUNET_NO);
442 statistics = NULL;
443 }
439} 444}
440 445
441 446
442static void 447static void
443send_lookup_response (struct VerifyRequestHandle *vrh) 448send_lookup_response(struct VerifyRequestHandle *vrh)
444{ 449{
445 struct GNUNET_MQ_Envelope *env; 450 struct GNUNET_MQ_Envelope *env;
446 struct DelegationChainResultMessage *rmsg; 451 struct DelegationChainResultMessage *rmsg;
@@ -451,99 +456,103 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
451 struct CredentialRecordEntry *tmp; 456 struct CredentialRecordEntry *tmp;
452 size_t size; 457 size_t size;
453 458
454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response\n"); 459 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending response\n");
455 dce = vrh->delegation_chain_head; 460 dce = vrh->delegation_chain_head;
456 for (uint32_t i = 0; i < vrh->delegation_chain_size; i++) { 461 for (uint32_t i = 0; i < vrh->delegation_chain_size; i++)
457 dd[i].issuer_key = dce->issuer_key; 462 {
458 dd[i].subject_key = dce->subject_key; 463 dd[i].issuer_key = dce->issuer_key;
459 dd[i].issuer_attribute = dce->issuer_attribute; 464 dd[i].subject_key = dce->subject_key;
460 dd[i].issuer_attribute_len = strlen (dce->issuer_attribute) + 1; 465 dd[i].issuer_attribute = dce->issuer_attribute;
461 dd[i].subject_attribute_len = 0; 466 dd[i].issuer_attribute_len = strlen(dce->issuer_attribute) + 1;
462 dd[i].subject_attribute = NULL; 467 dd[i].subject_attribute_len = 0;
463 if (NULL != dce->subject_attribute) { 468 dd[i].subject_attribute = NULL;
464 dd[i].subject_attribute = dce->subject_attribute; 469 if (NULL != dce->subject_attribute)
465 dd[i].subject_attribute_len = strlen (dce->subject_attribute) + 1; 470 {
471 dd[i].subject_attribute = dce->subject_attribute;
472 dd[i].subject_attribute_len = strlen(dce->subject_attribute) + 1;
473 }
474 dce = dce->next;
466 } 475 }
467 dce = dce->next;
468 }
469 476
470 /** 477 /**
471 * Remove all credentials not needed 478 * Remove all credentials not needed
472 */ 479 */
473 for (cd = vrh->cred_chain_head; NULL != cd;) { 480 for (cd = vrh->cred_chain_head; NULL != cd;)
474 if (cd->refcount > 0) { 481 {
482 if (cd->refcount > 0)
483 {
484 cd = cd->next;
485 continue;
486 }
487 tmp = cd;
475 cd = cd->next; 488 cd = cd->next;
476 continue; 489 GNUNET_CONTAINER_DLL_remove(vrh->cred_chain_head,
490 vrh->cred_chain_tail,
491 tmp);
492 GNUNET_free(tmp->credential);
493 GNUNET_free(tmp);
494 vrh->cred_chain_size--;
477 } 495 }
478 tmp = cd;
479 cd = cd->next;
480 GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head,
481 vrh->cred_chain_tail,
482 tmp);
483 GNUNET_free (tmp->credential);
484 GNUNET_free (tmp);
485 vrh->cred_chain_size--;
486 }
487 496
488 /** 497 /**
489 * Get serialized record data 498 * Get serialized record data
490 * Append at the end of rmsg 499 * Append at the end of rmsg
491 */ 500 */
492 cd = vrh->cred_chain_head; 501 cd = vrh->cred_chain_head;
493 for (uint32_t i = 0; i < vrh->cred_chain_size; i++) { 502 for (uint32_t i = 0; i < vrh->cred_chain_size; i++)
494 cred[i].issuer_key = cd->credential->issuer_key; 503 {
495 cred[i].subject_key = cd->credential->subject_key; 504 cred[i].issuer_key = cd->credential->issuer_key;
496 cred[i].issuer_attribute_len 505 cred[i].subject_key = cd->credential->subject_key;
497 = strlen (cd->credential->issuer_attribute) + 1; 506 cred[i].issuer_attribute_len
498 cred[i].issuer_attribute = cd->credential->issuer_attribute; 507 = strlen(cd->credential->issuer_attribute) + 1;
499 cred[i].expiration = cd->credential->expiration; 508 cred[i].issuer_attribute = cd->credential->issuer_attribute;
500 cred[i].signature = cd->credential->signature; 509 cred[i].expiration = cd->credential->expiration;
501 cd = cd->next; 510 cred[i].signature = cd->credential->signature;
502 } 511 cd = cd->next;
512 }
503 size 513 size
504 = GNUNET_CREDENTIAL_delegation_chain_get_size (vrh->delegation_chain_size, 514 = GNUNET_CREDENTIAL_delegation_chain_get_size(vrh->delegation_chain_size,
505 dd, 515 dd,
506 vrh->cred_chain_size, 516 vrh->cred_chain_size,
507 cred); 517 cred);
508 env = GNUNET_MQ_msg_extra (rmsg, 518 env = GNUNET_MQ_msg_extra(rmsg,
509 size, 519 size,
510 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT); 520 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT);
511 // Assign id so that client can find associated request 521 // Assign id so that client can find associated request
512 rmsg->id = vrh->request_id; 522 rmsg->id = vrh->request_id;
513 rmsg->d_count = htonl (vrh->delegation_chain_size); 523 rmsg->d_count = htonl(vrh->delegation_chain_size);
514 rmsg->c_count = htonl (vrh->cred_chain_size); 524 rmsg->c_count = htonl(vrh->cred_chain_size);
515 525
516 if (0 < vrh->cred_chain_size) 526 if (0 < vrh->cred_chain_size)
517 rmsg->cred_found = htonl (GNUNET_YES); 527 rmsg->cred_found = htonl(GNUNET_YES);
518 else 528 else
519 rmsg->cred_found = htonl (GNUNET_NO); 529 rmsg->cred_found = htonl(GNUNET_NO);
520 530
521 GNUNET_assert ( 531 GNUNET_assert(
522 -1 532 -1
523 != GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->delegation_chain_size, 533 != GNUNET_CREDENTIAL_delegation_chain_serialize(vrh->delegation_chain_size,
524 dd, 534 dd,
525 vrh->cred_chain_size, 535 vrh->cred_chain_size,
526 cred, 536 cred,
527 size, 537 size,
528 (char *)&rmsg[1])); 538 (char *)&rmsg[1]));
529 539
530 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (vrh->client), env); 540 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(vrh->client), env);
531 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); 541 GNUNET_CONTAINER_DLL_remove(vrh_head, vrh_tail, vrh);
532 cleanup_handle (vrh); 542 cleanup_handle(vrh);
533 543
534 GNUNET_STATISTICS_update (statistics, 544 GNUNET_STATISTICS_update(statistics,
535 "Completed verifications", 545 "Completed verifications",
536 1, 546 1,
537 GNUNET_NO); 547 GNUNET_NO);
538} 548}
539 549
540 550
541static void 551static void
542backward_resolution (void *cls, 552backward_resolution(void *cls,
543 uint32_t rd_count, 553 uint32_t rd_count,
544 const struct GNUNET_GNSRECORD_Data *rd) 554 const struct GNUNET_GNSRECORD_Data *rd)
545{ 555{
546
547 struct VerifyRequestHandle *vrh; 556 struct VerifyRequestHandle *vrh;
548 const struct GNUNET_CREDENTIAL_DelegationRecord *sets; 557 const struct GNUNET_CREDENTIAL_DelegationRecord *sets;
549 struct CredentialRecordEntry *cred_pointer; 558 struct CredentialRecordEntry *cred_pointer;
@@ -559,176 +568,194 @@ backward_resolution (void *cls,
559 current_set->lookup_request = NULL; 568 current_set->lookup_request = NULL;
560 vrh = current_set->handle; 569 vrh = current_set->handle;
561 vrh->pending_lookups--; 570 vrh->pending_lookups--;
562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %d attrs\n", rd_count); 571 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got %d attrs\n", rd_count);
563 572
564 // Each OR 573 // Each OR
565 for (uint32_t i = 0; i < rd_count; i++) { 574 for (uint32_t i = 0; i < rd_count; i++)
566 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type) 575 {
567 continue; 576 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type)
568 577 continue;
569 sets = rd[i].data;
570 struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets->set_count)];
571 GNUNET_log (
572 GNUNET_ERROR_TYPE_DEBUG,
573 "Found new attribute delegation with %d sets. Creating new Job...\n",
574 ntohl (sets->set_count));
575
576 if (GNUNET_OK
577 != GNUNET_CREDENTIAL_delegation_set_deserialize (
578 GNUNET_ntohll (sets->data_size),
579 (const char *)&sets[1],
580 ntohl (sets->set_count),
581 set)) {
582 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to deserialize!\n");
583 continue;
584 }
585 dq_entry = GNUNET_new (struct DelegationQueueEntry);
586 dq_entry->required_solutions = ntohl (sets->set_count);
587 dq_entry->parent_set = current_set;
588 GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head,
589 current_set->queue_entries_tail,
590 dq_entry);
591 // Each AND
592 for (uint32_t j = 0; j < ntohl (sets->set_count); j++) {
593 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
594 if (NULL != current_set->attr_trailer) {
595 if (0 == set[j].subject_attribute_len) {
596 GNUNET_asprintf (&expanded_attr, "%s", current_set->attr_trailer);
597
598 } else {
599 GNUNET_asprintf (&expanded_attr,
600 "%s.%s",
601 set[j].subject_attribute,
602 current_set->attr_trailer);
603 }
604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expanded to %s\n", expanded_attr);
605 ds_entry->unresolved_attribute_delegation = expanded_attr;
606 } else {
607 if (0 != set[j].subject_attribute_len) {
608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
609 "Not Expanding %s\n",
610 set[j].subject_attribute);
611 ds_entry->unresolved_attribute_delegation
612 = GNUNET_strdup (set[j].subject_attribute);
613 }
614 }
615
616 // Add a credential chain entry
617 ds_entry->delegation_chain_entry
618 = GNUNET_new (struct DelegationChainEntry);
619 ds_entry->delegation_chain_entry->subject_key = set[j].subject_key;
620 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
621 GNUNET_memcpy (ds_entry->issuer_key,
622 &set[j].subject_key,
623 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
624 if (0 < set[j].subject_attribute_len)
625 ds_entry->delegation_chain_entry->subject_attribute
626 = GNUNET_strdup (set[j].subject_attribute);
627 ds_entry->delegation_chain_entry->issuer_key = *current_set->issuer_key;
628 ds_entry->delegation_chain_entry->issuer_attribute
629 = GNUNET_strdup (current_set->lookup_attribute);
630
631 ds_entry->parent_queue_entry = dq_entry; // current_delegation;
632 GNUNET_CONTAINER_DLL_insert (dq_entry->set_entries_head,
633 dq_entry->set_entries_tail,
634 ds_entry);
635
636 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking for cred match\n");
637 /**
638 * Check if this delegation already matches one of our credentials
639 */
640 for (cred_pointer = vrh->cred_chain_head; cred_pointer != NULL;
641 cred_pointer = cred_pointer->next) {
642 if (0
643 != GNUNET_memcmp (&set->subject_key,
644 &cred_pointer->credential->issuer_key))
645 continue;
646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
647 "Checking if %s matches %s\n",
648 ds_entry->unresolved_attribute_delegation,
649 cred_pointer->credential->issuer_attribute);
650
651 if (0
652 != strcmp (ds_entry->unresolved_attribute_delegation,
653 cred_pointer->credential->issuer_attribute))
654 continue;
655 578
656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found issuer\n"); 579 sets = rd[i].data;
657 cred_pointer->refcount++; 580 struct GNUNET_CREDENTIAL_DelegationSet set[ntohl(sets->set_count)];
658 // Backtrack 581 GNUNET_log(
659 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry; 582 GNUNET_ERROR_TYPE_DEBUG,
660 tmp_set = tmp_set->parent_queue_entry->parent_set) { 583 "Found new attribute delegation with %d sets. Creating new Job...\n",
661 tmp_set->parent_queue_entry->required_solutions--; 584 ntohl(sets->set_count));
662 if (NULL != tmp_set->delegation_chain_entry) { 585
663 vrh->delegation_chain_size++; 586 if (GNUNET_OK
664 GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head, 587 != GNUNET_CREDENTIAL_delegation_set_deserialize(
665 vrh->delegation_chain_tail, 588 GNUNET_ntohll(sets->data_size),
666 tmp_set->delegation_chain_entry); 589 (const char *)&sets[1],
667 } 590 ntohl(sets->set_count),
668 if (0 < tmp_set->parent_queue_entry->required_solutions) 591 set))
669 break; 592 {
593 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to deserialize!\n");
594 continue;
670 } 595 }
671 596 dq_entry = GNUNET_new(struct DelegationQueueEntry);
672 if (NULL == tmp_set->parent_queue_entry) { 597 dq_entry->required_solutions = ntohl(sets->set_count);
673 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "All solutions found\n"); 598 dq_entry->parent_set = current_set;
674 // Found match 599 GNUNET_CONTAINER_DLL_insert(current_set->queue_entries_head,
675 send_lookup_response (vrh); 600 current_set->queue_entries_tail,
676 return; 601 dq_entry);
602 // Each AND
603 for (uint32_t j = 0; j < ntohl(sets->set_count); j++)
604 {
605 ds_entry = GNUNET_new(struct DelegationSetQueueEntry);
606 if (NULL != current_set->attr_trailer)
607 {
608 if (0 == set[j].subject_attribute_len)
609 {
610 GNUNET_asprintf(&expanded_attr, "%s", current_set->attr_trailer);
611 }
612 else
613 {
614 GNUNET_asprintf(&expanded_attr,
615 "%s.%s",
616 set[j].subject_attribute,
617 current_set->attr_trailer);
618 }
619 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Expanded to %s\n", expanded_attr);
620 ds_entry->unresolved_attribute_delegation = expanded_attr;
621 }
622 else
623 {
624 if (0 != set[j].subject_attribute_len)
625 {
626 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
627 "Not Expanding %s\n",
628 set[j].subject_attribute);
629 ds_entry->unresolved_attribute_delegation
630 = GNUNET_strdup(set[j].subject_attribute);
631 }
632 }
633
634 // Add a credential chain entry
635 ds_entry->delegation_chain_entry
636 = GNUNET_new(struct DelegationChainEntry);
637 ds_entry->delegation_chain_entry->subject_key = set[j].subject_key;
638 ds_entry->issuer_key = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPublicKey);
639 GNUNET_memcpy(ds_entry->issuer_key,
640 &set[j].subject_key,
641 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
642 if (0 < set[j].subject_attribute_len)
643 ds_entry->delegation_chain_entry->subject_attribute
644 = GNUNET_strdup(set[j].subject_attribute);
645 ds_entry->delegation_chain_entry->issuer_key = *current_set->issuer_key;
646 ds_entry->delegation_chain_entry->issuer_attribute
647 = GNUNET_strdup(current_set->lookup_attribute);
648
649 ds_entry->parent_queue_entry = dq_entry; // current_delegation;
650 GNUNET_CONTAINER_DLL_insert(dq_entry->set_entries_head,
651 dq_entry->set_entries_tail,
652 ds_entry);
653
654 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Checking for cred match\n");
655 /**
656 * Check if this delegation already matches one of our credentials
657 */
658 for (cred_pointer = vrh->cred_chain_head; cred_pointer != NULL;
659 cred_pointer = cred_pointer->next)
660 {
661 if (0
662 != GNUNET_memcmp(&set->subject_key,
663 &cred_pointer->credential->issuer_key))
664 continue;
665 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
666 "Checking if %s matches %s\n",
667 ds_entry->unresolved_attribute_delegation,
668 cred_pointer->credential->issuer_attribute);
669
670 if (0
671 != strcmp(ds_entry->unresolved_attribute_delegation,
672 cred_pointer->credential->issuer_attribute))
673 continue;
674
675 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found issuer\n");
676 cred_pointer->refcount++;
677 // Backtrack
678 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry;
679 tmp_set = tmp_set->parent_queue_entry->parent_set)
680 {
681 tmp_set->parent_queue_entry->required_solutions--;
682 if (NULL != tmp_set->delegation_chain_entry)
683 {
684 vrh->delegation_chain_size++;
685 GNUNET_CONTAINER_DLL_insert(vrh->delegation_chain_head,
686 vrh->delegation_chain_tail,
687 tmp_set->delegation_chain_entry);
688 }
689 if (0 < tmp_set->parent_queue_entry->required_solutions)
690 break;
691 }
692
693 if (NULL == tmp_set->parent_queue_entry)
694 {
695 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "All solutions found\n");
696 // Found match
697 send_lookup_response(vrh);
698 return;
699 }
700 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Not all solutions found yet.\n");
701 continue;
702 }
703 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
704 "Building new lookup request from %s\n",
705 ds_entry->unresolved_attribute_delegation);
706 // Continue with backward resolution
707 char
708 issuer_attribute_name[strlen(ds_entry->unresolved_attribute_delegation)
709 + 1];
710 strcpy(issuer_attribute_name, ds_entry->unresolved_attribute_delegation);
711 char *next_attr = strtok(issuer_attribute_name, ".");
712 if (NULL == next_attr)
713 {
714 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
715 "Failed to parse next attribute\n");
716 continue;
717 }
718 GNUNET_asprintf(&lookup_attribute, "%s", next_attr);
719 GNUNET_asprintf(&ds_entry->lookup_attribute, "%s", next_attr);
720 if (strlen(next_attr)
721 == strlen(ds_entry->unresolved_attribute_delegation))
722 {
723 ds_entry->attr_trailer = NULL;
724 }
725 else
726 {
727 next_attr += strlen(next_attr) + 1;
728 ds_entry->attr_trailer = GNUNET_strdup(next_attr);
729 }
730
731 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
732 "Looking up %s\n",
733 ds_entry->lookup_attribute);
734 if (NULL != ds_entry->attr_trailer)
735 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
736 "%s still to go...\n",
737 ds_entry->attr_trailer);
738
739 vrh->pending_lookups++;
740 ds_entry->handle = vrh;
741 ds_entry->lookup_request
742 = GNUNET_GNS_lookup(gns,
743 lookup_attribute,
744 ds_entry->issuer_key, // issuer_key,
745 GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
746 GNUNET_GNS_LO_DEFAULT,
747 &backward_resolution,
748 ds_entry);
749 GNUNET_free(lookup_attribute);
677 } 750 }
678 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not all solutions found yet.\n");
679 continue;
680 }
681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
682 "Building new lookup request from %s\n",
683 ds_entry->unresolved_attribute_delegation);
684 // Continue with backward resolution
685 char
686 issuer_attribute_name[strlen (ds_entry->unresolved_attribute_delegation)
687 + 1];
688 strcpy (issuer_attribute_name, ds_entry->unresolved_attribute_delegation);
689 char *next_attr = strtok (issuer_attribute_name, ".");
690 if (NULL == next_attr) {
691 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
692 "Failed to parse next attribute\n");
693 continue;
694 }
695 GNUNET_asprintf (&lookup_attribute, "%s", next_attr);
696 GNUNET_asprintf (&ds_entry->lookup_attribute, "%s", next_attr);
697 if (strlen (next_attr)
698 == strlen (ds_entry->unresolved_attribute_delegation)) {
699 ds_entry->attr_trailer = NULL;
700 } else {
701 next_attr += strlen (next_attr) + 1;
702 ds_entry->attr_trailer = GNUNET_strdup (next_attr);
703 }
704
705 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
706 "Looking up %s\n",
707 ds_entry->lookup_attribute);
708 if (NULL != ds_entry->attr_trailer)
709 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
710 "%s still to go...\n",
711 ds_entry->attr_trailer);
712
713 vrh->pending_lookups++;
714 ds_entry->handle = vrh;
715 ds_entry->lookup_request
716 = GNUNET_GNS_lookup (gns,
717 lookup_attribute,
718 ds_entry->issuer_key, // issuer_key,
719 GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
720 GNUNET_GNS_LO_DEFAULT,
721 &backward_resolution,
722 ds_entry);
723 GNUNET_free (lookup_attribute);
724 } 751 }
725 }
726 752
727 if (0 == vrh->pending_lookups) { 753 if (0 == vrh->pending_lookups)
728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n"); 754 {
729 send_lookup_response (vrh); 755 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n");
730 return; 756 send_lookup_response(vrh);
731 } 757 return;
758 }
732} 759}
733 760
734 761
@@ -738,90 +765,96 @@ backward_resolution (void *cls,
738 * @param cls the closure (our client lookup handle) 765 * @param cls the closure (our client lookup handle)
739 */ 766 */
740static void 767static void
741delegation_chain_resolution_start (void *cls) 768delegation_chain_resolution_start(void *cls)
742{ 769{
743 struct VerifyRequestHandle *vrh = cls; 770 struct VerifyRequestHandle *vrh = cls;
744 struct DelegationSetQueueEntry *ds_entry; 771 struct DelegationSetQueueEntry *ds_entry;
745 struct CredentialRecordEntry *cr_entry; 772 struct CredentialRecordEntry *cr_entry;
773
746 vrh->lookup_request = NULL; 774 vrh->lookup_request = NULL;
747 775
748 if (0 == vrh->cred_chain_size) { 776 if (0 == vrh->cred_chain_size)
749 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No credentials found\n"); 777 {
750 send_lookup_response (vrh); 778 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No credentials found\n");
751 return; 779 send_lookup_response(vrh);
752 } 780 return;
781 }
753 782
754 for (cr_entry = vrh->cred_chain_head; cr_entry != NULL; 783 for (cr_entry = vrh->cred_chain_head; cr_entry != NULL;
755 cr_entry = cr_entry->next) { 784 cr_entry = cr_entry->next)
756 if (0 785 {
757 != GNUNET_memcmp (&cr_entry->credential->issuer_key, 786 if (0
758 &vrh->issuer_key)) 787 != GNUNET_memcmp(&cr_entry->credential->issuer_key,
759 continue; 788 &vrh->issuer_key))
760 if (0 789 continue;
761 != strcmp (cr_entry->credential->issuer_attribute, 790 if (0
762 vrh->issuer_attribute)) 791 != strcmp(cr_entry->credential->issuer_attribute,
763 continue; 792 vrh->issuer_attribute))
764 cr_entry->refcount++; 793 continue;
765 // Found match prematurely 794 cr_entry->refcount++;
766 send_lookup_response (vrh); 795 // Found match prematurely
767 return; 796 send_lookup_response(vrh);
768 } 797 return;
798 }
769 799
770 /** 800 /**
771 * Check for attributes from the issuer and follow the chain 801 * Check for attributes from the issuer and follow the chain
772 * till you get the required subject's attributes 802 * till you get the required subject's attributes
773 */ 803 */
774 char issuer_attribute_name[strlen (vrh->issuer_attribute) + 1]; 804 char issuer_attribute_name[strlen(vrh->issuer_attribute) + 1];
775 strcpy (issuer_attribute_name, vrh->issuer_attribute); 805 strcpy(issuer_attribute_name, vrh->issuer_attribute);
776 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 806 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
777 "Looking up %s\n", 807 "Looking up %s\n",
778 issuer_attribute_name); 808 issuer_attribute_name);
779 ds_entry = GNUNET_new (struct DelegationSetQueueEntry); 809 ds_entry = GNUNET_new(struct DelegationSetQueueEntry);
780 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); 810 ds_entry->issuer_key = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPublicKey);
781 GNUNET_memcpy (ds_entry->issuer_key, 811 GNUNET_memcpy(ds_entry->issuer_key,
782 &vrh->issuer_key, 812 &vrh->issuer_key,
783 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); 813 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
784 ds_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute); 814 ds_entry->issuer_attribute = GNUNET_strdup(vrh->issuer_attribute);
785 ds_entry->handle = vrh; 815 ds_entry->handle = vrh;
786 ds_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute); 816 ds_entry->lookup_attribute = GNUNET_strdup(vrh->issuer_attribute);
787 vrh->root_set = ds_entry; 817 vrh->root_set = ds_entry;
788 vrh->pending_lookups = 1; 818 vrh->pending_lookups = 1;
789 // Start with backward resolution 819 // Start with backward resolution
790 ds_entry->lookup_request = GNUNET_GNS_lookup (gns, 820 ds_entry->lookup_request = GNUNET_GNS_lookup(gns,
791 issuer_attribute_name, 821 issuer_attribute_name,
792 &vrh->issuer_key, // issuer_key, 822 &vrh->issuer_key, // issuer_key,
793 GNUNET_GNSRECORD_TYPE_ATTRIBUTE, 823 GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
794 GNUNET_GNS_LO_DEFAULT, 824 GNUNET_GNS_LO_DEFAULT,
795 &backward_resolution, 825 &backward_resolution,
796 ds_entry); 826 ds_entry);
797} 827}
798 828
799static int 829static int
800check_verify (void *cls, const struct VerifyMessage *v_msg) 830check_verify(void *cls, const struct VerifyMessage *v_msg)
801{ 831{
802 size_t msg_size; 832 size_t msg_size;
803 const char *attr; 833 const char *attr;
804 834
805 msg_size = ntohs (v_msg->header.size); 835 msg_size = ntohs(v_msg->header.size);
806 if (msg_size < sizeof (struct VerifyMessage)) { 836 if (msg_size < sizeof(struct VerifyMessage))
807 GNUNET_break (0); 837 {
808 return GNUNET_SYSERR; 838 GNUNET_break(0);
809 } 839 return GNUNET_SYSERR;
810 if (ntohs (v_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) { 840 }
811 GNUNET_break (0); 841 if (ntohs(v_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH)
812 return GNUNET_SYSERR; 842 {
813 } 843 GNUNET_break(0);
844 return GNUNET_SYSERR;
845 }
814 attr = (const char *)&v_msg[1]; 846 attr = (const char *)&v_msg[1];
815 847
816 if (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH) { 848 if (strlen(attr) > GNUNET_CREDENTIAL_MAX_LENGTH)
817 GNUNET_break (0); 849 {
818 return GNUNET_SYSERR; 850 GNUNET_break(0);
819 } 851 return GNUNET_SYSERR;
852 }
820 return GNUNET_OK; 853 return GNUNET_OK;
821} 854}
822 855
823static void 856static void
824handle_verify (void *cls, const struct VerifyMessage *v_msg) 857handle_verify(void *cls, const struct VerifyMessage *v_msg)
825{ 858{
826 struct VerifyRequestHandle *vrh; 859 struct VerifyRequestHandle *vrh;
827 struct GNUNET_SERVICE_Client *client = cls; 860 struct GNUNET_SERVICE_Client *client = cls;
@@ -834,96 +867,101 @@ handle_verify (void *cls, const struct VerifyMessage *v_msg)
834 char *credential_data; 867 char *credential_data;
835 const char *utf_in; 868 const char *utf_in;
836 869
837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received VERIFY message\n"); 870 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received VERIFY message\n");
838 utf_in = (const char *)&v_msg[1]; 871 utf_in = (const char *)&v_msg[1];
839 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr); 872 GNUNET_STRINGS_utf8_tolower(utf_in, attrptr);
840 GNUNET_memcpy (issuer_attribute, attr, ntohs (v_msg->issuer_attribute_len)); 873 GNUNET_memcpy(issuer_attribute, attr, ntohs(v_msg->issuer_attribute_len));
841 issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0'; 874 issuer_attribute[ntohs(v_msg->issuer_attribute_len)] = '\0';
842 vrh = GNUNET_new (struct VerifyRequestHandle); 875 vrh = GNUNET_new(struct VerifyRequestHandle);
843 GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh); 876 GNUNET_CONTAINER_DLL_insert(vrh_head, vrh_tail, vrh);
844 vrh->client = client; 877 vrh->client = client;
845 vrh->request_id = v_msg->id; 878 vrh->request_id = v_msg->id;
846 vrh->issuer_key = v_msg->issuer_key; 879 vrh->issuer_key = v_msg->issuer_key;
847 vrh->subject_key = v_msg->subject_key; 880 vrh->subject_key = v_msg->subject_key;
848 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute); 881 vrh->issuer_attribute = GNUNET_strdup(issuer_attribute);
849 GNUNET_SERVICE_client_continue (vrh->client); 882 GNUNET_SERVICE_client_continue(vrh->client);
850 if (0 == strlen (issuer_attribute)) { 883 if (0 == strlen(issuer_attribute))
851 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n"); 884 {
852 send_lookup_response (vrh); 885 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
853 return; 886 send_lookup_response(vrh);
854 } 887 return;
888 }
855 /** 889 /**
856 * First, collect credentials 890 * First, collect credentials
857 * TODO: cleanup! 891 * TODO: cleanup!
858 */ 892 */
859 credentials_count = ntohl (v_msg->c_count); 893 credentials_count = ntohl(v_msg->c_count);
860 credential_data_size = ntohs (v_msg->header.size) 894 credential_data_size = ntohs(v_msg->header.size)
861 - sizeof (struct VerifyMessage) 895 - sizeof(struct VerifyMessage)
862 - ntohs (v_msg->issuer_attribute_len) - 1; 896 - ntohs(v_msg->issuer_attribute_len) - 1;
863 struct GNUNET_CREDENTIAL_Credential credentials[credentials_count]; 897 struct GNUNET_CREDENTIAL_Credential credentials[credentials_count];
864 memset (credentials, 898 memset(credentials,
865 0, 899 0,
866 sizeof (struct GNUNET_CREDENTIAL_Credential) * credentials_count); 900 sizeof(struct GNUNET_CREDENTIAL_Credential) * credentials_count);
867 credential_data = (char *)&v_msg[1] + ntohs (v_msg->issuer_attribute_len) + 1; 901 credential_data = (char *)&v_msg[1] + ntohs(v_msg->issuer_attribute_len) + 1;
868 if (GNUNET_OK 902 if (GNUNET_OK
869 != GNUNET_CREDENTIAL_credentials_deserialize (credential_data_size, 903 != GNUNET_CREDENTIAL_credentials_deserialize(credential_data_size,
870 credential_data, 904 credential_data,
871 credentials_count, 905 credentials_count,
872 credentials)) { 906 credentials))
873 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot deserialize credentials!\n"); 907 {
874 send_lookup_response (vrh); 908 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot deserialize credentials!\n");
875 return; 909 send_lookup_response(vrh);
876 } 910 return;
877 911 }
878 for (uint32_t i = 0; i < credentials_count; i++) { 912
879 cr_entry = GNUNET_new (struct CredentialRecordEntry); 913 for (uint32_t i = 0; i < credentials_count; i++)
880 cr_entry->credential 914 {
881 = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) 915 cr_entry = GNUNET_new(struct CredentialRecordEntry);
882 + credentials[i].issuer_attribute_len + 1); 916 cr_entry->credential
883 GNUNET_memcpy (cr_entry->credential, 917 = GNUNET_malloc(sizeof(struct GNUNET_CREDENTIAL_Credential)
884 &credentials[i], 918 + credentials[i].issuer_attribute_len + 1);
885 sizeof (struct GNUNET_CREDENTIAL_Credential)); 919 GNUNET_memcpy(cr_entry->credential,
886 GNUNET_memcpy (&cr_entry->credential[1], 920 &credentials[i],
887 credentials[i].issuer_attribute, 921 sizeof(struct GNUNET_CREDENTIAL_Credential));
888 credentials[i].issuer_attribute_len); 922 GNUNET_memcpy(&cr_entry->credential[1],
889 cr_entry->credential->issuer_attribute_len 923 credentials[i].issuer_attribute,
890 = credentials[i].issuer_attribute_len; 924 credentials[i].issuer_attribute_len);
891 cr_entry->credential->issuer_attribute = (char *)&cr_entry->credential[1]; 925 cr_entry->credential->issuer_attribute_len
892 GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head, 926 = credentials[i].issuer_attribute_len;
893 vrh->cred_chain_tail, 927 cr_entry->credential->issuer_attribute = (char *)&cr_entry->credential[1];
894 cr_entry); 928 GNUNET_CONTAINER_DLL_insert_tail(vrh->cred_chain_head,
895 vrh->cred_chain_size++; 929 vrh->cred_chain_tail,
896 } 930 cr_entry);
897 931 vrh->cred_chain_size++;
898 delegation_chain_resolution_start (vrh); 932 }
933
934 delegation_chain_resolution_start(vrh);
899} 935}
900 936
901static void 937static void
902handle_cred_collection_error_cb (void *cls) 938handle_cred_collection_error_cb(void *cls)
903{ 939{
904 struct VerifyRequestHandle *vrh = cls; 940 struct VerifyRequestHandle *vrh = cls;
905 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 941
906 "Got disconnected from namestore database.\n"); 942 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
943 "Got disconnected from namestore database.\n");
907 vrh->cred_collection_iter = NULL; 944 vrh->cred_collection_iter = NULL;
908 send_lookup_response (vrh); 945 send_lookup_response(vrh);
909} 946}
910 947
911static void 948static void
912collect_next (void *cls) 949collect_next(void *cls)
913{ 950{
914 struct VerifyRequestHandle *vrh = cls; 951 struct VerifyRequestHandle *vrh = cls;
952
915 vrh->collect_next_task = NULL; 953 vrh->collect_next_task = NULL;
916 GNUNET_assert (NULL != vrh->cred_collection_iter); 954 GNUNET_assert(NULL != vrh->cred_collection_iter);
917 GNUNET_NAMESTORE_zone_iterator_next (vrh->cred_collection_iter, 1); 955 GNUNET_NAMESTORE_zone_iterator_next(vrh->cred_collection_iter, 1);
918} 956}
919 957
920 958
921static void 959static void
922handle_cred_collection_cb (void *cls, 960handle_cred_collection_cb(void *cls,
923 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, 961 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
924 const char *label, 962 const char *label,
925 unsigned int rd_count, 963 unsigned int rd_count,
926 const struct GNUNET_GNSRECORD_Data *rd) 964 const struct GNUNET_GNSRECORD_Data *rd)
927{ 965{
928 struct VerifyRequestHandle *vrh = cls; 966 struct VerifyRequestHandle *vrh = cls;
929 struct GNUNET_CREDENTIAL_Credential *crd; 967 struct GNUNET_CREDENTIAL_Credential *crd;
@@ -931,37 +969,40 @@ handle_cred_collection_cb (void *cls,
931 int cred_record_count; 969 int cred_record_count;
932 970
933 cred_record_count = 0; 971 cred_record_count = 0;
934 for (uint32_t i = 0; i < rd_count; i++) { 972 for (uint32_t i = 0; i < rd_count; i++)
935 if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type) 973 {
936 continue; 974 if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type)
937 cred_record_count++; 975 continue;
938 crd 976 cred_record_count++;
939 = GNUNET_CREDENTIAL_credential_deserialize (rd[i].data, rd[i].data_size); 977 crd
940 if (NULL == crd) { 978 = GNUNET_CREDENTIAL_credential_deserialize(rd[i].data, rd[i].data_size);
941 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential found\n"); 979 if (NULL == crd)
942 continue; 980 {
981 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Invalid credential found\n");
982 continue;
983 }
984 cr_entry = GNUNET_new(struct CredentialRecordEntry);
985 cr_entry->credential = crd;
986 GNUNET_CONTAINER_DLL_insert_tail(vrh->cred_chain_head,
987 vrh->cred_chain_tail,
988 cr_entry);
989 vrh->cred_chain_size++;
943 } 990 }
944 cr_entry = GNUNET_new (struct CredentialRecordEntry); 991 vrh->collect_next_task = GNUNET_SCHEDULER_add_now(&collect_next, vrh);
945 cr_entry->credential = crd;
946 GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head,
947 vrh->cred_chain_tail,
948 cr_entry);
949 vrh->cred_chain_size++;
950 }
951 vrh->collect_next_task = GNUNET_SCHEDULER_add_now (&collect_next, vrh);
952} 992}
953 993
954static void 994static void
955handle_cred_collection_finished_cb (void *cls) 995handle_cred_collection_finished_cb(void *cls)
956{ 996{
957 struct VerifyRequestHandle *vrh = cls; 997 struct VerifyRequestHandle *vrh = cls;
958 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done collecting credentials.\n"); 998
999 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Done collecting credentials.\n");
959 vrh->cred_collection_iter = NULL; 1000 vrh->cred_collection_iter = NULL;
960 delegation_chain_resolution_start (vrh); 1001 delegation_chain_resolution_start(vrh);
961} 1002}
962 1003
963static void 1004static void
964handle_collect (void *cls, const struct CollectMessage *c_msg) 1005handle_collect(void *cls, const struct CollectMessage *c_msg)
965{ 1006{
966 char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1]; 1007 char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
967 char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1]; 1008 char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
@@ -970,31 +1011,32 @@ handle_collect (void *cls, const struct CollectMessage *c_msg)
970 char *attrptr = attr; 1011 char *attrptr = attr;
971 const char *utf_in; 1012 const char *utf_in;
972 1013
973 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received COLLECT message\n"); 1014 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received COLLECT message\n");
974 1015
975 utf_in = (const char *)&c_msg[1]; 1016 utf_in = (const char *)&c_msg[1];
976 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr); 1017 GNUNET_STRINGS_utf8_tolower(utf_in, attrptr);
977 1018
978 GNUNET_memcpy (issuer_attribute, attr, ntohs (c_msg->issuer_attribute_len)); 1019 GNUNET_memcpy(issuer_attribute, attr, ntohs(c_msg->issuer_attribute_len));
979 issuer_attribute[ntohs (c_msg->issuer_attribute_len)] = '\0'; 1020 issuer_attribute[ntohs(c_msg->issuer_attribute_len)] = '\0';
980 vrh = GNUNET_new (struct VerifyRequestHandle); 1021 vrh = GNUNET_new(struct VerifyRequestHandle);
981 GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh); 1022 GNUNET_CONTAINER_DLL_insert(vrh_head, vrh_tail, vrh);
982 vrh->client = client; 1023 vrh->client = client;
983 vrh->request_id = c_msg->id; 1024 vrh->request_id = c_msg->id;
984 vrh->issuer_key = c_msg->issuer_key; 1025 vrh->issuer_key = c_msg->issuer_key;
985 GNUNET_CRYPTO_ecdsa_key_get_public (&c_msg->subject_key, &vrh->subject_key); 1026 GNUNET_CRYPTO_ecdsa_key_get_public(&c_msg->subject_key, &vrh->subject_key);
986 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute); 1027 vrh->issuer_attribute = GNUNET_strdup(issuer_attribute);
987 1028
988 if (0 == strlen (issuer_attribute)) { 1029 if (0 == strlen(issuer_attribute))
989 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n"); 1030 {
990 send_lookup_response (vrh); 1031 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
991 return; 1032 send_lookup_response(vrh);
992 } 1033 return;
993 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting credentials for subject\n"); 1034 }
1035 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Getting credentials for subject\n");
994 /** 1036 /**
995 * First, get attribute from subject 1037 * First, get attribute from subject
996 */ 1038 */
997 vrh->cred_collection_iter = GNUNET_NAMESTORE_zone_iteration_start ( 1039 vrh->cred_collection_iter = GNUNET_NAMESTORE_zone_iteration_start(
998 namestore, 1040 namestore,
999 &c_msg->subject_key, 1041 &c_msg->subject_key,
1000 &handle_cred_collection_error_cb, 1042 &handle_cred_collection_error_cb,
@@ -1003,49 +1045,52 @@ handle_collect (void *cls, const struct CollectMessage *c_msg)
1003 vrh, 1045 vrh,
1004 &handle_cred_collection_finished_cb, 1046 &handle_cred_collection_finished_cb,
1005 vrh); 1047 vrh);
1006 GNUNET_SERVICE_client_continue (vrh->client); 1048 GNUNET_SERVICE_client_continue(vrh->client);
1007} 1049}
1008 1050
1009 1051
1010static int 1052static int
1011check_collect (void *cls, const struct CollectMessage *c_msg) 1053check_collect(void *cls, const struct CollectMessage *c_msg)
1012{ 1054{
1013 size_t msg_size; 1055 size_t msg_size;
1014 const char *attr; 1056 const char *attr;
1015 1057
1016 msg_size = ntohs (c_msg->header.size); 1058 msg_size = ntohs(c_msg->header.size);
1017 if (msg_size < sizeof (struct CollectMessage)) { 1059 if (msg_size < sizeof(struct CollectMessage))
1018 GNUNET_break (0); 1060 {
1019 return GNUNET_SYSERR; 1061 GNUNET_break(0);
1020 } 1062 return GNUNET_SYSERR;
1021 if (ntohs (c_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) { 1063 }
1022 GNUNET_break (0); 1064 if (ntohs(c_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH)
1023 return GNUNET_SYSERR; 1065 {
1024 } 1066 GNUNET_break(0);
1067 return GNUNET_SYSERR;
1068 }
1025 attr = (const char *)&c_msg[1]; 1069 attr = (const char *)&c_msg[1];
1026 1070
1027 if (('\0' != attr[msg_size - sizeof (struct CollectMessage) - 1]) 1071 if (('\0' != attr[msg_size - sizeof(struct CollectMessage) - 1])
1028 || (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH)) { 1072 || (strlen(attr) > GNUNET_CREDENTIAL_MAX_LENGTH))
1029 GNUNET_break (0); 1073 {
1030 return GNUNET_SYSERR; 1074 GNUNET_break(0);
1031 } 1075 return GNUNET_SYSERR;
1076 }
1032 return GNUNET_OK; 1077 return GNUNET_OK;
1033} 1078}
1034 1079
1035static void 1080static void
1036client_disconnect_cb (void *cls, 1081client_disconnect_cb(void *cls,
1037 struct GNUNET_SERVICE_Client *client, 1082 struct GNUNET_SERVICE_Client *client,
1038 void *app_ctx) 1083 void *app_ctx)
1039{ 1084{
1040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); 1085 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
1041} 1086}
1042 1087
1043static void * 1088static void *
1044client_connect_cb (void *cls, 1089client_connect_cb(void *cls,
1045 struct GNUNET_SERVICE_Client *client, 1090 struct GNUNET_SERVICE_Client *client,
1046 struct GNUNET_MQ_Handle *mq) 1091 struct GNUNET_MQ_Handle *mq)
1047{ 1092{
1048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); 1093 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client);
1049 return client; 1094 return client;
1050} 1095}
1051 1096
@@ -1057,43 +1102,44 @@ client_connect_cb (void *cls,
1057 * @param handle service handle 1102 * @param handle service handle
1058 */ 1103 */
1059static void 1104static void
1060run (void *cls, 1105run(void *cls,
1061 const struct GNUNET_CONFIGURATION_Handle *c, 1106 const struct GNUNET_CONFIGURATION_Handle *c,
1062 struct GNUNET_SERVICE_Handle *handle) 1107 struct GNUNET_SERVICE_Handle *handle)
1063{ 1108{
1109 gns = GNUNET_GNS_connect(c);
1110 if (NULL == gns)
1111 {
1112 fprintf(stderr, _("Failed to connect to GNS\n"));
1113 }
1114 namestore = GNUNET_NAMESTORE_connect(c);
1115 if (NULL == namestore)
1116 {
1117 fprintf(stderr, _("Failed to connect to namestore\n"));
1118 }
1064 1119
1065 gns = GNUNET_GNS_connect (c); 1120 statistics = GNUNET_STATISTICS_create("credential", c);
1066 if (NULL == gns) { 1121 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
1067 fprintf (stderr, _ ("Failed to connect to GNS\n"));
1068 }
1069 namestore = GNUNET_NAMESTORE_connect (c);
1070 if (NULL == namestore) {
1071 fprintf (stderr, _ ("Failed to connect to namestore\n"));
1072 }
1073
1074 statistics = GNUNET_STATISTICS_create ("credential", c);
1075 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1076} 1122}
1077 1123
1078 1124
1079/** 1125/**
1080 * Define "main" method using service macro 1126 * Define "main" method using service macro
1081 */ 1127 */
1082GNUNET_SERVICE_MAIN ( 1128GNUNET_SERVICE_MAIN(
1083 "credential", 1129 "credential",
1084 GNUNET_SERVICE_OPTION_NONE, 1130 GNUNET_SERVICE_OPTION_NONE,
1085 &run, 1131 &run,
1086 &client_connect_cb, 1132 &client_connect_cb,
1087 &client_disconnect_cb, 1133 &client_disconnect_cb,
1088 NULL, 1134 NULL,
1089 GNUNET_MQ_hd_var_size (verify, 1135 GNUNET_MQ_hd_var_size(verify,
1090 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY, 1136 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY,
1091 struct VerifyMessage, 1137 struct VerifyMessage,
1092 NULL), 1138 NULL),
1093 GNUNET_MQ_hd_var_size (collect, 1139 GNUNET_MQ_hd_var_size(collect,
1094 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT, 1140 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT,
1095 struct CollectMessage, 1141 struct CollectMessage,
1096 NULL), 1142 NULL),
1097 GNUNET_MQ_handler_end ()); 1143 GNUNET_MQ_handler_end());
1098 1144
1099/* end of gnunet-service-credential.c */ 1145/* end of gnunet-service-credential.c */
diff --git a/src/credential/plugin_gnsrecord_credential.c b/src/credential/plugin_gnsrecord_credential.c
index c03f2b3e4..9207aa7ad 100644
--- a/src/credential/plugin_gnsrecord_credential.c
+++ b/src/credential/plugin_gnsrecord_credential.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file credential/plugin_gnsrecord_credential.c 22 * @file credential/plugin_gnsrecord_credential.c
@@ -43,72 +43,85 @@
43 * @return NULL on error, otherwise human-readable representation of the value 43 * @return NULL on error, otherwise human-readable representation of the value
44 */ 44 */
45static char * 45static char *
46credential_value_to_string (void *cls, uint32_t type, const void *data, 46credential_value_to_string(void *cls, uint32_t type, const void *data,
47 size_t data_size) 47 size_t data_size)
48{ 48{
49
50 const char *cdata; 49 const char *cdata;
51 50
52 switch (type) { 51 switch (type)
53 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: { 52 {
54 struct GNUNET_CREDENTIAL_DelegationRecord sets; 53 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: {
55 char *attr_str; 54 struct GNUNET_CREDENTIAL_DelegationRecord sets;
56 char *subject_pkey; 55 char *attr_str;
57 char *tmp_str; 56 char *subject_pkey;
58 int i; 57 char *tmp_str;
59 if (data_size < sizeof (struct GNUNET_CREDENTIAL_DelegationRecord)) 58 int i;
60 return NULL; /* malformed */ 59 if (data_size < sizeof(struct GNUNET_CREDENTIAL_DelegationRecord))
61 GNUNET_memcpy (&sets, data, sizeof (sets)); 60 return NULL; /* malformed */
62 cdata = data; 61 GNUNET_memcpy(&sets, data, sizeof(sets));
63 struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets.set_count)]; 62 cdata = data;
64 if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize ( 63 struct GNUNET_CREDENTIAL_DelegationSet set[ntohl(sets.set_count)];
65 GNUNET_ntohll (sets.data_size), &cdata[sizeof (sets)], 64 if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize(
66 ntohl (sets.set_count), set)) 65 GNUNET_ntohll(sets.data_size), &cdata[sizeof(sets)],
67 return NULL; 66 ntohl(sets.set_count), set))
68 67 return NULL;
69 for (i = 0; i < ntohl (sets.set_count); i++) { 68
70 subject_pkey = 69 for (i = 0; i < ntohl(sets.set_count); i++)
71 GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key); 70 {
72 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d len attr\n", 71 subject_pkey =
73 set[i].subject_attribute_len); 72 GNUNET_CRYPTO_ecdsa_public_key_to_string(&set[i].subject_key);
74 if (0 == set[i].subject_attribute_len) { 73 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%d len attr\n",
75 if (0 == i) { 74 set[i].subject_attribute_len);
76 GNUNET_asprintf (&attr_str, "%s", subject_pkey); 75 if (0 == set[i].subject_attribute_len)
77 } else { 76 {
78 GNUNET_asprintf (&tmp_str, "%s,%s", attr_str, subject_pkey); 77 if (0 == i)
79 GNUNET_free (attr_str); 78 {
80 attr_str = tmp_str; 79 GNUNET_asprintf(&attr_str, "%s", subject_pkey);
80 }
81 else
82 {
83 GNUNET_asprintf(&tmp_str, "%s,%s", attr_str, subject_pkey);
84 GNUNET_free(attr_str);
85 attr_str = tmp_str;
86 }
87 }
88 else
89 {
90 if (0 == i)
91 {
92 GNUNET_asprintf(&attr_str, "%s %s", subject_pkey,
93 set[i].subject_attribute);
94 }
95 else
96 {
97 GNUNET_asprintf(&tmp_str, "%s,%s %s", attr_str, subject_pkey,
98 set[i].subject_attribute);
99 GNUNET_free(attr_str);
100 attr_str = tmp_str;
101 }
102 }
103 GNUNET_free(subject_pkey);
81 } 104 }
82 } else { 105 return attr_str;
83 if (0 == i) { 106 }
84 GNUNET_asprintf (&attr_str, "%s %s", subject_pkey, 107
85 set[i].subject_attribute); 108 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: {
86 } else { 109 struct GNUNET_CREDENTIAL_Credential *cred;
87 GNUNET_asprintf (&tmp_str, "%s,%s %s", attr_str, subject_pkey, 110 char *cred_str;
88 set[i].subject_attribute); 111
89 GNUNET_free (attr_str); 112 cred = GNUNET_CREDENTIAL_credential_deserialize(data, data_size);
90 attr_str = tmp_str; 113 cred_str = GNUNET_CREDENTIAL_credential_to_string(cred);
91 } 114 GNUNET_free(cred);
92 } 115 return cred_str;
93 GNUNET_free (subject_pkey); 116 }
117
118 case GNUNET_GNSRECORD_TYPE_POLICY: {
119 return GNUNET_strndup(data, data_size);
120 }
121
122 default:
123 return NULL;
94 } 124 }
95 return attr_str;
96 }
97 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: {
98 struct GNUNET_CREDENTIAL_Credential *cred;
99 char *cred_str;
100
101 cred = GNUNET_CREDENTIAL_credential_deserialize (data, data_size);
102 cred_str = GNUNET_CREDENTIAL_credential_to_string (cred);
103 GNUNET_free (cred);
104 return cred_str;
105 }
106 case GNUNET_GNSRECORD_TYPE_POLICY: {
107 return GNUNET_strndup (data, data_size);
108 }
109 default:
110 return NULL;
111 }
112} 125}
113 126
114 127
@@ -124,100 +137,114 @@ credential_value_to_string (void *cls, uint32_t type, const void *data,
124 * @return #GNUNET_OK on success 137 * @return #GNUNET_OK on success
125 */ 138 */
126static int 139static int
127credential_string_to_value (void *cls, uint32_t type, const char *s, 140credential_string_to_value(void *cls, uint32_t type, const char *s,
128 void **data, size_t *data_size) 141 void **data, size_t *data_size)
129{ 142{
130 if (NULL == s) 143 if (NULL == s)
131 return GNUNET_SYSERR; 144 return GNUNET_SYSERR;
132 switch (type) { 145 switch (type)
133 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: { 146 {
134 struct GNUNET_CREDENTIAL_DelegationRecord *sets; 147 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: {
135 char attr_str[253 + 1]; 148 struct GNUNET_CREDENTIAL_DelegationRecord *sets;
136 char subject_pkey[52 + 1]; 149 char attr_str[253 + 1];
137 char *token; 150 char subject_pkey[52 + 1];
138 char *tmp_str; 151 char *token;
139 int matches = 0; 152 char *tmp_str;
140 int entries; 153 int matches = 0;
141 size_t tmp_data_size; 154 int entries;
142 int i; 155 size_t tmp_data_size;
143 156 int i;
144 tmp_str = GNUNET_strdup (s); 157
145 token = strtok (tmp_str, ","); 158 tmp_str = GNUNET_strdup(s);
146 entries = 0; 159 token = strtok(tmp_str, ",");
147 tmp_data_size = 0; 160 entries = 0;
148 *data_size = sizeof (struct GNUNET_CREDENTIAL_DelegationRecord); 161 tmp_data_size = 0;
149 while (NULL != token) { 162 *data_size = sizeof(struct GNUNET_CREDENTIAL_DelegationRecord);
150 matches = SSCANF (token, "%s %s", subject_pkey, attr_str); 163 while (NULL != token)
151 if (0 == matches) { 164 {
152 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 165 matches = SSCANF(token, "%s %s", subject_pkey, attr_str);
153 _ ("Unable to parse ATTR record string `%s'\n"), s); 166 if (0 == matches)
154 GNUNET_free (tmp_str); 167 {
155 return GNUNET_SYSERR; 168 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
156 } 169 _("Unable to parse ATTR record string `%s'\n"), s);
157 if (1 == matches) { 170 GNUNET_free(tmp_str);
158 tmp_data_size += sizeof (struct GNUNET_CREDENTIAL_DelegationRecordSet); 171 return GNUNET_SYSERR;
159 } else if (2 == matches) { 172 }
160 tmp_data_size += sizeof (struct GNUNET_CREDENTIAL_DelegationRecordSet) + 173 if (1 == matches)
161 strlen (attr_str) + 1; 174 {
162 } 175 tmp_data_size += sizeof(struct GNUNET_CREDENTIAL_DelegationRecordSet);
163 entries++; 176 }
164 token = strtok (NULL, ","); 177 else if (2 == matches)
178 {
179 tmp_data_size += sizeof(struct GNUNET_CREDENTIAL_DelegationRecordSet) +
180 strlen(attr_str) + 1;
181 }
182 entries++;
183 token = strtok(NULL, ",");
184 }
185 GNUNET_free(tmp_str);
186 tmp_str = GNUNET_strdup(s);
187 token = strtok(tmp_str, ",");
188 if (NULL == token)
189 {
190 GNUNET_free(tmp_str);
191 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s);
192 return GNUNET_SYSERR;
193 }
194 struct GNUNET_CREDENTIAL_DelegationSet set[entries];
195 memset(set, 0, sizeof(struct GNUNET_CREDENTIAL_DelegationSet) * entries);
196 for (i = 0; i < entries; i++)
197 {
198 matches = SSCANF(token, "%s %s", subject_pkey, attr_str);
199 GNUNET_CRYPTO_ecdsa_public_key_from_string(
200 subject_pkey, strlen(subject_pkey), &set[i].subject_key);
201 if (2 == matches)
202 {
203 set[i].subject_attribute_len = strlen(attr_str) + 1;
204 set[i].subject_attribute = GNUNET_strdup(attr_str);
205 }
206 token = strtok(NULL, ",");
207 }
208 tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size(entries, set);
209
210 if (-1 == tmp_data_size)
211 {
212 GNUNET_free(tmp_str);
213 return GNUNET_SYSERR;
214 }
215 *data_size += tmp_data_size;
216 *data = sets = GNUNET_malloc(*data_size);
217 GNUNET_CREDENTIAL_delegation_set_serialize(entries, set, tmp_data_size,
218 (char *)&sets[1]);
219 for (i = 0; i < entries; i++)
220 {
221 if (0 != set[i].subject_attribute_len)
222 GNUNET_free((char *)set[i].subject_attribute);
223 }
224 sets->set_count = htonl(entries);
225 sets->data_size = GNUNET_htonll(tmp_data_size);
226
227 GNUNET_free(tmp_str);
228 return GNUNET_OK;
165 } 229 }
166 GNUNET_free (tmp_str); 230
167 tmp_str = GNUNET_strdup (s); 231 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: {
168 token = strtok (tmp_str, ","); 232 struct GNUNET_CREDENTIAL_Credential *cred;
169 if (NULL == token) { 233 cred = GNUNET_CREDENTIAL_credential_from_string(s);
170 GNUNET_free (tmp_str); 234
171 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s); 235 *data_size = GNUNET_CREDENTIAL_credential_serialize(cred, (char **)data);
172 return GNUNET_SYSERR; 236 return GNUNET_OK;
173 } 237 }
174 struct GNUNET_CREDENTIAL_DelegationSet set[entries]; 238
175 memset (set, 0, sizeof (struct GNUNET_CREDENTIAL_DelegationSet) * entries); 239 case GNUNET_GNSRECORD_TYPE_POLICY: {
176 for (i = 0; i < entries; i++) { 240 *data_size = strlen(s);
177 matches = SSCANF (token, "%s %s", subject_pkey, attr_str); 241 *data = GNUNET_strdup(s);
178 GNUNET_CRYPTO_ecdsa_public_key_from_string ( 242 return GNUNET_OK;
179 subject_pkey, strlen (subject_pkey), &set[i].subject_key);
180 if (2 == matches) {
181 set[i].subject_attribute_len = strlen (attr_str) + 1;
182 set[i].subject_attribute = GNUNET_strdup (attr_str);
183 }
184 token = strtok (NULL, ",");
185 } 243 }
186 tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries, set);
187 244
188 if (-1 == tmp_data_size) { 245 default:
189 GNUNET_free (tmp_str);
190 return GNUNET_SYSERR; 246 return GNUNET_SYSERR;
191 } 247 }
192 *data_size += tmp_data_size;
193 *data = sets = GNUNET_malloc (*data_size);
194 GNUNET_CREDENTIAL_delegation_set_serialize (entries, set, tmp_data_size,
195 (char *)&sets[1]);
196 for (i = 0; i < entries; i++) {
197 if (0 != set[i].subject_attribute_len)
198 GNUNET_free ((char *)set[i].subject_attribute);
199 }
200 sets->set_count = htonl (entries);
201 sets->data_size = GNUNET_htonll (tmp_data_size);
202
203 GNUNET_free (tmp_str);
204 return GNUNET_OK;
205 }
206 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: {
207 struct GNUNET_CREDENTIAL_Credential *cred;
208 cred = GNUNET_CREDENTIAL_credential_from_string (s);
209
210 *data_size = GNUNET_CREDENTIAL_credential_serialize (cred, (char **)data);
211 return GNUNET_OK;
212 }
213 case GNUNET_GNSRECORD_TYPE_POLICY: {
214 *data_size = strlen (s);
215 *data = GNUNET_strdup (s);
216 return GNUNET_OK;
217 }
218 default:
219 return GNUNET_SYSERR;
220 }
221} 248}
222 249
223 250
@@ -225,14 +252,13 @@ credential_string_to_value (void *cls, uint32_t type, const char *s,
225 * Mapping of record type numbers to human-readable 252 * Mapping of record type numbers to human-readable
226 * record type names. 253 * record type names.
227 */ 254 */
228static struct 255static struct {
229{
230 const char *name; 256 const char *name;
231 uint32_t number; 257 uint32_t number;
232} name_map[] = {{"CRED", GNUNET_GNSRECORD_TYPE_CREDENTIAL}, 258} name_map[] = { { "CRED", GNUNET_GNSRECORD_TYPE_CREDENTIAL },
233 {"ATTR", GNUNET_GNSRECORD_TYPE_ATTRIBUTE}, 259 { "ATTR", GNUNET_GNSRECORD_TYPE_ATTRIBUTE },
234 {"POLICY", GNUNET_GNSRECORD_TYPE_POLICY}, 260 { "POLICY", GNUNET_GNSRECORD_TYPE_POLICY },
235 {NULL, UINT32_MAX}}; 261 { NULL, UINT32_MAX } };
236 262
237 263
238/** 264/**
@@ -243,13 +269,13 @@ static struct
243 * @return corresponding number, UINT32_MAX on error 269 * @return corresponding number, UINT32_MAX on error
244 */ 270 */
245static uint32_t 271static uint32_t
246credential_typename_to_number (void *cls, const char *gns_typename) 272credential_typename_to_number(void *cls, const char *gns_typename)
247{ 273{
248 unsigned int i; 274 unsigned int i;
249 275
250 i = 0; 276 i = 0;
251 while ((name_map[i].name != NULL) && 277 while ((name_map[i].name != NULL) &&
252 (0 != strcasecmp (gns_typename, name_map[i].name))) 278 (0 != strcasecmp(gns_typename, name_map[i].name)))
253 i++; 279 i++;
254 return name_map[i].number; 280 return name_map[i].number;
255} 281}
@@ -263,7 +289,7 @@ credential_typename_to_number (void *cls, const char *gns_typename)
263 * @return corresponding typestring, NULL on error 289 * @return corresponding typestring, NULL on error
264 */ 290 */
265static const char * 291static const char *
266credential_number_to_typename (void *cls, uint32_t type) 292credential_number_to_typename(void *cls, uint32_t type)
267{ 293{
268 unsigned int i; 294 unsigned int i;
269 295
@@ -281,11 +307,11 @@ credential_number_to_typename (void *cls, uint32_t type)
281 * @return the exported block API 307 * @return the exported block API
282 */ 308 */
283void * 309void *
284libgnunet_plugin_gnsrecord_credential_init (void *cls) 310libgnunet_plugin_gnsrecord_credential_init(void *cls)
285{ 311{
286 struct GNUNET_GNSRECORD_PluginFunctions *api; 312 struct GNUNET_GNSRECORD_PluginFunctions *api;
287 313
288 api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions); 314 api = GNUNET_new(struct GNUNET_GNSRECORD_PluginFunctions);
289 api->value_to_string = &credential_value_to_string; 315 api->value_to_string = &credential_value_to_string;
290 api->string_to_value = &credential_string_to_value; 316 api->string_to_value = &credential_string_to_value;
291 api->typename_to_number = &credential_typename_to_number; 317 api->typename_to_number = &credential_typename_to_number;
@@ -301,11 +327,11 @@ libgnunet_plugin_gnsrecord_credential_init (void *cls)
301 * @return NULL 327 * @return NULL
302 */ 328 */
303void * 329void *
304libgnunet_plugin_gnsrecord_credential_done (void *cls) 330libgnunet_plugin_gnsrecord_credential_done(void *cls)
305{ 331{
306 struct GNUNET_GNSRECORD_PluginFunctions *api = cls; 332 struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
307 333
308 GNUNET_free (api); 334 GNUNET_free(api);
309 return NULL; 335 return NULL;
310} 336}
311 337
diff --git a/src/credential/plugin_rest_credential.c b/src/credential/plugin_rest_credential.c
index 78267b54e..51c1f8b8c 100644
--- a/src/credential/plugin_rest_credential.c
+++ b/src/credential/plugin_rest_credential.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @author Martin Schanzenbach 21 * @author Martin Schanzenbach
22 * @file credential/plugin_rest_credential.c 22 * @file credential/plugin_rest_credential.c
@@ -62,15 +62,13 @@
62/** 62/**
63 * @brief struct returned by the initialization function of the plugin 63 * @brief struct returned by the initialization function of the plugin
64 */ 64 */
65struct Plugin 65struct Plugin {
66{
67 const struct GNUNET_CONFIGURATION_Handle *cfg; 66 const struct GNUNET_CONFIGURATION_Handle *cfg;
68}; 67};
69 68
70const struct GNUNET_CONFIGURATION_Handle *cfg; 69const struct GNUNET_CONFIGURATION_Handle *cfg;
71 70
72struct RequestHandle 71struct RequestHandle {
73{
74 /** 72 /**
75 * Handle to Credential service. 73 * Handle to Credential service.
76 */ 74 */
@@ -155,7 +153,6 @@ struct RequestHandle
155 * Timeout 153 * Timeout
156 */ 154 */
157 struct GNUNET_TIME_Relative timeout; 155 struct GNUNET_TIME_Relative timeout;
158
159}; 156};
160 157
161 158
@@ -165,44 +162,44 @@ struct RequestHandle
165 * @param handle Handle to clean up 162 * @param handle Handle to clean up
166 */ 163 */
167static void 164static void
168cleanup_handle (struct RequestHandle *handle) 165cleanup_handle(struct RequestHandle *handle)
169{ 166{
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 167 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
171 "Cleaning up\n"); 168 "Cleaning up\n");
172 if (NULL != handle->json_root) 169 if (NULL != handle->json_root)
173 json_decref (handle->json_root); 170 json_decref(handle->json_root);
174 171
175 if (NULL != handle->issuer_attr) 172 if (NULL != handle->issuer_attr)
176 GNUNET_free (handle->issuer_attr); 173 GNUNET_free(handle->issuer_attr);
177 if (NULL != handle->subject_attr) 174 if (NULL != handle->subject_attr)
178 GNUNET_free (handle->subject_attr); 175 GNUNET_free(handle->subject_attr);
179 if (NULL != handle->verify_request) 176 if (NULL != handle->verify_request)
180 GNUNET_CREDENTIAL_request_cancel (handle->verify_request); 177 GNUNET_CREDENTIAL_request_cancel(handle->verify_request);
181 if (NULL != handle->credential) 178 if (NULL != handle->credential)
182 GNUNET_CREDENTIAL_disconnect (handle->credential); 179 GNUNET_CREDENTIAL_disconnect(handle->credential);
183 if (NULL != handle->id_op) 180 if (NULL != handle->id_op)
184 GNUNET_IDENTITY_cancel (handle->id_op); 181 GNUNET_IDENTITY_cancel(handle->id_op);
185 if (NULL != handle->ego_lookup) 182 if (NULL != handle->ego_lookup)
186 GNUNET_IDENTITY_ego_lookup_cancel (handle->ego_lookup); 183 GNUNET_IDENTITY_ego_lookup_cancel(handle->ego_lookup);
187 if (NULL != handle->identity) 184 if (NULL != handle->identity)
188 GNUNET_IDENTITY_disconnect (handle->identity); 185 GNUNET_IDENTITY_disconnect(handle->identity);
189 if (NULL != handle->timeout_task) 186 if (NULL != handle->timeout_task)
190 { 187 {
191 GNUNET_SCHEDULER_cancel (handle->timeout_task); 188 GNUNET_SCHEDULER_cancel(handle->timeout_task);
192 } 189 }
193 GNUNET_free (handle); 190 GNUNET_free(handle);
194} 191}
195 192
196 193
197static void 194static void
198do_error (void *cls) 195do_error(void *cls)
199{ 196{
200 struct RequestHandle *handle = cls; 197 struct RequestHandle *handle = cls;
201 struct MHD_Response *resp; 198 struct MHD_Response *resp;
202 199
203 resp = GNUNET_REST_create_response (NULL); 200 resp = GNUNET_REST_create_response(NULL);
204 handle->proc (handle->proc_cls, resp, handle->response_code); 201 handle->proc(handle->proc_cls, resp, handle->response_code);
205 cleanup_handle (handle); 202 cleanup_handle(handle);
206} 203}
207 204
208/** 205/**
@@ -212,41 +209,41 @@ do_error (void *cls)
212 * @return JSON, NULL if failed 209 * @return JSON, NULL if failed
213 */ 210 */
214static json_t* 211static json_t*
215attribute_delegation_to_json (struct GNUNET_CREDENTIAL_Delegation *delegation_chain_entry) 212attribute_delegation_to_json(struct GNUNET_CREDENTIAL_Delegation *delegation_chain_entry)
216{ 213{
217 char *subject; 214 char *subject;
218 char *issuer; 215 char *issuer;
219 json_t *attr_obj; 216 json_t *attr_obj;
220 217
221 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&delegation_chain_entry->issuer_key); 218 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string(&delegation_chain_entry->issuer_key);
222 if (NULL == issuer) 219 if (NULL == issuer)
223 { 220 {
224 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 221 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
225 "Issuer in delegation malformed\n"); 222 "Issuer in delegation malformed\n");
226 return NULL; 223 return NULL;
227 } 224 }
228 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string (&delegation_chain_entry->subject_key); 225 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string(&delegation_chain_entry->subject_key);
229 if (NULL == subject) 226 if (NULL == subject)
230 { 227 {
231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 228 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
232 "Subject in credential malformed\n"); 229 "Subject in credential malformed\n");
233 GNUNET_free (issuer); 230 GNUNET_free(issuer);
234 return NULL; 231 return NULL;
235 } 232 }
236 attr_obj = json_object (); 233 attr_obj = json_object();
237 234
238 json_object_set_new (attr_obj, "issuer", json_string (issuer)); 235 json_object_set_new(attr_obj, "issuer", json_string(issuer));
239 json_object_set_new (attr_obj, "issuer_attribute", 236 json_object_set_new(attr_obj, "issuer_attribute",
240 json_string (delegation_chain_entry->issuer_attribute)); 237 json_string(delegation_chain_entry->issuer_attribute));
241 238
242 json_object_set_new (attr_obj, "subject", json_string (subject)); 239 json_object_set_new(attr_obj, "subject", json_string(subject));
243 if (0 < delegation_chain_entry->subject_attribute_len) 240 if (0 < delegation_chain_entry->subject_attribute_len)
244 { 241 {
245 json_object_set_new (attr_obj, "subject_attribute", 242 json_object_set_new(attr_obj, "subject_attribute",
246 json_string (delegation_chain_entry->subject_attribute)); 243 json_string(delegation_chain_entry->subject_attribute));
247 } 244 }
248 GNUNET_free (issuer); 245 GNUNET_free(issuer);
249 GNUNET_free (subject); 246 GNUNET_free(subject);
250 return attr_obj; 247 return attr_obj;
251} 248}
252 249
@@ -257,7 +254,7 @@ attribute_delegation_to_json (struct GNUNET_CREDENTIAL_Delegation *delegation_ch
257 * @return the resulting credential, NULL if failed 254 * @return the resulting credential, NULL if failed
258 */ 255 */
259static struct GNUNET_CREDENTIAL_Credential* 256static struct GNUNET_CREDENTIAL_Credential*
260json_to_credential (json_t *res) 257json_to_credential(json_t *res)
261{ 258{
262 struct GNUNET_CREDENTIAL_Credential *cred; 259 struct GNUNET_CREDENTIAL_Credential *cred;
263 json_t *tmp; 260 json_t *tmp;
@@ -265,58 +262,58 @@ json_to_credential (json_t *res)
265 const char *signature; 262 const char *signature;
266 char *sig; 263 char *sig;
267 264
268 tmp = json_object_get (res, "attribute"); 265 tmp = json_object_get(res, "attribute");
269 if (0 == json_is_string (tmp)) 266 if (0 == json_is_string(tmp))
270 { 267 {
271 return NULL; 268 return NULL;
272 } 269 }
273 attribute = json_string_value (tmp); 270 attribute = json_string_value(tmp);
274 cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) 271 cred = GNUNET_malloc(sizeof(struct GNUNET_CREDENTIAL_Credential)
275 + strlen (attribute)); 272 + strlen(attribute));
276 cred->issuer_attribute = attribute; 273 cred->issuer_attribute = attribute;
277 cred->issuer_attribute_len = strlen (attribute); 274 cred->issuer_attribute_len = strlen(attribute);
278 tmp = json_object_get (res, "issuer"); 275 tmp = json_object_get(res, "issuer");
279 if (0 == json_is_string (tmp)) 276 if (0 == json_is_string(tmp))
280 { 277 {
281 GNUNET_free (cred); 278 GNUNET_free(cred);
282 return NULL; 279 return NULL;
283 } 280 }
284 281
285 GNUNET_CRYPTO_ecdsa_public_key_from_string (json_string_value(tmp), 282 GNUNET_CRYPTO_ecdsa_public_key_from_string(json_string_value(tmp),
286 strlen (json_string_value(tmp)), 283 strlen(json_string_value(tmp)),
287 &cred->issuer_key); 284 &cred->issuer_key);
288 tmp = json_object_get (res, "subject"); 285 tmp = json_object_get(res, "subject");
289 if (0 == json_is_string (tmp)) 286 if (0 == json_is_string(tmp))
290 { 287 {
291 GNUNET_free (cred); 288 GNUNET_free(cred);
292 return NULL; 289 return NULL;
293 } 290 }
294 GNUNET_CRYPTO_ecdsa_public_key_from_string (json_string_value(tmp), 291 GNUNET_CRYPTO_ecdsa_public_key_from_string(json_string_value(tmp),
295 strlen (json_string_value(tmp)), 292 strlen(json_string_value(tmp)),
296 &cred->subject_key); 293 &cred->subject_key);
297 294
298 tmp = json_object_get (res, "signature"); 295 tmp = json_object_get(res, "signature");
299 if (0 == json_is_string (tmp)) 296 if (0 == json_is_string(tmp))
300 { 297 {
301 GNUNET_free (cred); 298 GNUNET_free(cred);
302 return NULL; 299 return NULL;
303 } 300 }
304 signature = json_string_value (tmp); 301 signature = json_string_value(tmp);
305 GNUNET_STRINGS_base64_decode (signature, 302 GNUNET_STRINGS_base64_decode(signature,
306 strlen (signature), 303 strlen(signature),
307 (char**)&sig); 304 (char**)&sig);
308 GNUNET_memcpy (&cred->signature, 305 GNUNET_memcpy(&cred->signature,
309 sig, 306 sig,
310 sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); 307 sizeof(struct GNUNET_CRYPTO_EcdsaSignature));
311 GNUNET_free (sig); 308 GNUNET_free(sig);
312 309
313 tmp = json_object_get (res, "expiration"); 310 tmp = json_object_get(res, "expiration");
314 if (0 == json_is_integer (tmp)) 311 if (0 == json_is_integer(tmp))
315 { 312 {
316 GNUNET_free (cred); 313 GNUNET_free(cred);
317 return NULL; 314 return NULL;
318 } 315 }
319 cred->expiration.abs_value_us = json_integer_value (tmp); 316 cred->expiration.abs_value_us = json_integer_value(tmp);
320 return cred; 317 return cred;
321} 318}
322 319
@@ -328,7 +325,7 @@ json_to_credential (json_t *res)
328 * @return the resulting json, NULL if failed 325 * @return the resulting json, NULL if failed
329 */ 326 */
330static json_t* 327static json_t*
331credential_to_json (struct GNUNET_CREDENTIAL_Credential *cred) 328credential_to_json(struct GNUNET_CREDENTIAL_Credential *cred)
332{ 329{
333 char *issuer; 330 char *issuer;
334 char *subject; 331 char *subject;
@@ -336,42 +333,42 @@ credential_to_json (struct GNUNET_CREDENTIAL_Credential *cred)
336 char attribute[cred->issuer_attribute_len + 1]; 333 char attribute[cred->issuer_attribute_len + 1];
337 json_t *cred_obj; 334 json_t *cred_obj;
338 335
339 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key); 336 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->issuer_key);
340 if (NULL == issuer) 337 if (NULL == issuer)
341 { 338 {
342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 339 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
343 "Issuer in credential malformed\n"); 340 "Issuer in credential malformed\n");
344 return NULL; 341 return NULL;
345 } 342 }
346 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key); 343 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->subject_key);
347 if (NULL == subject) 344 if (NULL == subject)
348 { 345 {
349 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 346 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
350 "Subject in credential malformed\n"); 347 "Subject in credential malformed\n");
351 GNUNET_free (issuer); 348 GNUNET_free(issuer);
352 return NULL; 349 return NULL;
353 } 350 }
354 GNUNET_STRINGS_base64_encode ((char*)&cred->signature, 351 GNUNET_STRINGS_base64_encode((char*)&cred->signature,
355 sizeof (struct GNUNET_CRYPTO_EcdsaSignature), 352 sizeof(struct GNUNET_CRYPTO_EcdsaSignature),
356 &signature); 353 &signature);
357 GNUNET_memcpy (attribute, 354 GNUNET_memcpy(attribute,
358 cred->issuer_attribute, 355 cred->issuer_attribute,
359 cred->issuer_attribute_len); 356 cred->issuer_attribute_len);
360 attribute[cred->issuer_attribute_len] = '\0'; 357 attribute[cred->issuer_attribute_len] = '\0';
361 cred_obj = json_object (); 358 cred_obj = json_object();
362 json_object_set_new (cred_obj, "issuer", json_string (issuer)); 359 json_object_set_new(cred_obj, "issuer", json_string(issuer));
363 json_object_set_new (cred_obj, "subject", json_string (subject)); 360 json_object_set_new(cred_obj, "subject", json_string(subject));
364 json_object_set_new (cred_obj, "attribute", json_string (attribute)); 361 json_object_set_new(cred_obj, "attribute", json_string(attribute));
365 json_object_set_new (cred_obj, "signature", json_string (signature)); 362 json_object_set_new(cred_obj, "signature", json_string(signature));
366 json_object_set_new (cred_obj, "expiration", json_integer (cred->expiration.abs_value_us)); 363 json_object_set_new(cred_obj, "expiration", json_integer(cred->expiration.abs_value_us));
367 GNUNET_free (issuer); 364 GNUNET_free(issuer);
368 GNUNET_free (subject); 365 GNUNET_free(subject);
369 GNUNET_free (signature); 366 GNUNET_free(signature);
370 return cred_obj; 367 return cred_obj;
371} 368}
372 369
373static void 370static void
374handle_collect_response (void *cls, 371handle_collect_response(void *cls,
375 unsigned int d_count, 372 unsigned int d_count,
376 struct GNUNET_CREDENTIAL_Delegation *delegation_chain, 373 struct GNUNET_CREDENTIAL_Delegation *delegation_chain,
377 unsigned int c_count, 374 unsigned int c_count,
@@ -389,85 +386,86 @@ handle_collect_response (void *cls,
389 uint32_t i; 386 uint32_t i;
390 387
391 handle->verify_request = NULL; 388 handle->verify_request = NULL;
392 if (NULL == cred) { 389 if (NULL == cred)
393 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 390 {
394 "Verify failed.\n"); 391 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
395 handle->response_code = MHD_HTTP_NOT_FOUND; 392 "Verify failed.\n");
396 GNUNET_SCHEDULER_add_now (&do_error, handle); 393 handle->response_code = MHD_HTTP_NOT_FOUND;
397 return; 394 GNUNET_SCHEDULER_add_now(&do_error, handle);
398 } 395 return;
399 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&handle->issuer_key); 396 }
397 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string(&handle->issuer_key);
400 if (NULL == issuer) 398 if (NULL == issuer)
401 { 399 {
402 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 400 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
403 "Issuer in delegation malformed\n"); 401 "Issuer in delegation malformed\n");
404 return; 402 return;
405 } 403 }
406 GNUNET_asprintf (&id, 404 GNUNET_asprintf(&id,
407 "%s.%s", 405 "%s.%s",
408 issuer, 406 issuer,
409 handle->issuer_attr); 407 handle->issuer_attr);
410 GNUNET_free (issuer); 408 GNUNET_free(issuer);
411 json_document = GNUNET_JSONAPI_document_new (); 409 json_document = GNUNET_JSONAPI_document_new();
412 json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO, 410 json_resource = GNUNET_JSONAPI_resource_new(GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO,
413 id); 411 id);
414 GNUNET_free (id); 412 GNUNET_free(id);
415 cred_array = json_array (); 413 cred_array = json_array();
416 for (i=0;i<c_count;i++) 414 for (i = 0; i < c_count; i++)
417 { 415 {
418 cred_obj = credential_to_json (&cred[i]); 416 cred_obj = credential_to_json(&cred[i]);
419 json_array_append_new (cred_array, cred_obj); 417 json_array_append_new(cred_array, cred_obj);
420 } 418 }
421 GNUNET_JSONAPI_resource_add_attr (json_resource, 419 GNUNET_JSONAPI_resource_add_attr(json_resource,
422 GNUNET_REST_JSONAPI_CREDENTIAL, 420 GNUNET_REST_JSONAPI_CREDENTIAL,
423 cred_array); 421 cred_array);
424 GNUNET_JSONAPI_document_resource_add (json_document, json_resource); 422 GNUNET_JSONAPI_document_resource_add(json_document, json_resource);
425 GNUNET_JSONAPI_document_serialize (json_document, &result); 423 GNUNET_JSONAPI_document_serialize(json_document, &result);
426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 424 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
427 "Result %s\n", 425 "Result %s\n",
428 result); 426 result);
429 json_decref (cred_array); 427 json_decref(cred_array);
430 GNUNET_JSONAPI_document_delete (json_document); 428 GNUNET_JSONAPI_document_delete(json_document);
431 resp = GNUNET_REST_create_response (result); 429 resp = GNUNET_REST_create_response(result);
432 GNUNET_free(result); 430 GNUNET_free(result);
433 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 431 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
434 cleanup_handle (handle); 432 cleanup_handle(handle);
435} 433}
436 434
437static void 435static void
438subject_ego_lookup (void *cls, 436subject_ego_lookup(void *cls,
439 const struct GNUNET_IDENTITY_Ego *ego) 437 const struct GNUNET_IDENTITY_Ego *ego)
440{ 438{
441 struct RequestHandle *handle = cls; 439 struct RequestHandle *handle = cls;
442 const struct GNUNET_CRYPTO_EcdsaPrivateKey *sub_key; 440 const struct GNUNET_CRYPTO_EcdsaPrivateKey *sub_key;
441
443 handle->ego_lookup = NULL; 442 handle->ego_lookup = NULL;
444 443
445 if (NULL == ego) 444 if (NULL == ego)
446 { 445 {
447 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 446 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
448 "Subject not found\n"); 447 "Subject not found\n");
449 GNUNET_SCHEDULER_add_now (&do_error, handle); 448 GNUNET_SCHEDULER_add_now(&do_error, handle);
450 return; 449 return;
451 } 450 }
452 sub_key = GNUNET_IDENTITY_ego_get_private_key (ego); 451 sub_key = GNUNET_IDENTITY_ego_get_private_key(ego);
453 handle->verify_request = GNUNET_CREDENTIAL_collect (handle->credential, 452 handle->verify_request = GNUNET_CREDENTIAL_collect(handle->credential,
454 &handle->issuer_key, 453 &handle->issuer_key,
455 handle->issuer_attr, 454 handle->issuer_attr,
456 sub_key, 455 sub_key,
457 &handle_collect_response, 456 &handle_collect_response,
458 handle); 457 handle);
459} 458}
460 459
461 460
462 461
463static void 462static void
464handle_verify_response (void *cls, 463handle_verify_response(void *cls,
465 unsigned int d_count, 464 unsigned int d_count,
466 struct GNUNET_CREDENTIAL_Delegation *delegation_chain, 465 struct GNUNET_CREDENTIAL_Delegation *delegation_chain,
467 unsigned int c_count, 466 unsigned int c_count,
468 struct GNUNET_CREDENTIAL_Credential *cred) 467 struct GNUNET_CREDENTIAL_Credential *cred)
469{ 468{
470
471 struct RequestHandle *handle = cls; 469 struct RequestHandle *handle = cls;
472 struct MHD_Response *resp; 470 struct MHD_Response *resp;
473 struct GNUNET_JSONAPI_Document *json_document; 471 struct GNUNET_JSONAPI_Document *json_document;
@@ -482,165 +480,166 @@ handle_verify_response (void *cls,
482 uint32_t i; 480 uint32_t i;
483 481
484 handle->verify_request = NULL; 482 handle->verify_request = NULL;
485 if (NULL == cred) { 483 if (NULL == cred)
486 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 484 {
487 "Verify failed.\n"); 485 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
488 handle->response_code = MHD_HTTP_NOT_FOUND; 486 "Verify failed.\n");
489 GNUNET_SCHEDULER_add_now (&do_error, handle); 487 handle->response_code = MHD_HTTP_NOT_FOUND;
490 return; 488 GNUNET_SCHEDULER_add_now(&do_error, handle);
491 } 489 return;
492 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&handle->issuer_key); 490 }
491 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string(&handle->issuer_key);
493 if (NULL == issuer) 492 if (NULL == issuer)
494 { 493 {
495 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 494 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
496 "Issuer in delegation malformed\n"); 495 "Issuer in delegation malformed\n");
497 return; 496 return;
498 } 497 }
499 GNUNET_asprintf (&id, 498 GNUNET_asprintf(&id,
500 "%s.%s", 499 "%s.%s",
501 issuer, 500 issuer,
502 handle->issuer_attr); 501 handle->issuer_attr);
503 GNUNET_free (issuer); 502 GNUNET_free(issuer);
504 json_document = GNUNET_JSONAPI_document_new (); 503 json_document = GNUNET_JSONAPI_document_new();
505 json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO, 504 json_resource = GNUNET_JSONAPI_resource_new(GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO,
506 id); 505 id);
507 GNUNET_free (id); 506 GNUNET_free(id);
508 attr_array = json_array (); 507 attr_array = json_array();
509 for (i = 0; i < d_count; i++) 508 for (i = 0; i < d_count; i++)
510 { 509 {
511 attr_obj = attribute_delegation_to_json (&delegation_chain[i]); 510 attr_obj = attribute_delegation_to_json(&delegation_chain[i]);
512 json_array_append_new (attr_array, attr_obj); 511 json_array_append_new(attr_array, attr_obj);
513 } 512 }
514 cred_array = json_array (); 513 cred_array = json_array();
515 for (i=0;i<c_count;i++) 514 for (i = 0; i < c_count; i++)
516 { 515 {
517 cred_obj = credential_to_json (&cred[i]); 516 cred_obj = credential_to_json(&cred[i]);
518 json_array_append_new (cred_array, cred_obj); 517 json_array_append_new(cred_array, cred_obj);
519 } 518 }
520 GNUNET_JSONAPI_resource_add_attr (json_resource, 519 GNUNET_JSONAPI_resource_add_attr(json_resource,
521 GNUNET_REST_JSONAPI_CREDENTIAL, 520 GNUNET_REST_JSONAPI_CREDENTIAL,
522 cred_array); 521 cred_array);
523 GNUNET_JSONAPI_resource_add_attr (json_resource, 522 GNUNET_JSONAPI_resource_add_attr(json_resource,
524 GNUNET_REST_JSONAPI_DELEGATIONS, 523 GNUNET_REST_JSONAPI_DELEGATIONS,
525 attr_array); 524 attr_array);
526 GNUNET_JSONAPI_document_resource_add (json_document, json_resource); 525 GNUNET_JSONAPI_document_resource_add(json_document, json_resource);
527 GNUNET_JSONAPI_document_serialize (json_document, &result); 526 GNUNET_JSONAPI_document_serialize(json_document, &result);
528 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 527 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
529 "Result %s\n", 528 "Result %s\n",
530 result); 529 result);
531 json_decref (attr_array); 530 json_decref(attr_array);
532 json_decref (cred_array); 531 json_decref(cred_array);
533 GNUNET_JSONAPI_document_delete (json_document); 532 GNUNET_JSONAPI_document_delete(json_document);
534 resp = GNUNET_REST_create_response (result); 533 resp = GNUNET_REST_create_response(result);
535 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 534 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
536 GNUNET_free (result); 535 GNUNET_free(result);
537 cleanup_handle (handle); 536 cleanup_handle(handle);
538} 537}
539 538
540static void 539static void
541collect_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle, 540collect_cred_cont(struct GNUNET_REST_RequestHandle *conndata_handle,
542 const char* url, 541 const char* url,
543 void *cls) 542 void *cls)
544{ 543{
545 struct RequestHandle *handle = cls; 544 struct RequestHandle *handle = cls;
546 struct GNUNET_HashCode key; 545 struct GNUNET_HashCode key;
547 char *tmp; 546 char *tmp;
548 char *entity_attr; 547 char *entity_attr;
549 548
550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 549 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
551 "Connecting...\n"); 550 "Connecting...\n");
552 handle->credential = GNUNET_CREDENTIAL_connect (cfg); 551 handle->credential = GNUNET_CREDENTIAL_connect(cfg);
553 handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout, 552 handle->timeout_task = GNUNET_SCHEDULER_add_delayed(handle->timeout,
554 &do_error, handle); 553 &do_error, handle);
555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 554 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
556 "Connected\n"); 555 "Connected\n");
557 if (NULL == handle->credential) 556 if (NULL == handle->credential)
558 { 557 {
559 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 558 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
560 "Connecting to CREDENTIAL failed\n"); 559 "Connecting to CREDENTIAL failed\n");
561 GNUNET_SCHEDULER_add_now (&do_error, handle); 560 GNUNET_SCHEDULER_add_now(&do_error, handle);
562 return; 561 return;
563 } 562 }
564 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR, 563 GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR,
565 strlen (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR), 564 strlen(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR),
566 &key); 565 &key);
567 if ( GNUNET_NO == 566 if (GNUNET_NO ==
568 GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map, 567 GNUNET_CONTAINER_multihashmap_contains(conndata_handle->url_param_map,
569 &key) ) 568 &key))
570 { 569 {
571 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 570 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
572 "Missing issuer attribute\n"); 571 "Missing issuer attribute\n");
573 GNUNET_SCHEDULER_add_now (&do_error, handle); 572 GNUNET_SCHEDULER_add_now(&do_error, handle);
574 return; 573 return;
575 } 574 }
576 tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, 575 tmp = GNUNET_CONTAINER_multihashmap_get(conndata_handle->url_param_map,
577 &key); 576 &key);
578 entity_attr = GNUNET_strdup (tmp); 577 entity_attr = GNUNET_strdup(tmp);
579 tmp = strtok(entity_attr, "."); 578 tmp = strtok(entity_attr, ".");
580 if (NULL == tmp) 579 if (NULL == tmp)
581 { 580 {
582 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 581 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
583 "Malformed issuer or attribute\n"); 582 "Malformed issuer or attribute\n");
584 GNUNET_free (entity_attr); 583 GNUNET_free(entity_attr);
585 GNUNET_SCHEDULER_add_now (&do_error, handle); 584 GNUNET_SCHEDULER_add_now(&do_error, handle);
586 return; 585 return;
587 } 586 }
588 if (GNUNET_OK != 587 if (GNUNET_OK !=
589 GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp, 588 GNUNET_CRYPTO_ecdsa_public_key_from_string(tmp,
590 strlen (tmp), 589 strlen(tmp),
591 &handle->issuer_key)) 590 &handle->issuer_key))
592 { 591 {
593 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 592 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
594 "Malformed issuer key\n"); 593 "Malformed issuer key\n");
595 GNUNET_free (entity_attr); 594 GNUNET_free(entity_attr);
596 GNUNET_SCHEDULER_add_now (&do_error, handle); 595 GNUNET_SCHEDULER_add_now(&do_error, handle);
597 return; 596 return;
598 } 597 }
599 tmp = strtok (NULL, "."); //Issuer attribute 598 tmp = strtok(NULL, "."); //Issuer attribute
600 if (NULL == tmp) 599 if (NULL == tmp)
601 { 600 {
602 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 601 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
603 "Malformed attribute\n"); 602 "Malformed attribute\n");
604 GNUNET_free (entity_attr); 603 GNUNET_free(entity_attr);
605 GNUNET_SCHEDULER_add_now (&do_error, handle); 604 GNUNET_SCHEDULER_add_now(&do_error, handle);
606 return; 605 return;
607 } 606 }
608 handle->issuer_attr = GNUNET_strdup (tmp); 607 handle->issuer_attr = GNUNET_strdup(tmp);
609 GNUNET_free (entity_attr); 608 GNUNET_free(entity_attr);
610 609
611 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_EGO, 610 GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_EGO,
612 strlen (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_EGO), 611 strlen(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_EGO),
613 &key); 612 &key);
614 if ( GNUNET_NO == 613 if (GNUNET_NO ==
615 GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map, 614 GNUNET_CONTAINER_multihashmap_contains(conndata_handle->url_param_map,
616 &key) ) 615 &key))
617 { 616 {
618 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 617 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
619 "Missing subject\n"); 618 "Missing subject\n");
620 GNUNET_SCHEDULER_add_now (&do_error, handle); 619 GNUNET_SCHEDULER_add_now(&do_error, handle);
621 return; 620 return;
622 } 621 }
623 tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, 622 tmp = GNUNET_CONTAINER_multihashmap_get(conndata_handle->url_param_map,
624 &key); 623 &key);
625 if (NULL == tmp) 624 if (NULL == tmp)
626 { 625 {
627 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 626 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
628 "Malformed subject\n"); 627 "Malformed subject\n");
629 GNUNET_SCHEDULER_add_now (&do_error, handle); 628 GNUNET_SCHEDULER_add_now(&do_error, handle);
630 return; 629 return;
631 } 630 }
632 handle->ego_lookup = GNUNET_IDENTITY_ego_lookup (cfg, 631 handle->ego_lookup = GNUNET_IDENTITY_ego_lookup(cfg,
633 tmp, 632 tmp,
634 &subject_ego_lookup, 633 &subject_ego_lookup,
635 handle); 634 handle);
636} 635}
637 636
638 637
639 638
640static void 639static void
641verify_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle, 640verify_cred_cont(struct GNUNET_REST_RequestHandle *conndata_handle,
642 const char* url, 641 const char* url,
643 void *cls) 642 void *cls)
644{ 643{
645 struct RequestHandle *handle = cls; 644 struct RequestHandle *handle = cls;
646 struct GNUNET_HashCode key; 645 struct GNUNET_HashCode key;
@@ -656,186 +655,186 @@ verify_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
656 json_t *data_js; 655 json_t *data_js;
657 json_error_t err; 656 json_error_t err;
658 657
659 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 658 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
660 "Connecting...\n"); 659 "Connecting...\n");
661 handle->credential = GNUNET_CREDENTIAL_connect (cfg); 660 handle->credential = GNUNET_CREDENTIAL_connect(cfg);
662 handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout, 661 handle->timeout_task = GNUNET_SCHEDULER_add_delayed(handle->timeout,
663 &do_error, handle); 662 &do_error, handle);
664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 663 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
665 "Connected\n"); 664 "Connected\n");
666 if (NULL == handle->credential) 665 if (NULL == handle->credential)
667 { 666 {
668 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 667 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
669 "Connecting to CREDENTIAL failed\n"); 668 "Connecting to CREDENTIAL failed\n");
670 GNUNET_SCHEDULER_add_now (&do_error, handle); 669 GNUNET_SCHEDULER_add_now(&do_error, handle);
671 return; 670 return;
672 } 671 }
673 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR, 672 GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR,
674 strlen (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR), 673 strlen(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR),
675 &key); 674 &key);
676 if ( GNUNET_NO == 675 if (GNUNET_NO ==
677 GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map, 676 GNUNET_CONTAINER_multihashmap_contains(conndata_handle->url_param_map,
678 &key) ) 677 &key))
679 { 678 {
680 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 679 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
681 "Missing issuer attribute\n"); 680 "Missing issuer attribute\n");
682 GNUNET_SCHEDULER_add_now (&do_error, handle); 681 GNUNET_SCHEDULER_add_now(&do_error, handle);
683 return; 682 return;
684 } 683 }
685 tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, 684 tmp = GNUNET_CONTAINER_multihashmap_get(conndata_handle->url_param_map,
686 &key); 685 &key);
687 entity_attr = GNUNET_strdup (tmp); 686 entity_attr = GNUNET_strdup(tmp);
688 tmp = strtok(entity_attr, "."); 687 tmp = strtok(entity_attr, ".");
689 if (NULL == tmp) 688 if (NULL == tmp)
690 { 689 {
691 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 690 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
692 "Malformed issuer or attribute\n"); 691 "Malformed issuer or attribute\n");
693 GNUNET_free (entity_attr); 692 GNUNET_free(entity_attr);
694 GNUNET_SCHEDULER_add_now (&do_error, handle); 693 GNUNET_SCHEDULER_add_now(&do_error, handle);
695 return; 694 return;
696 } 695 }
697 if (GNUNET_OK != 696 if (GNUNET_OK !=
698 GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp, 697 GNUNET_CRYPTO_ecdsa_public_key_from_string(tmp,
699 strlen (tmp), 698 strlen(tmp),
700 &handle->issuer_key)) 699 &handle->issuer_key))
701 { 700 {
702 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 701 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
703 "Malformed issuer key\n"); 702 "Malformed issuer key\n");
704 GNUNET_free (entity_attr); 703 GNUNET_free(entity_attr);
705 GNUNET_SCHEDULER_add_now (&do_error, handle); 704 GNUNET_SCHEDULER_add_now(&do_error, handle);
706 return; 705 return;
707 } 706 }
708 tmp = strtok (NULL, "."); //Issuer attribute 707 tmp = strtok(NULL, "."); //Issuer attribute
709 if (NULL == tmp) 708 if (NULL == tmp)
710 { 709 {
711 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 710 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
712 "Malformed attribute\n"); 711 "Malformed attribute\n");
713 GNUNET_free (entity_attr); 712 GNUNET_free(entity_attr);
714 GNUNET_SCHEDULER_add_now (&do_error, handle); 713 GNUNET_SCHEDULER_add_now(&do_error, handle);
715 return; 714 return;
716 } 715 }
717 handle->issuer_attr = GNUNET_strdup (tmp); 716 handle->issuer_attr = GNUNET_strdup(tmp);
718 GNUNET_free (entity_attr); 717 GNUNET_free(entity_attr);
719 718
720 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY, 719 GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY,
721 strlen (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY), 720 strlen(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY),
722 &key); 721 &key);
723 if ( GNUNET_NO == 722 if (GNUNET_NO ==
724 GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map, 723 GNUNET_CONTAINER_multihashmap_contains(conndata_handle->url_param_map,
725 &key) ) 724 &key))
726 { 725 {
727 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 726 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
728 "Missing subject key\n"); 727 "Missing subject key\n");
729 GNUNET_SCHEDULER_add_now (&do_error, handle); 728 GNUNET_SCHEDULER_add_now(&do_error, handle);
730 return; 729 return;
731 } 730 }
732 tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, 731 tmp = GNUNET_CONTAINER_multihashmap_get(conndata_handle->url_param_map,
733 &key); 732 &key);
734 if (NULL == tmp) 733 if (NULL == tmp)
735 { 734 {
736 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 735 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
737 "Malformed subject\n"); 736 "Malformed subject\n");
738 GNUNET_SCHEDULER_add_now (&do_error, handle); 737 GNUNET_SCHEDULER_add_now(&do_error, handle);
739 return; 738 return;
740 } 739 }
741 if (GNUNET_OK != 740 if (GNUNET_OK !=
742 GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp, 741 GNUNET_CRYPTO_ecdsa_public_key_from_string(tmp,
743 strlen (tmp), 742 strlen(tmp),
744 &handle->subject_key)) { 743 &handle->subject_key))
745 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 744 {
746 "Malformed subject key\n"); 745 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
747 GNUNET_SCHEDULER_add_now (&do_error, handle); 746 "Malformed subject key\n");
748 return; 747 GNUNET_SCHEDULER_add_now(&do_error, handle);
749 } 748 return;
749 }
750 750
751 if (0 >= handle->rest_handle->data_size) 751 if (0 >= handle->rest_handle->data_size)
752 { 752 {
753 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 753 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
754 "Missing credentials\n"); 754 "Missing credentials\n");
755 GNUNET_SCHEDULER_add_now (&do_error, handle); 755 GNUNET_SCHEDULER_add_now(&do_error, handle);
756 return; 756 return;
757 } 757 }
758 758
759 struct GNUNET_JSON_Specification docspec[] = { 759 struct GNUNET_JSON_Specification docspec[] = {
760 GNUNET_JSON_spec_jsonapi_document (&json_obj), 760 GNUNET_JSON_spec_jsonapi_document(&json_obj),
761 GNUNET_JSON_spec_end() 761 GNUNET_JSON_spec_end()
762 }; 762 };
763 char term_data[handle->rest_handle->data_size+1]; 763 char term_data[handle->rest_handle->data_size + 1];
764 term_data[handle->rest_handle->data_size] = '\0'; 764 term_data[handle->rest_handle->data_size] = '\0';
765 credential_count = 0; 765 credential_count = 0;
766 GNUNET_memcpy (term_data, 766 GNUNET_memcpy(term_data,
767 handle->rest_handle->data, 767 handle->rest_handle->data,
768 handle->rest_handle->data_size); 768 handle->rest_handle->data_size);
769 data_js = json_loads (term_data, 769 data_js = json_loads(term_data,
770 JSON_DECODE_ANY, 770 JSON_DECODE_ANY,
771 &err); 771 &err);
772 GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (data_js, docspec, 772 GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(data_js, docspec,
773 NULL, NULL)); 773 NULL, NULL));
774 json_decref (data_js); 774 json_decref(data_js);
775 if (NULL == json_obj) 775 if (NULL == json_obj)
776 { 776 {
777 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 777 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
778 "Unable to parse JSONAPI Object from %s\n", 778 "Unable to parse JSONAPI Object from %s\n",
779 term_data); 779 term_data);
780 GNUNET_SCHEDULER_add_now (&do_error, handle); 780 GNUNET_SCHEDULER_add_now(&do_error, handle);
781 return; 781 return;
782 } 782 }
783 783
784 resource_count = GNUNET_JSONAPI_document_resource_count(json_obj); 784 resource_count = GNUNET_JSONAPI_document_resource_count(json_obj);
785 GNUNET_assert (1 == resource_count); 785 GNUNET_assert(1 == resource_count);
786 res = (GNUNET_JSONAPI_document_get_resource(json_obj, 0)); 786 res = (GNUNET_JSONAPI_document_get_resource(json_obj, 0));
787 if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type(res, 787 if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type(res,
788 GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO)) 788 GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO))
789 { 789 {
790 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 790 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
791 "Resource not a credential!\n"); 791 "Resource not a credential!\n");
792 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 792 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
793 "Unable to parse JSONAPI Object from %s\n", 793 "Unable to parse JSONAPI Object from %s\n",
794 term_data); 794 term_data);
795 GNUNET_JSONAPI_document_delete (json_obj); 795 GNUNET_JSONAPI_document_delete(json_obj);
796 GNUNET_SCHEDULER_add_now (&do_error, handle); 796 GNUNET_SCHEDULER_add_now(&do_error, handle);
797 return; 797 return;
798 } 798 }
799 cred_json = GNUNET_JSONAPI_resource_read_attr (res, 799 cred_json = GNUNET_JSONAPI_resource_read_attr(res,
800 GNUNET_REST_JSONAPI_CREDENTIAL); 800 GNUNET_REST_JSONAPI_CREDENTIAL);
801 801
802 GNUNET_assert (json_is_array (cred_json)); 802 GNUNET_assert(json_is_array(cred_json));
803 803
804 credential_count = json_array_size(cred_json); 804 credential_count = json_array_size(cred_json);
805 805
806 struct GNUNET_CREDENTIAL_Credential credentials[credential_count]; 806 struct GNUNET_CREDENTIAL_Credential credentials[credential_count];
807 for (i=0;i<credential_count;i++) 807 for (i = 0; i < credential_count; i++)
808 {
809 cred = json_to_credential (json_array_get (cred_json, i));
810 if (NULL == cred)
811 { 808 {
812 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 809 cred = json_to_credential(json_array_get(cred_json, i));
813 "Unable to parse credential!\n"); 810 if (NULL == cred)
814 continue; 811 {
812 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
813 "Unable to parse credential!\n");
814 continue;
815 }
816 GNUNET_memcpy(&credentials[i],
817 cred,
818 sizeof(struct GNUNET_CREDENTIAL_Credential));
819 credentials[i].issuer_attribute = GNUNET_strdup(cred->issuer_attribute);
820 GNUNET_free(cred);
815 } 821 }
816 GNUNET_memcpy (&credentials[i],
817 cred,
818 sizeof (struct GNUNET_CREDENTIAL_Credential));
819 credentials[i].issuer_attribute = GNUNET_strdup (cred->issuer_attribute);
820 GNUNET_free (cred);
821 }
822 GNUNET_JSONAPI_document_delete(json_obj); 822 GNUNET_JSONAPI_document_delete(json_obj);
823 handle->verify_request = GNUNET_CREDENTIAL_verify (handle->credential, 823 handle->verify_request = GNUNET_CREDENTIAL_verify(handle->credential,
824 &handle->issuer_key, 824 &handle->issuer_key,
825 handle->issuer_attr, 825 handle->issuer_attr,
826 &handle->subject_key, 826 &handle->subject_key,
827 credential_count, 827 credential_count,
828 credentials, 828 credentials,
829 &handle_verify_response, 829 &handle_verify_response,
830 handle); 830 handle);
831 for (i=0;i<credential_count;i++) 831 for (i = 0; i < credential_count; i++)
832 GNUNET_free ((char*)credentials[i].issuer_attribute); 832 GNUNET_free((char*)credentials[i].issuer_attribute);
833
834} 833}
835 834
836void 835void
837send_cred_response (struct RequestHandle *handle, 836send_cred_response(struct RequestHandle *handle,
838 struct GNUNET_CREDENTIAL_Credential *cred) 837 struct GNUNET_CREDENTIAL_Credential *cred)
839{ 838{
840 struct MHD_Response *resp; 839 struct MHD_Response *resp;
841 struct GNUNET_JSONAPI_Document *json_document; 840 struct GNUNET_JSONAPI_Document *json_document;
@@ -847,64 +846,64 @@ send_cred_response (struct RequestHandle *handle,
847 char *signature; 846 char *signature;
848 char *id; 847 char *id;
849 848
850 GNUNET_assert (NULL != cred); 849 GNUNET_assert(NULL != cred);
851 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key); 850 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->issuer_key);
852 if (NULL == issuer) 851 if (NULL == issuer)
853 { 852 {
854 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 853 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
855 "Subject malformed\n"); 854 "Subject malformed\n");
856 GNUNET_free (issuer); 855 GNUNET_free(issuer);
857 return; 856 return;
858 } 857 }
859 GNUNET_asprintf (&id, 858 GNUNET_asprintf(&id,
860 "%s.%s", 859 "%s.%s",
861 issuer, 860 issuer,
862 (char*)&cred[1]); 861 (char*)&cred[1]);
863 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key); 862 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->subject_key);
864 if (NULL == subject) 863 if (NULL == subject)
865 { 864 {
866 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 865 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
867 "Subject malformed\n"); 866 "Subject malformed\n");
868 GNUNET_free (id); 867 GNUNET_free(id);
869 GNUNET_free (issuer); 868 GNUNET_free(issuer);
870 return; 869 return;
871 } 870 }
872 GNUNET_STRINGS_base64_encode ((char*)&cred->signature, 871 GNUNET_STRINGS_base64_encode((char*)&cred->signature,
873 sizeof (struct GNUNET_CRYPTO_EcdsaSignature), 872 sizeof(struct GNUNET_CRYPTO_EcdsaSignature),
874 &signature); 873 &signature);
875 json_document = GNUNET_JSONAPI_document_new (); 874 json_document = GNUNET_JSONAPI_document_new();
876 json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO, 875 json_resource = GNUNET_JSONAPI_resource_new(GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO,
877 id); 876 id);
878 GNUNET_free (id); 877 GNUNET_free(id);
879 cred_obj = json_object(); 878 cred_obj = json_object();
880 json_object_set_new (cred_obj, "issuer", json_string (issuer)); 879 json_object_set_new(cred_obj, "issuer", json_string(issuer));
881 json_object_set_new (cred_obj, "subject", json_string (subject)); 880 json_object_set_new(cred_obj, "subject", json_string(subject));
882 json_object_set_new (cred_obj, "expiration", json_integer( cred->expiration.abs_value_us)); 881 json_object_set_new(cred_obj, "expiration", json_integer(cred->expiration.abs_value_us));
883 json_object_set_new (cred_obj, "signature", json_string (signature)); 882 json_object_set_new(cred_obj, "signature", json_string(signature));
884 GNUNET_JSONAPI_resource_add_attr (json_resource, 883 GNUNET_JSONAPI_resource_add_attr(json_resource,
885 GNUNET_REST_JSONAPI_CREDENTIAL, 884 GNUNET_REST_JSONAPI_CREDENTIAL,
886 cred_obj); 885 cred_obj);
887 GNUNET_JSONAPI_document_resource_add (json_document, json_resource); 886 GNUNET_JSONAPI_document_resource_add(json_document, json_resource);
888 GNUNET_JSONAPI_document_serialize (json_document, &result); 887 GNUNET_JSONAPI_document_serialize(json_document, &result);
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 888 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
890 "Result %s\n", 889 "Result %s\n",
891 result); 890 result);
892 json_decref (cred_obj); 891 json_decref(cred_obj);
893 GNUNET_JSONAPI_document_delete (json_document); 892 GNUNET_JSONAPI_document_delete(json_document);
894 resp = GNUNET_REST_create_response (result); 893 resp = GNUNET_REST_create_response(result);
895 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 894 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
896 GNUNET_free (result); 895 GNUNET_free(result);
897 GNUNET_free (signature); 896 GNUNET_free(signature);
898 GNUNET_free (issuer); 897 GNUNET_free(issuer);
899 GNUNET_free (subject); 898 GNUNET_free(subject);
900 cleanup_handle (handle); 899 cleanup_handle(handle);
901} 900}
902 901
903void 902void
904get_cred_issuer_cb (void *cls, 903get_cred_issuer_cb(void *cls,
905 struct GNUNET_IDENTITY_Ego *ego, 904 struct GNUNET_IDENTITY_Ego *ego,
906 void **ctx, 905 void **ctx,
907 const char *name) 906 const char *name)
908{ 907{
909 struct RequestHandle *handle = cls; 908 struct RequestHandle *handle = cls;
910 struct GNUNET_TIME_Absolute etime_abs; 909 struct GNUNET_TIME_Absolute etime_abs;
@@ -918,156 +917,158 @@ get_cred_issuer_cb (void *cls,
918 handle->id_op = NULL; 917 handle->id_op = NULL;
919 918
920 if (NULL == name) 919 if (NULL == name)
921 { 920 {
922 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 921 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
923 "Issuer not configured!\n"); 922 "Issuer not configured!\n");
924 GNUNET_SCHEDULER_add_now (&do_error, handle); 923 GNUNET_SCHEDULER_add_now(&do_error, handle);
925 return; 924 return;
926 } 925 }
927 926
928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 927 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
929 "Connecting to credential service...\n"); 928 "Connecting to credential service...\n");
930 handle->credential = GNUNET_CREDENTIAL_connect (cfg); 929 handle->credential = GNUNET_CREDENTIAL_connect(cfg);
931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 930 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
932 "Connected\n"); 931 "Connected\n");
933 if (NULL == handle->credential) 932 if (NULL == handle->credential)
934 { 933 {
935 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 934 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
936 "Connecting to CREDENTIAL failed\n"); 935 "Connecting to CREDENTIAL failed\n");
937 GNUNET_SCHEDULER_add_now (&do_error, handle); 936 GNUNET_SCHEDULER_add_now(&do_error, handle);
938 return; 937 return;
939 } 938 }
940 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_EXPIRATION, 939 GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_EXPIRATION,
941 strlen (GNUNET_REST_JSONAPI_CREDENTIAL_EXPIRATION), 940 strlen(GNUNET_REST_JSONAPI_CREDENTIAL_EXPIRATION),
942 &key); 941 &key);
943 if ( GNUNET_NO == 942 if (GNUNET_NO ==
944 GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle->url_param_map, 943 GNUNET_CONTAINER_multihashmap_contains(handle->rest_handle->url_param_map,
945 &key) ) 944 &key))
946 { 945 {
947 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 946 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
948 "Missing expiration\n"); 947 "Missing expiration\n");
949 GNUNET_SCHEDULER_add_now (&do_error, handle); 948 GNUNET_SCHEDULER_add_now(&do_error, handle);
950 return; 949 return;
951 } 950 }
952 expiration_str = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, 951 expiration_str = GNUNET_CONTAINER_multihashmap_get(handle->rest_handle->url_param_map,
953 &key); 952 &key);
954 if ( NULL == expiration_str ) 953 if (NULL == expiration_str)
955 { 954 {
956 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 955 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
957 "Expiration malformed\n"); 956 "Expiration malformed\n");
958 GNUNET_SCHEDULER_add_now (&do_error, handle); 957 GNUNET_SCHEDULER_add_now(&do_error, handle);
959 return; 958 return;
960 } 959 }
961 960
962 if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative (expiration_str, 961 if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative(expiration_str,
963 &etime_rel)) 962 &etime_rel))
964 { 963 {
965 etime_abs = GNUNET_TIME_relative_to_absolute (etime_rel); 964 etime_abs = GNUNET_TIME_relative_to_absolute(etime_rel);
966 } else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (expiration_str, 965 }
967 &etime_abs)) 966 else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute(expiration_str,
968 { 967 &etime_abs))
969 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 968 {
970 "Malformed expiration: %s\n", expiration_str); 969 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
971 GNUNET_SCHEDULER_add_now (&do_error, handle); 970 "Malformed expiration: %s\n", expiration_str);
972 return; 971 GNUNET_SCHEDULER_add_now(&do_error, handle);
973 } 972 return;
974 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR, 973 }
975 strlen (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR), 974 GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR,
976 &key); 975 strlen(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR),
977 if ( GNUNET_NO == 976 &key);
978 GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle->url_param_map, 977 if (GNUNET_NO ==
979 &key) ) 978 GNUNET_CONTAINER_multihashmap_contains(handle->rest_handle->url_param_map,
980 { 979 &key))
981 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 980 {
982 "Missing issuer attribute\n"); 981 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
983 GNUNET_SCHEDULER_add_now (&do_error, handle); 982 "Missing issuer attribute\n");
984 return; 983 GNUNET_SCHEDULER_add_now(&do_error, handle);
985 } 984 return;
985 }
986 handle->issuer_attr = GNUNET_strdup(GNUNET_CONTAINER_multihashmap_get 986 handle->issuer_attr = GNUNET_strdup(GNUNET_CONTAINER_multihashmap_get
987 (handle->rest_handle->url_param_map, 987 (handle->rest_handle->url_param_map,
988 &key)); 988 &key));
989 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY, 989 GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY,
990 strlen (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY), 990 strlen(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY),
991 &key); 991 &key);
992 if ( GNUNET_NO == 992 if (GNUNET_NO ==
993 GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle->url_param_map, 993 GNUNET_CONTAINER_multihashmap_contains(handle->rest_handle->url_param_map,
994 &key) ) 994 &key))
995 { 995 {
996 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 996 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
997 "Missing subject\n"); 997 "Missing subject\n");
998 GNUNET_SCHEDULER_add_now (&do_error, handle); 998 GNUNET_SCHEDULER_add_now(&do_error, handle);
999 return; 999 return;
1000 } 1000 }
1001 tmp = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, 1001 tmp = GNUNET_CONTAINER_multihashmap_get(handle->rest_handle->url_param_map,
1002 &key); 1002 &key);
1003 if (NULL == tmp) 1003 if (NULL == tmp)
1004 { 1004 {
1005 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1005 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1006 "Malformed subject\n"); 1006 "Malformed subject\n");
1007 GNUNET_SCHEDULER_add_now (&do_error, handle); 1007 GNUNET_SCHEDULER_add_now(&do_error, handle);
1008 return; 1008 return;
1009 } 1009 }
1010 if (GNUNET_OK != 1010 if (GNUNET_OK !=
1011 GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp, 1011 GNUNET_CRYPTO_ecdsa_public_key_from_string(tmp,
1012 strlen (tmp), 1012 strlen(tmp),
1013 &handle->subject_key)) { 1013 &handle->subject_key))
1014 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1014 {
1015 "Malformed subject key\n"); 1015 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1016 GNUNET_SCHEDULER_add_now (&do_error, handle); 1016 "Malformed subject key\n");
1017 return; 1017 GNUNET_SCHEDULER_add_now(&do_error, handle);
1018 } 1018 return;
1019 issuer_key = GNUNET_IDENTITY_ego_get_private_key (ego); 1019 }
1020 cred = GNUNET_CREDENTIAL_credential_issue (issuer_key, 1020 issuer_key = GNUNET_IDENTITY_ego_get_private_key(ego);
1021 &handle->subject_key, 1021 cred = GNUNET_CREDENTIAL_credential_issue(issuer_key,
1022 handle->issuer_attr, 1022 &handle->subject_key,
1023 &etime_abs); 1023 handle->issuer_attr,
1024 &etime_abs);
1024 if (NULL == cred) 1025 if (NULL == cred)
1025 { 1026 {
1026 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1027 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1027 "Failed to create credential\n"); 1028 "Failed to create credential\n");
1028 GNUNET_SCHEDULER_add_now (&do_error, handle); 1029 GNUNET_SCHEDULER_add_now(&do_error, handle);
1029 return; 1030 return;
1030 } 1031 }
1031 send_cred_response (handle, cred); 1032 send_cred_response(handle, cred);
1032} 1033}
1033 1034
1034 1035
1035static void 1036static void
1036issue_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle, 1037issue_cred_cont(struct GNUNET_REST_RequestHandle *conndata_handle,
1037 const char* url, 1038 const char* url,
1038 void *cls) 1039 void *cls)
1039{ 1040{
1040 struct RequestHandle *handle = cls; 1041 struct RequestHandle *handle = cls;
1041 1042
1042 handle->identity = GNUNET_IDENTITY_connect (cfg, 1043 handle->identity = GNUNET_IDENTITY_connect(cfg,
1043 NULL, 1044 NULL,
1044 NULL); 1045 NULL);
1045 handle->id_op = GNUNET_IDENTITY_get(handle->identity, 1046 handle->id_op = GNUNET_IDENTITY_get(handle->identity,
1046 "credential-issuer", 1047 "credential-issuer",
1047 &get_cred_issuer_cb, 1048 &get_cred_issuer_cb,
1048 handle); 1049 handle);
1049 handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout, 1050 handle->timeout_task = GNUNET_SCHEDULER_add_delayed(handle->timeout,
1050 &do_error, 1051 &do_error,
1051 handle); 1052 handle);
1052} 1053}
1053 1054
1054static void 1055static void
1055options_cont (struct GNUNET_REST_RequestHandle *con_handle, 1056options_cont(struct GNUNET_REST_RequestHandle *con_handle,
1056 const char* url, 1057 const char* url,
1057 void *cls) 1058 void *cls)
1058{ 1059{
1059 struct MHD_Response *resp; 1060 struct MHD_Response *resp;
1060 struct RequestHandle *handle = cls; 1061 struct RequestHandle *handle = cls;
1061 1062
1062 //For GNS, independent of path return all options 1063 //For GNS, independent of path return all options
1063 resp = GNUNET_REST_create_response (NULL); 1064 resp = GNUNET_REST_create_response(NULL);
1064 MHD_add_response_header (resp, 1065 MHD_add_response_header(resp,
1065 "Access-Control-Allow-Methods", 1066 "Access-Control-Allow-Methods",
1066 MHD_HTTP_METHOD_GET); 1067 MHD_HTTP_METHOD_GET);
1067 handle->proc (handle->proc_cls, 1068 handle->proc(handle->proc_cls,
1068 resp, 1069 resp,
1069 MHD_HTTP_OK); 1070 MHD_HTTP_OK);
1070 cleanup_handle (handle); 1071 cleanup_handle(handle);
1071} 1072}
1072 1073
1073 1074
@@ -1076,7 +1077,7 @@ rest_credential_process_request(struct GNUNET_REST_RequestHandle *conndata_handl
1076 GNUNET_REST_ResultProcessor proc, 1077 GNUNET_REST_ResultProcessor proc,
1077 void *proc_cls) 1078 void *proc_cls)
1078{ 1079{
1079 struct RequestHandle *handle = GNUNET_new (struct RequestHandle); 1080 struct RequestHandle *handle = GNUNET_new(struct RequestHandle);
1080 struct GNUNET_REST_RequestHandlerError err; 1081 struct GNUNET_REST_RequestHandlerError err;
1081 1082
1082 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1083 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
@@ -1085,21 +1086,21 @@ rest_credential_process_request(struct GNUNET_REST_RequestHandle *conndata_handl
1085 handle->rest_handle = conndata_handle; 1086 handle->rest_handle = conndata_handle;
1086 1087
1087 static const struct GNUNET_REST_RequestHandler handlers[] = { 1088 static const struct GNUNET_REST_RequestHandler handlers[] = {
1088 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_CREDENTIAL_VERIFY, &verify_cred_cont}, 1089 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_CREDENTIAL_VERIFY, &verify_cred_cont },
1089 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_CREDENTIAL_COLLECT, &collect_cred_cont}, 1090 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_CREDENTIAL_COLLECT, &collect_cred_cont },
1090 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_CREDENTIAL_ISSUE, &issue_cred_cont}, 1091 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_CREDENTIAL_ISSUE, &issue_cred_cont },
1091 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_CREDENTIAL, &options_cont}, 1092 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_CREDENTIAL, &options_cont },
1092 GNUNET_REST_HANDLER_END 1093 GNUNET_REST_HANDLER_END
1093 }; 1094 };
1094 1095
1095 if (GNUNET_NO == GNUNET_JSONAPI_handle_request (conndata_handle, 1096 if (GNUNET_NO == GNUNET_JSONAPI_handle_request(conndata_handle,
1096 handlers, 1097 handlers,
1097 &err, 1098 &err,
1098 handle)) 1099 handle))
1099 { 1100 {
1100 handle->response_code = err.error_code; 1101 handle->response_code = err.error_code;
1101 GNUNET_SCHEDULER_add_now (&do_error, handle); 1102 GNUNET_SCHEDULER_add_now(&do_error, handle);
1102 } 1103 }
1103} 1104}
1104 1105
1105 1106
@@ -1110,22 +1111,23 @@ rest_credential_process_request(struct GNUNET_REST_RequestHandle *conndata_handl
1110 * @return NULL on error, otherwise the plugin context 1111 * @return NULL on error, otherwise the plugin context
1111 */ 1112 */
1112void * 1113void *
1113libgnunet_plugin_rest_credential_init (void *cls) 1114libgnunet_plugin_rest_credential_init(void *cls)
1114{ 1115{
1115 static struct Plugin plugin; 1116 static struct Plugin plugin;
1117
1116 cfg = cls; 1118 cfg = cls;
1117 struct GNUNET_REST_Plugin *api; 1119 struct GNUNET_REST_Plugin *api;
1118 1120
1119 if (NULL != plugin.cfg) 1121 if (NULL != plugin.cfg)
1120 return NULL; /* can only initialize once! */ 1122 return NULL; /* can only initialize once! */
1121 memset (&plugin, 0, sizeof (struct Plugin)); 1123 memset(&plugin, 0, sizeof(struct Plugin));
1122 plugin.cfg = cfg; 1124 plugin.cfg = cfg;
1123 api = GNUNET_new (struct GNUNET_REST_Plugin); 1125 api = GNUNET_new(struct GNUNET_REST_Plugin);
1124 api->cls = &plugin; 1126 api->cls = &plugin;
1125 api->name = GNUNET_REST_API_NS_CREDENTIAL; 1127 api->name = GNUNET_REST_API_NS_CREDENTIAL;
1126 api->process_request = &rest_credential_process_request; 1128 api->process_request = &rest_credential_process_request;
1127 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1129 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1128 _("GNS REST API initialized\n")); 1130 _("GNS REST API initialized\n"));
1129 return api; 1131 return api;
1130} 1132}
1131 1133
@@ -1137,15 +1139,15 @@ libgnunet_plugin_rest_credential_init (void *cls)
1137 * @return always NULL 1139 * @return always NULL
1138 */ 1140 */
1139void * 1141void *
1140libgnunet_plugin_rest_credential_done (void *cls) 1142libgnunet_plugin_rest_credential_done(void *cls)
1141{ 1143{
1142 struct GNUNET_REST_Plugin *api = cls; 1144 struct GNUNET_REST_Plugin *api = cls;
1143 struct Plugin *plugin = api->cls; 1145 struct Plugin *plugin = api->cls;
1144 1146
1145 plugin->cfg = NULL; 1147 plugin->cfg = NULL;
1146 GNUNET_free (api); 1148 GNUNET_free(api);
1147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1149 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1148 "GNS REST plugin is finished\n"); 1150 "GNS REST plugin is finished\n");
1149 return NULL; 1151 return NULL;
1150} 1152}
1151 1153