From f12a22a2a9b6d71f0fc9d24940e77d84d6568da0 Mon Sep 17 00:00:00 2001 From: "Schanzenbach, Martin" Date: Sat, 7 Oct 2017 11:08:04 +0200 Subject: [PATCH] -add api impl for revocation --- .../gnunet-service-identity-provider.c | 2 +- src/identity-provider/identity_provider.h | 2 +- src/identity-provider/identity_provider_api.c | 107 +++++++++++++++++- .../gnunet_identity_provider_service.h | 2 +- 4 files changed, 104 insertions(+), 9 deletions(-) diff --git a/src/identity-provider/gnunet-service-identity-provider.c b/src/identity-provider/gnunet-service-identity-provider.c index b4cf154b4..f9d3f3f92 100644 --- a/src/identity-provider/gnunet-service-identity-provider.c +++ b/src/identity-provider/gnunet-service-identity-provider.c @@ -1768,7 +1768,7 @@ attr_store_cont (void *cls, { struct AttributeStoreHandle *as_handle = cls; struct GNUNET_MQ_Envelope *env; - struct AttributeStoreResponseMessage *acr_msg; + struct AttributeStoreResultMessage *acr_msg; if (GNUNET_SYSERR == success) { diff --git a/src/identity-provider/identity_provider.h b/src/identity-provider/identity_provider.h index cb0f1591d..be9fdc6f5 100644 --- a/src/identity-provider/identity_provider.h +++ b/src/identity-provider/identity_provider.h @@ -65,7 +65,7 @@ struct AttributeStoreMessage /** * Attribute store response message */ -struct AttributeStoreResponseMessage +struct AttributeStoreResultMessage { /** * Message header diff --git a/src/identity-provider/identity_provider_api.c b/src/identity-provider/identity_provider_api.c index 97ecc691c..fb9926a2c 100644 --- a/src/identity-provider/identity_provider_api.c +++ b/src/identity-provider/identity_provider_api.c @@ -72,6 +72,11 @@ struct GNUNET_IDENTITY_PROVIDER_Operation * Attribute result callback */ GNUNET_IDENTITY_PROVIDER_AttributeResult ar_cb; + + /** + * Revocation result callback + */ + GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus rvk_cb; /** * Ticket result callback @@ -400,7 +405,7 @@ mq_error_handler (void *cls, */ static void handle_attribute_store_response (void *cls, - const struct AttributeStoreResponseMessage *msg) + const struct AttributeStoreResultMessage *msg) { struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls; struct GNUNET_IDENTITY_PROVIDER_Operation *op; @@ -716,6 +721,48 @@ handle_ticket_result (void *cls, GNUNET_break (0); } +/** + * Handle an incoming message of type + * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT + * + * @param cls + * @param msg the message we received + */ +static void +handle_revoke_ticket_result (void *cls, + const struct RevokeTicketResultMessage *msg) +{ + struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls; + struct GNUNET_IDENTITY_PROVIDER_Operation *op; + uint32_t r_id = ntohl (msg->id); + int32_t success; + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Processing revocation result.\n"); + + + for (op = h->op_head; NULL != op; op = op->next) + if (op->r_id == r_id) + break; + if (NULL == op) + return; + success = ntohl (msg->success); + { + if (NULL != op->rvk_cb) + { + op->rvk_cb (op->cls, + success, + NULL); + } + GNUNET_CONTAINER_DLL_remove (h->op_head, + h->op_tail, + op); + GNUNET_free (op); + return; + } + GNUNET_assert (0); +} + /** @@ -729,7 +776,7 @@ reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h) struct GNUNET_MQ_MessageHandler handlers[] = { GNUNET_MQ_hd_fixed_size (attribute_store_response, GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE_RESPONSE, - struct AttributeStoreResponseMessage, + struct AttributeStoreResultMessage, h), GNUNET_MQ_hd_var_size (attribute_result, GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT, @@ -743,6 +790,10 @@ reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h) GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT, struct ConsumeTicketResultMessage, h), + GNUNET_MQ_hd_fixed_size (revoke_ticket_result, + GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT, + struct RevokeTicketResultMessage, + h), GNUNET_MQ_handler_end () }; struct GNUNET_IDENTITY_PROVIDER_Operation *op; @@ -1077,10 +1128,10 @@ GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *h */ struct GNUNET_IDENTITY_PROVIDER_Operation * GNUNET_IDENTITY_PROVIDER_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Handle *h, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, - const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, - GNUNET_IDENTITY_PROVIDER_AttributeResult cb, - void *cb_cls) + const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, + const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, + GNUNET_IDENTITY_PROVIDER_AttributeResult cb, + void *cb_cls) { struct GNUNET_IDENTITY_PROVIDER_Operation *op; struct ConsumeTicketMessage *ctm; @@ -1280,6 +1331,50 @@ GNUNET_IDENTITY_PROVIDER_ticket_iteration_stop (struct GNUNET_IDENTITY_PROVIDER_ GNUNET_free (it); } +/** + * Revoked an issued ticket. The relying party will be unable to retrieve + * updated attributes. + * + * @param id the identity provider to use + * @param identity the issuing identity + * @param ticket the ticket to revoke + * @param cb the callback + * @param cb_cls the callback closure + * @return handle to abort the operation + */ +struct GNUNET_IDENTITY_PROVIDER_Operation * +GNUNET_IDENTITY_PROVIDER_ticket_revoke (struct GNUNET_IDENTITY_PROVIDER_Handle *h, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, + const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, + GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cb, + void *cb_cls) +{ + struct GNUNET_IDENTITY_PROVIDER_Operation *op; + struct GNUNET_MQ_Envelope *env; + struct RevokeTicketMessage *msg; + uint32_t rid; + + rid = h->r_id_gen++; + op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation); + op->h = h; + op->rvk_cb = cb; + op->cls = cb_cls; + op->r_id = rid; + GNUNET_CONTAINER_DLL_insert_tail (h->op_head, + h->op_tail, + op); + env = GNUNET_MQ_msg (msg, + GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET); + msg->id = htonl (rid); + msg->identity = *identity; + if (NULL == h->mq) + op->env = env; + else + GNUNET_MQ_send (h->mq, + env); + return op; +} + /* end of identity_provider_api.c */ diff --git a/src/include/gnunet_identity_provider_service.h b/src/include/gnunet_identity_provider_service.h index d1b437128..fa4d4536c 100644 --- a/src/include/gnunet_identity_provider_service.h +++ b/src/include/gnunet_identity_provider_service.h @@ -326,7 +326,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *i GNUNET_IDENTITY_PROVIDER_TicketCallback cb, void *cb_cls); -/** TODO +/** * Revoked an issued ticket. The relying party will be unable to retrieve * updated attributes. * -- 2.25.1