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