gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

commit 87948bf6eece00bfa6f3fe5b3787b8626c6de37b
parent 597404615c3d7793b88ababe3410cffadc3f7715
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Sat, 29 Oct 2022 21:36:05 +0900

-fix revocation API

Diffstat:
Msrc/messenger/gnunet-service-messenger.c | 2+-
Msrc/revocation/gnunet-service-revocation.c | 46+++++++++++++++++++++++++++++++++++++++-------
Msrc/revocation/revocation.h | 7+++----
Msrc/revocation/revocation_api.c | 10++++++----
Msrc/revocation/test_revocation.c | 6+++---
5 files changed, 52 insertions(+), 19 deletions(-)

diff --git a/src/messenger/gnunet-service-messenger.c b/src/messenger/gnunet-service-messenger.c @@ -225,7 +225,7 @@ check_send_message (void *cls, return GNUNET_NO; const uint16_t msg_length = length - key_length; - const char*msg_buffer = buffer + key_length; + const char *msg_buffer = buffer + key_length; struct GNUNET_MESSENGER_Message message; diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c @@ -221,6 +221,23 @@ client_disconnect_cb (void *cls, GNUNET_assert (client == app_cls); } +static int +check_query_message (void *cls, + const struct QueryMessage *qm) +{ + uint16_t size; + + size = ntohs (qm->header.size); + if (size <= sizeof(struct RevokeMessage) || + (size > UINT16_MAX)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + return GNUNET_OK; + +} + /** * Handle QUERY message from client. @@ -233,13 +250,27 @@ handle_query_message (void *cls, const struct QueryMessage *qm) { struct GNUNET_SERVICE_Client *client = cls; + struct GNUNET_IDENTITY_PublicKey zone; struct GNUNET_MQ_Envelope *env; struct QueryResponseMessage *qrm; struct GNUNET_HashCode hc; int res; - - GNUNET_CRYPTO_hash (&qm->key, - sizeof(struct GNUNET_IDENTITY_PublicKey), + size_t key_len; + size_t read; + + key_len = ntohl (qm->key_len); + if ((GNUNET_SYSERR == + GNUNET_IDENTITY_read_public_key_from_buffer (&qm[1], key_len, + &zone, &read)) || + (read != key_len)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unable to parse query public key\n"); + GNUNET_SERVICE_client_drop (client); + return; + } + GNUNET_CRYPTO_hash (&qm[1], + key_len, &hc); res = GNUNET_CONTAINER_multihashmap_contains (revocation_map, &hc); @@ -316,6 +347,7 @@ publicize_rm (const struct RevokeMessage *rm) const struct GNUNET_IDENTITY_PublicKey *pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; + /** FIXME yeah this works, but should we have a key length somewhere? */ pklen = GNUNET_IDENTITY_public_key_get_length (pk); if (0 > pklen) { @@ -1000,10 +1032,10 @@ GNUNET_SERVICE_MAIN &client_connect_cb, &client_disconnect_cb, NULL, - GNUNET_MQ_hd_fixed_size (query_message, - GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, - struct QueryMessage, - NULL), + GNUNET_MQ_hd_var_size (query_message, + GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, + struct QueryMessage, + NULL), GNUNET_MQ_hd_var_size (revoke_message, GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, struct RevokeMessage, diff --git a/src/revocation/revocation.h b/src/revocation/revocation.h @@ -42,14 +42,13 @@ struct QueryMessage struct GNUNET_MessageHeader header; /** - * For alignment. + * Key length. */ - uint32_t reserved GNUNET_PACKED; + uint32_t key_len GNUNET_PACKED; /** - * Key to check. + * Followed by the public key to check. */ - struct GNUNET_IDENTITY_PublicKey key; }; diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c @@ -175,6 +175,7 @@ GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg, }; struct QueryMessage *qm; struct GNUNET_MQ_Envelope *env; + size_t key_len; q->mq = GNUNET_CLIENT_connect (cfg, "revocation", @@ -188,10 +189,11 @@ GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg, } q->func = func; q->func_cls = func_cls; - env = GNUNET_MQ_msg (qm, - GNUNET_MESSAGE_TYPE_REVOCATION_QUERY); - qm->reserved = htonl (0); - qm->key = *key; + key_len = GNUNET_IDENTITY_public_key_get_length (key); + env = GNUNET_MQ_msg_extra (qm, key_len, + GNUNET_MESSAGE_TYPE_REVOCATION_QUERY); + GNUNET_IDENTITY_write_public_key_to_buffer (key, &qm[1], key_len); + qm->key_len = htonl (key_len); GNUNET_MQ_send (q->mq, env); return q; diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c @@ -195,16 +195,16 @@ ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) static void identity_create_cb (void *cls, const struct GNUNET_IDENTITY_PrivateKey *pk, - const char *emsg) + enum GNUNET_ErrorCode ec) { static int completed = 0; - if ((NULL == emsg) && (cls == &testpeers[0])) + if ((GNUNET_EC_NONE == ec) && (cls == &testpeers[0])) { testpeers[0].create_id_op = NULL; completed++; } - if ((NULL == emsg) && (cls == &testpeers[1])) + if ((GNUNET_EC_NONE == ec) && (cls == &testpeers[1])) { testpeers[1].create_id_op = NULL; completed++;