aboutsummaryrefslogtreecommitdiff
path: root/src/identity-provider/identity_provider_api.c
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2017-10-06 16:50:32 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2017-10-06 16:50:32 +0200
commitcc838240da0d28fa1fc6d7a97da2808a7a622365 (patch)
tree49603d5a1e1db330863b3465ef052ca6f9b2b04e /src/identity-provider/identity_provider_api.c
parent7807374c7247af1d139ff70b4af047c227229a6e (diff)
downloadgnunet-cc838240da0d28fa1fc6d7a97da2808a7a622365.tar.gz
gnunet-cc838240da0d28fa1fc6d7a97da2808a7a622365.zip
-remove deprecated
Diffstat (limited to 'src/identity-provider/identity_provider_api.c')
-rw-r--r--src/identity-provider/identity_provider_api.c362
1 files changed, 6 insertions, 356 deletions
diff --git a/src/identity-provider/identity_provider_api.c b/src/identity-provider/identity_provider_api.c
index 6ef1d470e..d623eaf3b 100644
--- a/src/identity-provider/identity_provider_api.c
+++ b/src/identity-provider/identity_provider_api.c
@@ -64,18 +64,6 @@ struct GNUNET_IDENTITY_PROVIDER_Operation
64 const struct GNUNET_MessageHeader *msg; 64 const struct GNUNET_MessageHeader *msg;
65 65
66 /** 66 /**
67 * Continuation to invoke with the result of the transmission; @e cb
68 * will be NULL in this case.
69 */
70 GNUNET_IDENTITY_PROVIDER_ExchangeCallback ex_cb;
71
72 /**
73 * Continuation to invoke with the result of the transmission for
74 * 'issue' operations (@e cont will be NULL in this case).
75 */
76 GNUNET_IDENTITY_PROVIDER_IssueCallback iss_cb;
77
78 /**
79 * Continuation to invoke after attribute store call 67 * Continuation to invoke after attribute store call
80 */ 68 */
81 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus as_cb; 69 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus as_cb;
@@ -404,151 +392,6 @@ mq_error_handler (void *cls,
404} 392}
405 393
406/** 394/**
407 * Check validity of message received from the service
408 *
409 * @param cls the `struct GNUNET_IDENTITY_PROVIDER_Handle *`
410 * @param result_msg the incoming message
411 */
412static int
413check_exchange_result (void *cls,
414 const struct ExchangeResultMessage *erm)
415{
416 char *str;
417 size_t size = ntohs (erm->header.size);
418
419
420 str = (char *) &erm[0];
421 if ( (size > sizeof (struct ExchangeResultMessage)) &&
422 ('\0' != str[size - 1]) )
423 {
424 GNUNET_break (0);
425 return GNUNET_SYSERR;
426 }
427 return GNUNET_OK;
428}
429
430
431/**
432 * Check validity of message received from the service
433 *
434 * @param cls the `struct GNUNET_IDENTITY_PROVIDER_Handle *`
435 * @param result_msg the incoming message
436 */
437static int
438check_result (void *cls,
439 const struct IssueResultMessage *irm)
440{
441 char *str;
442 size_t size = ntohs (irm->header.size);
443 str = (char*) &irm[0];
444 if ( (size > sizeof (struct IssueResultMessage)) &&
445 ('\0' != str[size - 1]) )
446 {
447 GNUNET_break (0);
448 return GNUNET_SYSERR;
449 }
450 return GNUNET_OK;
451}
452
453/**
454 * Handler for messages received from the GNS service
455 *
456 * @param cls the `struct GNUNET_GNS_Handle *`
457 * @param loookup_msg the incoming message
458 */
459static void
460handle_exchange_result (void *cls,
461 const struct ExchangeResultMessage *erm)
462{
463 struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls;
464 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
465 struct GNUNET_IDENTITY_PROVIDER_Token token;
466 uint64_t ticket_nonce;
467 uint32_t r_id = ntohl (erm->id);
468 char *str;
469
470 for (op = handle->op_head; NULL != op; op = op->next)
471 if (op->r_id == r_id)
472 break;
473 if (NULL == op)
474 return;
475 str = GNUNET_strdup ((char*)&erm[1]);
476 op = handle->op_head;
477 GNUNET_CONTAINER_DLL_remove (handle->op_head,
478 handle->op_tail,
479 op);
480 token.data = str;
481 ticket_nonce = ntohl (erm->ticket_nonce);
482 if (NULL != op->ex_cb)
483 op->ex_cb (op->cls, &token, ticket_nonce);
484 GNUNET_free (str);
485 GNUNET_free (op);
486
487}
488
489/**
490 * Handler for messages received from the GNS service
491 *
492 * @param cls the `struct GNUNET_GNS_Handle *`
493 * @param loookup_msg the incoming message
494 */
495static void
496handle_result (void *cls,
497 const struct IssueResultMessage *irm)
498{
499 struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls;
500 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
501 struct GNUNET_IDENTITY_PROVIDER_Token token;
502 struct GNUNET_IDENTITY_PROVIDER_Ticket ticket;
503 uint32_t r_id = ntohl (irm->id);
504 char *str;
505 char *label_str;
506 char *ticket_str;
507 char *token_str;
508
509 for (op = handle->op_head; NULL != op; op = op->next)
510 if (op->r_id == r_id)
511 break;
512 if (NULL == op)
513 return;
514 str = GNUNET_strdup ((char*)&irm[1]);
515 label_str = strtok (str, ",");
516
517 if (NULL == label_str)
518 {
519 GNUNET_free (str);
520 GNUNET_break (0);
521 return;
522 }
523 ticket_str = strtok (NULL, ",");
524 if (NULL == ticket_str)
525 {
526 GNUNET_free (str);
527 GNUNET_break (0);
528 return;
529 }
530 token_str = strtok (NULL, ",");
531 if (NULL == token_str)
532 {
533 GNUNET_free (str);
534 GNUNET_break (0);
535 return;
536 }
537 GNUNET_CONTAINER_DLL_remove (handle->op_head,
538 handle->op_tail,
539 op);
540 ticket.data = ticket_str;
541 token.data = token_str;
542 if (NULL != op->iss_cb)
543 op->iss_cb (op->cls, label_str, &ticket, &token);
544 GNUNET_free (str);
545 GNUNET_free (op);
546
547}
548
549
550
551/**
552 * Handle an incoming message of type 395 * Handle an incoming message of type
553 * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE 396 * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE
554 * 397 *
@@ -824,7 +667,7 @@ handle_ticket_result (void *cls,
824 struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls; 667 struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls;
825 struct GNUNET_IDENTITY_PROVIDER_Operation *op; 668 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
826 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it; 669 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it;
827 const struct GNUNET_IDENTITY_PROVIDER_Ticket2 *ticket; 670 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket;
828 uint32_t r_id = ntohl (msg->id); 671 uint32_t r_id = ntohl (msg->id);
829 size_t msg_len; 672 size_t msg_len;
830 673
@@ -847,7 +690,7 @@ handle_ticket_result (void *cls,
847 if (NULL != op->tr_cb) 690 if (NULL != op->tr_cb)
848 op->tr_cb (op->cls, NULL); 691 op->tr_cb (op->cls, NULL);
849 } else { 692 } else {
850 ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket2 *)&msg[1]; 693 ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket *)&msg[1];
851 if (NULL != op->tr_cb) 694 if (NULL != op->tr_cb)
852 op->tr_cb (op->cls, ticket); 695 op->tr_cb (op->cls, ticket);
853 } 696 }
@@ -863,7 +706,7 @@ handle_ticket_result (void *cls,
863 it->finish_cb (it->finish_cb_cls); 706 it->finish_cb (it->finish_cb_cls);
864 } else { 707 } else {
865 708
866 ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket2 *)&msg[1]; 709 ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket *)&msg[1];
867 if (NULL != it->tr_cb) 710 if (NULL != it->tr_cb)
868 it->tr_cb (it->cls, ticket); 711 it->tr_cb (it->cls, ticket);
869 } 712 }
@@ -888,14 +731,6 @@ reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h)
888 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE_RESPONSE, 731 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE_RESPONSE,
889 struct AttributeStoreResponseMessage, 732 struct AttributeStoreResponseMessage,
890 h), 733 h),
891 GNUNET_MQ_hd_var_size (result,
892 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE_RESULT,
893 struct IssueResultMessage,
894 h),
895 GNUNET_MQ_hd_var_size (exchange_result,
896 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_EXCHANGE_RESULT,
897 struct ExchangeResultMessage,
898 h),
899 GNUNET_MQ_hd_var_size (attribute_result, 734 GNUNET_MQ_hd_var_size (attribute_result,
900 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT, 735 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT,
901 struct AttributeResultMessage, 736 struct AttributeResultMessage,
@@ -953,117 +788,6 @@ GNUNET_IDENTITY_PROVIDER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
953 788
954 789
955/** 790/**
956 * Issue an identity token
957 *
958 * @param id identity service to query
959 * @param service_name for which service is an identity wanted
960 * @param cb function to call with the result (will only be called once)
961 * @param cb_cls closure for @a cb
962 * @return handle to abort the operation
963 */
964struct GNUNET_IDENTITY_PROVIDER_Operation *
965GNUNET_IDENTITY_PROVIDER_issue_token (struct GNUNET_IDENTITY_PROVIDER_Handle *id,
966 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss_key,
967 const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
968 const char* scopes,
969 const char* vattr,
970 struct GNUNET_TIME_Absolute expiration,
971 uint64_t nonce,
972 GNUNET_IDENTITY_PROVIDER_IssueCallback cb,
973 void *cb_cls)
974{
975 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
976 struct IssueMessage *im;
977 size_t slen;
978
979 slen = strlen (scopes) + 1;
980 if (NULL != vattr)
981 slen += strlen (vattr) + 1;
982 if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct IssueMessage))
983 {
984 GNUNET_break (0);
985 return NULL;
986 }
987 op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation);
988 op->h = id;
989 op->iss_cb = cb;
990 op->cls = cb_cls;
991 op->r_id = id->r_id_gen++;
992 op->env = GNUNET_MQ_msg_extra (im,
993 slen,
994 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE);
995 im->id = op->r_id;
996 im->iss_key = *iss_key;
997 im->aud_key = *aud_key;
998 im->scope_len = htonl (strlen(scopes)+1);
999 im->nonce = htonl (nonce);
1000 im->expiration = GNUNET_TIME_absolute_hton (expiration);
1001 GNUNET_memcpy (&im[1], scopes, strlen(scopes));
1002 if (NULL != vattr)
1003 GNUNET_memcpy ((char*)&im[1]+strlen(scopes)+1, vattr, strlen(vattr));
1004 GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
1005 id->op_tail,
1006 op);
1007 if (NULL != id->mq)
1008 GNUNET_MQ_send_copy (id->mq,
1009 op->env);
1010 return op;
1011}
1012
1013
1014/**
1015 * Exchange a token ticket for a token
1016 *
1017 * @param id identity provider service
1018 * @param ticket ticket to exchange
1019 * @param cont function to call once the operation finished
1020 * @param cont_cls closure for @a cont
1021 * @return handle to abort the operation
1022 */
1023struct GNUNET_IDENTITY_PROVIDER_Operation *
1024GNUNET_IDENTITY_PROVIDER_exchange_ticket (struct GNUNET_IDENTITY_PROVIDER_Handle *id,
1025 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
1026 const struct GNUNET_CRYPTO_EcdsaPrivateKey *aud_privkey,
1027 GNUNET_IDENTITY_PROVIDER_ExchangeCallback cont,
1028 void *cont_cls)
1029{
1030 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
1031 struct ExchangeMessage *em;
1032 size_t slen;
1033 char *ticket_str;
1034
1035 ticket_str = GNUNET_IDENTITY_PROVIDER_ticket_to_string (ticket);
1036
1037 slen = strlen (ticket_str) + 1;
1038 if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct ExchangeMessage))
1039 {
1040 GNUNET_free (ticket_str);
1041 GNUNET_break (0);
1042 return NULL;
1043 }
1044 op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation);
1045 op->h = id;
1046 op->ex_cb = cont;
1047 op->cls = cont_cls;
1048 op->r_id = id->r_id_gen++;
1049 op->env = GNUNET_MQ_msg_extra (em,
1050 slen,
1051 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_EXCHANGE);
1052 em->aud_privkey = *aud_privkey;
1053 em->id = htonl (op->r_id);
1054 GNUNET_memcpy (&em[1], ticket_str, slen);
1055 GNUNET_free (ticket_str);
1056 GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
1057 id->op_tail,
1058 op);
1059 if (NULL != id->mq)
1060 GNUNET_MQ_send_copy (id->mq,
1061 op->env);
1062 return op;
1063}
1064
1065
1066/**
1067 * Cancel an operation. Note that the operation MAY still 791 * Cancel an operation. Note that the operation MAY still
1068 * be executed; this merely cancels the continuation; if the request 792 * be executed; this merely cancels the continuation; if the request
1069 * was already transmitted, the service may still choose to complete 793 * was already transmitted, the service may still choose to complete
@@ -1108,80 +832,6 @@ GNUNET_IDENTITY_PROVIDER_disconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h)
1108} 832}
1109 833
1110/** 834/**
1111 * Convenience API
1112 */
1113
1114
1115/**
1116 * Destroy token
1117 *
1118 * @param token the token
1119 */
1120void
1121GNUNET_IDENTITY_PROVIDER_token_destroy(struct GNUNET_IDENTITY_PROVIDER_Token *token)
1122{
1123 GNUNET_assert (NULL != token);
1124 if (NULL != token->data)
1125 GNUNET_free (token->data);
1126 GNUNET_free (token);
1127}
1128
1129/**
1130 * Returns string representation of token. A JSON-Web-Token.
1131 *
1132 * @param token the token
1133 * @return The JWT (must be freed)
1134 */
1135char *
1136GNUNET_IDENTITY_PROVIDER_token_to_string (const struct GNUNET_IDENTITY_PROVIDER_Token *token)
1137{
1138 return GNUNET_strdup (token->data);
1139}
1140
1141/**
1142 * Returns string representation of ticket. Base64-Encoded
1143 *
1144 * @param ticket the ticket
1145 * @return the Base64-Encoded ticket
1146 */
1147char *
1148GNUNET_IDENTITY_PROVIDER_ticket_to_string (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket)
1149{
1150 return GNUNET_strdup (ticket->data);
1151}
1152
1153/**
1154 * Created a ticket from a string (Base64 encoded ticket)
1155 *
1156 * @param input Base64 encoded ticket
1157 * @param ticket pointer where the ticket is stored
1158 * @return GNUNET_OK
1159 */
1160int
1161GNUNET_IDENTITY_PROVIDER_string_to_ticket (const char* input,
1162 struct GNUNET_IDENTITY_PROVIDER_Ticket **ticket)
1163{
1164 *ticket = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
1165 (*ticket)->data = GNUNET_strdup (input);
1166 return GNUNET_OK;
1167}
1168
1169
1170/**
1171 * Destroys a ticket
1172 *
1173 * @param ticket the ticket to destroy
1174 */
1175void
1176GNUNET_IDENTITY_PROVIDER_ticket_destroy(struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket)
1177{
1178 GNUNET_assert (NULL != ticket);
1179 if (NULL != ticket->data)
1180 GNUNET_free (ticket->data);
1181 GNUNET_free (ticket);
1182}
1183
1184/**
1185 * Store an attribute. If the attribute is already present, 835 * Store an attribute. If the attribute is already present,
1186 * it is replaced with the new attribute. 836 * it is replaced with the new attribute.
1187 * 837 *
@@ -1428,7 +1078,7 @@ GNUNET_IDENTITY_PROVIDER_idp_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handl
1428struct GNUNET_IDENTITY_PROVIDER_Operation * 1078struct GNUNET_IDENTITY_PROVIDER_Operation *
1429GNUNET_IDENTITY_PROVIDER_rp_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Handle *h, 1079GNUNET_IDENTITY_PROVIDER_rp_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
1430 const struct GNUNET_CRYPTO_EcdsaPrivateKey * identity, 1080 const struct GNUNET_CRYPTO_EcdsaPrivateKey * identity,
1431 const struct GNUNET_IDENTITY_PROVIDER_Ticket2 *ticket, 1081 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
1432 GNUNET_IDENTITY_PROVIDER_AttributeResult cb, 1082 GNUNET_IDENTITY_PROVIDER_AttributeResult cb,
1433 void *cb_cls) 1083 void *cb_cls)
1434{ 1084{
@@ -1444,14 +1094,14 @@ GNUNET_IDENTITY_PROVIDER_rp_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Hand
1444 h->op_tail, 1094 h->op_tail,
1445 op); 1095 op);
1446 op->env = GNUNET_MQ_msg_extra (ctm, 1096 op->env = GNUNET_MQ_msg_extra (ctm,
1447 sizeof (const struct GNUNET_IDENTITY_PROVIDER_Ticket2), 1097 sizeof (const struct GNUNET_IDENTITY_PROVIDER_Ticket),
1448 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET); 1098 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET);
1449 ctm->identity = *identity; 1099 ctm->identity = *identity;
1450 ctm->id = htonl (op->r_id); 1100 ctm->id = htonl (op->r_id);
1451 1101
1452 GNUNET_memcpy ((char*)&ctm[1], 1102 GNUNET_memcpy ((char*)&ctm[1],
1453 ticket, 1103 ticket,
1454 sizeof (const struct GNUNET_IDENTITY_PROVIDER_Ticket2)); 1104 sizeof (const struct GNUNET_IDENTITY_PROVIDER_Ticket));
1455 1105
1456 if (NULL != h->mq) 1106 if (NULL != h->mq)
1457 GNUNET_MQ_send_copy (h->mq, 1107 GNUNET_MQ_send_copy (h->mq,