diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2016-12-28 18:40:17 +0100 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2016-12-28 18:40:17 +0100 |
commit | a84624407eedd5418d36de590571da47d2f47015 (patch) | |
tree | 2f8d9fd84df5f1dba55a4e85c7d98722cc42cada /src/credential/credential_api.c | |
parent | 43b34377e10d329075327104e4a295ee9d3c53b4 (diff) | |
download | gnunet-a84624407eedd5418d36de590571da47d2f47015.tar.gz gnunet-a84624407eedd5418d36de590571da47d2f47015.zip |
-change api
Diffstat (limited to 'src/credential/credential_api.c')
-rw-r--r-- | src/credential/credential_api.c | 142 |
1 files changed, 111 insertions, 31 deletions
diff --git a/src/credential/credential_api.c b/src/credential/credential_api.c index e991b4153..b201d4d9c 100644 --- a/src/credential/credential_api.c +++ b/src/credential/credential_api.c | |||
@@ -61,7 +61,7 @@ struct GNUNET_CREDENTIAL_Request | |||
61 | /** | 61 | /** |
62 | * processor to call on verify result | 62 | * processor to call on verify result |
63 | */ | 63 | */ |
64 | GNUNET_CREDENTIAL_VerifyResultProcessor verify_proc; | 64 | GNUNET_CREDENTIAL_CredentialResultProcessor verify_proc; |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * @e verify_proc closure | 67 | * @e verify_proc closure |
@@ -100,12 +100,12 @@ struct GNUNET_CREDENTIAL_Handle | |||
100 | /** | 100 | /** |
101 | * Head of linked list of active verify requests. | 101 | * Head of linked list of active verify requests. |
102 | */ | 102 | */ |
103 | struct GNUNET_CREDENTIAL_Request *verify_head; | 103 | struct GNUNET_CREDENTIAL_Request *request_head; |
104 | 104 | ||
105 | /** | 105 | /** |
106 | * Tail of linked list of active verify requests. | 106 | * Tail of linked list of active verify requests. |
107 | */ | 107 | */ |
108 | struct GNUNET_CREDENTIAL_Request *verify_tail; | 108 | struct GNUNET_CREDENTIAL_Request *request_tail; |
109 | 109 | ||
110 | /** | 110 | /** |
111 | * Reconnect task | 111 | * Reconnect task |
@@ -185,7 +185,6 @@ mq_error_handler (void *cls, | |||
185 | force_reconnect (handle); | 185 | force_reconnect (handle); |
186 | } | 186 | } |
187 | 187 | ||
188 | |||
189 | /** | 188 | /** |
190 | * Check validity of message received from the CREDENTIAL service | 189 | * Check validity of message received from the CREDENTIAL service |
191 | * | 190 | * |
@@ -194,7 +193,7 @@ mq_error_handler (void *cls, | |||
194 | */ | 193 | */ |
195 | static int | 194 | static int |
196 | check_result (void *cls, | 195 | check_result (void *cls, |
197 | const struct VerifyResultMessage *vr_msg) | 196 | const struct DelegationChainResultMessage *vr_msg) |
198 | { | 197 | { |
199 | //TODO | 198 | //TODO |
200 | return GNUNET_OK; | 199 | return GNUNET_OK; |
@@ -209,7 +208,7 @@ check_result (void *cls, | |||
209 | */ | 208 | */ |
210 | static void | 209 | static void |
211 | handle_result (void *cls, | 210 | handle_result (void *cls, |
212 | const struct VerifyResultMessage *vr_msg) | 211 | const struct DelegationChainResultMessage *vr_msg) |
213 | { | 212 | { |
214 | struct GNUNET_CREDENTIAL_Handle *handle = cls; | 213 | struct GNUNET_CREDENTIAL_Handle *handle = cls; |
215 | uint32_t r_id = ntohl (vr_msg->id); | 214 | uint32_t r_id = ntohl (vr_msg->id); |
@@ -219,30 +218,30 @@ handle_result (void *cls, | |||
219 | uint32_t c_count = ntohl (vr_msg->c_count); | 218 | uint32_t c_count = ntohl (vr_msg->c_count); |
220 | struct GNUNET_CREDENTIAL_Delegation d_chain[d_count]; | 219 | struct GNUNET_CREDENTIAL_Delegation d_chain[d_count]; |
221 | struct GNUNET_CREDENTIAL_Credential creds[c_count]; | 220 | struct GNUNET_CREDENTIAL_Credential creds[c_count]; |
222 | GNUNET_CREDENTIAL_VerifyResultProcessor proc; | 221 | GNUNET_CREDENTIAL_CredentialResultProcessor proc; |
223 | void *proc_cls; | 222 | void *proc_cls; |
224 | 223 | ||
225 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 224 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
226 | "Received verify reply from CREDENTIAL service\n"); | 225 | "Received verify reply from CREDENTIAL service\n"); |
227 | for (vr = handle->verify_head; NULL != vr; vr = vr->next) | 226 | for (vr = handle->request_head; NULL != vr; vr = vr->next) |
228 | if (vr->r_id == r_id) | 227 | if (vr->r_id == r_id) |
229 | break; | 228 | break; |
230 | if (NULL == vr) | 229 | if (NULL == vr) |
231 | return; | 230 | return; |
232 | proc = vr->verify_proc; | 231 | proc = vr->verify_proc; |
233 | proc_cls = vr->proc_cls; | 232 | proc_cls = vr->proc_cls; |
234 | GNUNET_CONTAINER_DLL_remove (handle->verify_head, | 233 | GNUNET_CONTAINER_DLL_remove (handle->request_head, |
235 | handle->verify_tail, | 234 | handle->request_tail, |
236 | vr); | 235 | vr); |
237 | GNUNET_MQ_discard (vr->env); | 236 | GNUNET_MQ_discard (vr->env); |
238 | GNUNET_free (vr); | 237 | GNUNET_free (vr); |
239 | GNUNET_assert (GNUNET_OK == | 238 | GNUNET_assert (GNUNET_OK == |
240 | GNUNET_CREDENTIAL_delegation_chain_deserialize (mlen, | 239 | GNUNET_CREDENTIAL_delegation_chain_deserialize (mlen, |
241 | (const char*) &vr_msg[1], | 240 | (const char*) &vr_msg[1], |
242 | d_count, | 241 | d_count, |
243 | d_chain, | 242 | d_chain, |
244 | c_count, | 243 | c_count, |
245 | creds)); | 244 | creds)); |
246 | if (GNUNET_NO == ntohl (vr_msg->cred_found)) | 245 | if (GNUNET_NO == ntohl (vr_msg->cred_found)) |
247 | { | 246 | { |
248 | proc (proc_cls, | 247 | proc (proc_cls, |
@@ -271,7 +270,11 @@ reconnect (struct GNUNET_CREDENTIAL_Handle *handle) | |||
271 | struct GNUNET_MQ_MessageHandler handlers[] = { | 270 | struct GNUNET_MQ_MessageHandler handlers[] = { |
272 | GNUNET_MQ_hd_var_size (result, | 271 | GNUNET_MQ_hd_var_size (result, |
273 | GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT, | 272 | GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT, |
274 | struct VerifyResultMessage, | 273 | struct DelegationChainResultMessage, |
274 | handle), | ||
275 | GNUNET_MQ_hd_var_size (result, | ||
276 | GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT_RESULT, | ||
277 | struct DelegationChainResultMessage, | ||
275 | handle), | 278 | handle), |
276 | GNUNET_MQ_handler_end () | 279 | GNUNET_MQ_handler_end () |
277 | }; | 280 | }; |
@@ -287,7 +290,7 @@ reconnect (struct GNUNET_CREDENTIAL_Handle *handle) | |||
287 | handle); | 290 | handle); |
288 | if (NULL == handle->mq) | 291 | if (NULL == handle->mq) |
289 | return; | 292 | return; |
290 | for (vr = handle->verify_head; NULL != vr; vr = vr->next) | 293 | for (vr = handle->request_head; NULL != vr; vr = vr->next) |
291 | GNUNET_MQ_send_copy (handle->mq, | 294 | GNUNET_MQ_send_copy (handle->mq, |
292 | vr->env); | 295 | vr->env); |
293 | } | 296 | } |
@@ -334,7 +337,7 @@ GNUNET_CREDENTIAL_disconnect (struct GNUNET_CREDENTIAL_Handle *handle) | |||
334 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); | 337 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); |
335 | handle->reconnect_task = NULL; | 338 | handle->reconnect_task = NULL; |
336 | } | 339 | } |
337 | GNUNET_assert (NULL == handle->verify_head); | 340 | GNUNET_assert (NULL == handle->request_head); |
338 | GNUNET_free (handle); | 341 | GNUNET_free (handle); |
339 | } | 342 | } |
340 | 343 | ||
@@ -349,13 +352,81 @@ GNUNET_CREDENTIAL_verify_cancel (struct GNUNET_CREDENTIAL_Request *vr) | |||
349 | { | 352 | { |
350 | struct GNUNET_CREDENTIAL_Handle *handle = vr->credential_handle; | 353 | struct GNUNET_CREDENTIAL_Handle *handle = vr->credential_handle; |
351 | 354 | ||
352 | GNUNET_CONTAINER_DLL_remove (handle->verify_head, | 355 | GNUNET_CONTAINER_DLL_remove (handle->request_head, |
353 | handle->verify_tail, | 356 | handle->request_tail, |
354 | vr); | 357 | vr); |
355 | GNUNET_MQ_discard (vr->env); | 358 | GNUNET_MQ_discard (vr->env); |
356 | GNUNET_free (vr); | 359 | GNUNET_free (vr); |
357 | } | 360 | } |
358 | 361 | ||
362 | |||
363 | /** | ||
364 | * Performs attribute collection. | ||
365 | * Collects all credentials of subject to fulfill the | ||
366 | * attribute, if possible | ||
367 | * | ||
368 | * @param handle handle to the Credential service | ||
369 | * @param issuer_key the issuer public key | ||
370 | * @param issuer_attribute the issuer attribute | ||
371 | * @param subject_key the subject public key | ||
372 | * @param credential_count number of credentials provided | ||
373 | * @param credentials subject credentials | ||
374 | * @param proc function to call on result | ||
375 | * @param proc_cls closure for processor | ||
376 | * @return handle to the queued request | ||
377 | */ | ||
378 | struct GNUNET_CREDENTIAL_Request* | ||
379 | GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle, | ||
380 | const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, | ||
381 | const char *issuer_attribute, | ||
382 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *subject_key, | ||
383 | GNUNET_CREDENTIAL_CredentialResultProcessor proc, | ||
384 | void *proc_cls) | ||
385 | { | ||
386 | /* IPC to shorten credential names, return shorten_handle */ | ||
387 | struct CollectMessage *c_msg; | ||
388 | struct GNUNET_CREDENTIAL_Request *vr; | ||
389 | size_t nlen; | ||
390 | |||
391 | if (NULL == issuer_attribute) | ||
392 | { | ||
393 | GNUNET_break (0); | ||
394 | return NULL; | ||
395 | } | ||
396 | |||
397 | //DEBUG LOG | ||
398 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
399 | "Trying to collect `%s' in CREDENTIAL\n", | ||
400 | issuer_attribute); | ||
401 | nlen = strlen (issuer_attribute) + 1; | ||
402 | if (nlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*vr)) | ||
403 | { | ||
404 | GNUNET_break (0); | ||
405 | return NULL; | ||
406 | } | ||
407 | vr = GNUNET_new (struct GNUNET_CREDENTIAL_Request); | ||
408 | vr->credential_handle = handle; | ||
409 | vr->verify_proc = proc; | ||
410 | vr->proc_cls = proc_cls; | ||
411 | vr->r_id = handle->r_id_gen++; | ||
412 | vr->env = GNUNET_MQ_msg_extra (c_msg, | ||
413 | nlen, | ||
414 | GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT); | ||
415 | c_msg->id = htonl (vr->r_id); | ||
416 | c_msg->subject_key = *subject_key; | ||
417 | c_msg->issuer_key = *issuer_key; | ||
418 | c_msg->issuer_attribute_len = htons(strlen(issuer_attribute)); | ||
419 | GNUNET_memcpy (&c_msg[1], | ||
420 | issuer_attribute, | ||
421 | strlen (issuer_attribute)); | ||
422 | GNUNET_CONTAINER_DLL_insert (handle->request_head, | ||
423 | handle->request_tail, | ||
424 | vr); | ||
425 | if (NULL != handle->mq) | ||
426 | GNUNET_MQ_send_copy (handle->mq, | ||
427 | vr->env); | ||
428 | return vr; | ||
429 | } | ||
359 | /** | 430 | /** |
360 | * Performs attribute verification. | 431 | * Performs attribute verification. |
361 | * Checks if there is a delegation chain from | 432 | * Checks if there is a delegation chain from |
@@ -368,7 +439,8 @@ GNUNET_CREDENTIAL_verify_cancel (struct GNUNET_CREDENTIAL_Request *vr) | |||
368 | * @param issuer_key the issuer public key | 439 | * @param issuer_key the issuer public key |
369 | * @param issuer_attribute the issuer attribute | 440 | * @param issuer_attribute the issuer attribute |
370 | * @param subject_key the subject public key | 441 | * @param subject_key the subject public key |
371 | * @param subject_attribute the attribute claimed by the subject | 442 | * @param credential_count number of credentials provided |
443 | * @param credentials subject credentials | ||
372 | * @param proc function to call on result | 444 | * @param proc function to call on result |
373 | * @param proc_cls closure for processor | 445 | * @param proc_cls closure for processor |
374 | * @return handle to the queued request | 446 | * @return handle to the queued request |
@@ -378,25 +450,31 @@ GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle, | |||
378 | const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, | 450 | const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, |
379 | const char *issuer_attribute, | 451 | const char *issuer_attribute, |
380 | const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key, | 452 | const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key, |
381 | const char *subject_attribute, | 453 | uint32_t credential_count, |
382 | GNUNET_CREDENTIAL_VerifyResultProcessor proc, | 454 | const struct GNUNET_CREDENTIAL_Credential *credentials, |
455 | GNUNET_CREDENTIAL_CredentialResultProcessor proc, | ||
383 | void *proc_cls) | 456 | void *proc_cls) |
384 | { | 457 | { |
385 | /* IPC to shorten credential names, return shorten_handle */ | 458 | /* IPC to shorten credential names, return shorten_handle */ |
386 | struct VerifyMessage *v_msg; | 459 | struct VerifyMessage *v_msg; |
387 | struct GNUNET_CREDENTIAL_Request *vr; | 460 | struct GNUNET_CREDENTIAL_Request *vr; |
388 | size_t nlen; | 461 | size_t nlen; |
462 | size_t clen; | ||
389 | 463 | ||
390 | if (NULL == issuer_attribute || NULL == subject_attribute) | 464 | if (NULL == issuer_attribute || NULL == credentials) |
391 | { | 465 | { |
392 | GNUNET_break (0); | 466 | GNUNET_break (0); |
393 | return NULL; | 467 | return NULL; |
394 | } | 468 | } |
469 | |||
470 | clen = GNUNET_CREDENTIAL_credentials_get_size (credential_count, | ||
471 | credentials); | ||
472 | |||
395 | //DEBUG LOG | 473 | //DEBUG LOG |
396 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 474 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
397 | "Trying to verify `%s' in CREDENTIAL\n", | 475 | "Trying to verify `%s' in CREDENTIAL\n", |
398 | issuer_attribute); | 476 | issuer_attribute); |
399 | nlen = strlen (issuer_attribute) + strlen (subject_attribute) + 1; | 477 | nlen = strlen (issuer_attribute) + 1 + clen; |
400 | if (nlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*vr)) | 478 | if (nlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*vr)) |
401 | { | 479 | { |
402 | GNUNET_break (0); | 480 | GNUNET_break (0); |
@@ -412,17 +490,19 @@ GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle, | |||
412 | GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY); | 490 | GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY); |
413 | v_msg->id = htonl (vr->r_id); | 491 | v_msg->id = htonl (vr->r_id); |
414 | v_msg->subject_key = *subject_key; | 492 | v_msg->subject_key = *subject_key; |
493 | v_msg->c_count = htonl(credential_count); | ||
415 | v_msg->issuer_key = *issuer_key; | 494 | v_msg->issuer_key = *issuer_key; |
416 | v_msg->issuer_attribute_len = htons(strlen(issuer_attribute)); | 495 | v_msg->issuer_attribute_len = htons(strlen(issuer_attribute)); |
417 | v_msg->subject_attribute_len = htons(strlen(subject_attribute)); | ||
418 | GNUNET_memcpy (&v_msg[1], | 496 | GNUNET_memcpy (&v_msg[1], |
419 | issuer_attribute, | 497 | issuer_attribute, |
420 | strlen (issuer_attribute)); | 498 | strlen (issuer_attribute)); |
421 | GNUNET_memcpy (((char*)&v_msg[1]) + strlen (issuer_attribute), | 499 | GNUNET_CREDENTIAL_credentials_serialize (credential_count, |
422 | subject_attribute, | 500 | credentials, |
423 | strlen (subject_attribute)); | 501 | clen, |
424 | GNUNET_CONTAINER_DLL_insert (handle->verify_head, | 502 | ((char*)&v_msg[1]) |
425 | handle->verify_tail, | 503 | + strlen (issuer_attribute) + 1); |
504 | GNUNET_CONTAINER_DLL_insert (handle->request_head, | ||
505 | handle->request_tail, | ||
426 | vr); | 506 | vr); |
427 | if (NULL != handle->mq) | 507 | if (NULL != handle->mq) |
428 | GNUNET_MQ_send_copy (handle->mq, | 508 | GNUNET_MQ_send_copy (handle->mq, |