aboutsummaryrefslogtreecommitdiff
path: root/src/identity/identity_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/identity/identity_api.c')
-rw-r--r--src/identity/identity_api.c209
1 files changed, 17 insertions, 192 deletions
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c
index 934ee31c6..d41e05104 100644
--- a/src/identity/identity_api.c
+++ b/src/identity/identity_api.c
@@ -279,13 +279,13 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h)
279 op); 279 op);
280 if (NULL != op->cont) 280 if (NULL != op->cont)
281 op->cont (op->cls, 281 op->cont (op->cls,
282 "Error in communication with the identity service"); 282 GNUNET_EC_SERVICE_COMMUNICATION_FAILED);
283 else if (NULL != op->cb) 283 else if (NULL != op->cb)
284 op->cb (op->cls, NULL, NULL, NULL); 284 op->cb (op->cls, NULL, NULL, NULL);
285 else if (NULL != op->create_cont) 285 else if (NULL != op->create_cont)
286 op->create_cont (op->cls, 286 op->create_cont (op->cls,
287 NULL, 287 NULL,
288 "Failed to communicate with the identity service"); 288 GNUNET_EC_SERVICE_COMMUNICATION_FAILED);
289 GNUNET_free (op); 289 GNUNET_free (op);
290 } 290 }
291 GNUNET_CONTAINER_multihashmap_iterate (h->egos, 291 GNUNET_CONTAINER_multihashmap_iterate (h->egos,
@@ -322,24 +322,6 @@ mq_error_handler (void *cls,
322 322
323 323
324/** 324/**
325 * We received a result code from the service. Check the message
326 * is well-formed.
327 *
328 * @param cls closure
329 * @param rcm result message received
330 * @return #GNUNET_OK if the message is well-formed
331 */
332static int
333check_identity_result_code (void *cls,
334 const struct ResultCodeMessage *rcm)
335{
336 if (sizeof(*rcm) != htons (rcm->header.size))
337 GNUNET_MQ_check_zero_termination (rcm);
338 return GNUNET_OK;
339}
340
341
342/**
343 * We received a result code from the service. 325 * We received a result code from the service.
344 * 326 *
345 * @param cls closure 327 * @param cls closure
@@ -351,8 +333,7 @@ handle_identity_result_code (void *cls,
351{ 333{
352 struct GNUNET_IDENTITY_Handle *h = cls; 334 struct GNUNET_IDENTITY_Handle *h = cls;
353 struct GNUNET_IDENTITY_Operation *op; 335 struct GNUNET_IDENTITY_Operation *op;
354 uint16_t size = ntohs (rcm->header.size) - sizeof(*rcm); 336 enum GNUNET_ErrorCode ec = ntohl (rcm->result_code);
355 const char *str = (0 == size) ? NULL : (const char *) &rcm[1];
356 337
357 op = h->op_head; 338 op = h->op_head;
358 if (NULL == op) 339 if (NULL == op)
@@ -363,11 +344,11 @@ handle_identity_result_code (void *cls,
363 } 344 }
364 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); 345 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
365 if (NULL != op->cont) 346 if (NULL != op->cont)
366 op->cont (op->cls, str); 347 op->cont (op->cls, ec);
367 else if (NULL != op->cb) 348 else if (NULL != op->cb)
368 op->cb (op->cls, NULL, NULL, NULL); 349 op->cb (op->cls, NULL, NULL, NULL);
369 else if (NULL != op->create_cont) 350 else if (NULL != op->create_cont)
370 op->create_cont (op->cls, (NULL == str) ? &op->pk : NULL, str); 351 op->create_cont (op->cls, (GNUNET_EC_NONE == ec) ? &op->pk : NULL, ec);
371 GNUNET_free (op); 352 GNUNET_free (op);
372} 353}
373 354
@@ -477,80 +458,6 @@ handle_identity_update (void *cls,
477 458
478 459
479/** 460/**
480 * Function called when we receive a set default message from the
481 * service.
482 *
483 * @param cls closure
484 * @param sdm message received
485 * @return #GNUNET_OK if the message is well-formed
486 */
487static int
488check_identity_set_default (void *cls,
489 const struct SetDefaultMessage *sdm)
490{
491 uint16_t size = ntohs (sdm->header.size) - sizeof(*sdm);
492 uint16_t name_len = ntohs (sdm->name_len);
493 const char *str = (const char *) &sdm[1];
494
495 if ((size != name_len) || ((0 != name_len) && ('\0' != str[name_len - 1])))
496 {
497 GNUNET_break (0);
498 return GNUNET_SYSERR;
499 }
500 GNUNET_break (0 == ntohs (sdm->reserved));
501 return GNUNET_OK;
502}
503
504
505/**
506 * Type of a function to call when we receive a message
507 * from the service.
508 *
509 * @param cls closure
510 * @param sdm message received
511 */
512static void
513handle_identity_set_default (void *cls,
514 const struct SetDefaultMessage *sdm)
515{
516 struct GNUNET_IDENTITY_Handle *h = cls;
517 struct GNUNET_IDENTITY_Operation *op;
518 struct GNUNET_HashCode id;
519 struct GNUNET_IDENTITY_Ego *ego;
520
521 GNUNET_CRYPTO_hash (&sdm->private_key,
522 sizeof(sdm->private_key),
523 &id);
524 ego = GNUNET_CONTAINER_multihashmap_get (h->egos,
525 &id);
526 if (NULL == ego)
527 {
528 GNUNET_break (0);
529 reschedule_connect (h);
530 return;
531 }
532 op = h->op_head;
533 if (NULL == op)
534 {
535 GNUNET_break (0);
536 reschedule_connect (h);
537 return;
538 }
539 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
540 "Received SET_DEFAULT message from identity service\n");
541 GNUNET_CONTAINER_DLL_remove (h->op_head,
542 h->op_tail,
543 op);
544 if (NULL != op->cb)
545 op->cb (op->cls,
546 ego,
547 &ego->ctx,
548 ego->name);
549 GNUNET_free (op);
550}
551
552
553/**
554 * Try again to connect to the identity service. 461 * Try again to connect to the identity service.
555 * 462 *
556 * @param cls handle to the identity service. 463 * @param cls handle to the identity service.
@@ -560,18 +467,14 @@ reconnect (void *cls)
560{ 467{
561 struct GNUNET_IDENTITY_Handle *h = cls; 468 struct GNUNET_IDENTITY_Handle *h = cls;
562 struct GNUNET_MQ_MessageHandler handlers[] = { 469 struct GNUNET_MQ_MessageHandler handlers[] = {
563 GNUNET_MQ_hd_var_size (identity_result_code, 470 GNUNET_MQ_hd_fixed_size (identity_result_code,
564 GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, 471 GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE,
565 struct ResultCodeMessage, 472 struct ResultCodeMessage,
566 h), 473 h),
567 GNUNET_MQ_hd_var_size (identity_update, 474 GNUNET_MQ_hd_var_size (identity_update,
568 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, 475 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE,
569 struct UpdateMessage, 476 struct UpdateMessage,
570 h), 477 h),
571 GNUNET_MQ_hd_var_size (identity_set_default,
572 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
573 struct SetDefaultMessage,
574 h),
575 GNUNET_MQ_handler_end () 478 GNUNET_MQ_handler_end ()
576 }; 479 };
577 struct GNUNET_MQ_Envelope *env; 480 struct GNUNET_MQ_Envelope *env;
@@ -662,88 +565,6 @@ GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego,
662 565
663 566
664struct GNUNET_IDENTITY_Operation * 567struct GNUNET_IDENTITY_Operation *
665GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h,
666 const char *service_name,
667 GNUNET_IDENTITY_Callback cb,
668 void *cb_cls)
669{
670 struct GNUNET_IDENTITY_Operation *op;
671 struct GNUNET_MQ_Envelope *env;
672 struct GetDefaultMessage *gdm;
673 size_t slen;
674
675 if (NULL == h->mq)
676 return NULL;
677 GNUNET_assert (NULL != h->cb);
678 slen = strlen (service_name) + 1;
679 if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct GetDefaultMessage))
680 {
681 GNUNET_break (0);
682 return NULL;
683 }
684 op = GNUNET_new (struct GNUNET_IDENTITY_Operation);
685 op->h = h;
686 op->cb = cb;
687 op->cls = cb_cls;
688 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
689 env =
690 GNUNET_MQ_msg_extra (gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT);
691 gdm->name_len = htons (slen);
692 gdm->reserved = htons (0);
693 GNUNET_memcpy (&gdm[1], service_name, slen);
694 GNUNET_MQ_send (h->mq, env);
695 return op;
696}
697
698
699/**
700 * Set the preferred/default identity for a service.
701 *
702 * @param h identity service to inform
703 * @param service_name for which service is an identity set
704 * @param ego new default identity to be set for this service
705 * @param cont function to call once the operation finished
706 * @param cont_cls closure for @a cont
707 * @return handle to abort the operation
708 */
709struct GNUNET_IDENTITY_Operation *
710GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h,
711 const char *service_name,
712 struct GNUNET_IDENTITY_Ego *ego,
713 GNUNET_IDENTITY_Continuation cont,
714 void *cont_cls)
715{
716 struct GNUNET_IDENTITY_Operation *op;
717 struct GNUNET_MQ_Envelope *env;
718 struct SetDefaultMessage *sdm;
719 size_t slen;
720
721 if (NULL == h->mq)
722 return NULL;
723 GNUNET_assert (NULL != h->cb);
724 slen = strlen (service_name) + 1;
725 if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct SetDefaultMessage))
726 {
727 GNUNET_break (0);
728 return NULL;
729 }
730 op = GNUNET_new (struct GNUNET_IDENTITY_Operation);
731 op->h = h;
732 op->cont = cont;
733 op->cls = cont_cls;
734 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
735 env =
736 GNUNET_MQ_msg_extra (sdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
737 sdm->name_len = htons (slen);
738 sdm->reserved = htons (0);
739 sdm->private_key = ego->pk;
740 GNUNET_memcpy (&sdm[1], service_name, slen);
741 GNUNET_MQ_send (h->mq, env);
742 return op;
743}
744
745
746struct GNUNET_IDENTITY_Operation *
747GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, 568GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
748 const char *name, 569 const char *name,
749 const struct GNUNET_IDENTITY_PrivateKey *privkey, 570 const struct GNUNET_IDENTITY_PrivateKey *privkey,
@@ -1119,11 +940,13 @@ GNUNET_IDENTITY_sign_raw_ (const struct
1119 { 940 {
1120 case GNUNET_IDENTITY_TYPE_ECDSA: 941 case GNUNET_IDENTITY_TYPE_ECDSA:
1121 return GNUNET_CRYPTO_ecdsa_sign_ (&(priv->ecdsa_key), purpose, 942 return GNUNET_CRYPTO_ecdsa_sign_ (&(priv->ecdsa_key), purpose,
1122 (struct GNUNET_CRYPTO_EcdsaSignature*)sig); 943 (struct
944 GNUNET_CRYPTO_EcdsaSignature*) sig);
1123 break; 945 break;
1124 case GNUNET_IDENTITY_TYPE_EDDSA: 946 case GNUNET_IDENTITY_TYPE_EDDSA:
1125 return GNUNET_CRYPTO_eddsa_sign_ (&(priv->eddsa_key), purpose, 947 return GNUNET_CRYPTO_eddsa_sign_ (&(priv->eddsa_key), purpose,
1126 (struct GNUNET_CRYPTO_EddsaSignature*)sig); 948 (struct
949 GNUNET_CRYPTO_EddsaSignature*) sig);
1127 break; 950 break;
1128 default: 951 default:
1129 GNUNET_break (0); 952 GNUNET_break (0);
@@ -1202,12 +1025,14 @@ GNUNET_IDENTITY_signature_verify_raw_ (uint32_t purpose,
1202 { 1025 {
1203 case GNUNET_IDENTITY_TYPE_ECDSA: 1026 case GNUNET_IDENTITY_TYPE_ECDSA:
1204 return GNUNET_CRYPTO_ecdsa_verify_ (purpose, validate, 1027 return GNUNET_CRYPTO_ecdsa_verify_ (purpose, validate,
1205 (struct GNUNET_CRYPTO_EcdsaSignature*)sig, 1028 (struct
1029 GNUNET_CRYPTO_EcdsaSignature*) sig,
1206 &(pub->ecdsa_key)); 1030 &(pub->ecdsa_key));
1207 break; 1031 break;
1208 case GNUNET_IDENTITY_TYPE_EDDSA: 1032 case GNUNET_IDENTITY_TYPE_EDDSA:
1209 return GNUNET_CRYPTO_eddsa_verify_ (purpose, validate, 1033 return GNUNET_CRYPTO_eddsa_verify_ (purpose, validate,
1210 (struct GNUNET_CRYPTO_EddsaSignature*)sig, 1034 (struct
1035 GNUNET_CRYPTO_EddsaSignature*) sig,
1211 &(pub->eddsa_key)); 1036 &(pub->eddsa_key));
1212 break; 1037 break;
1213 default: 1038 default: