diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-12-01 18:31:59 +0900 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-12-01 18:31:59 +0900 |
commit | a25fa8cf399e0257a71a7c854fe9055ed0c58ab6 (patch) | |
tree | 9aec651707bccfd5e406962987f128b719244a28 /src | |
parent | c0ab1e5de5ad45d05c5f81a7bf4b782da5f11626 (diff) | |
download | gnunet-a25fa8cf399e0257a71a7c854fe9055ed0c58ab6.tar.gz gnunet-a25fa8cf399e0257a71a7c854fe9055ed0c58ab6.zip |
-more return value for payload processing that may fail
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/gnunet-service-tng.c | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c index e7bb813b7..dc470ca0e 100644 --- a/src/transport/gnunet-service-tng.c +++ b/src/transport/gnunet-service-tng.c | |||
@@ -4680,8 +4680,9 @@ dv_setup_key_state_from_km (const struct GNUNET_HashCode *km, | |||
4680 | * @param target the target peer to encrypt to | 4680 | * @param target the target peer to encrypt to |
4681 | * @param iv unique IV to use | 4681 | * @param iv unique IV to use |
4682 | * @param[out] key set to the key material | 4682 | * @param[out] key set to the key material |
4683 | * @return GNUNET_OK on success | ||
4683 | */ | 4684 | */ |
4684 | static void | 4685 | static enum GNUNET_GenericReturnValue |
4685 | dh_key_derive_eph_pid ( | 4686 | dh_key_derive_eph_pid ( |
4686 | const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral, | 4687 | const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral, |
4687 | const struct GNUNET_PeerIdentity *target, | 4688 | const struct GNUNET_PeerIdentity *target, |
@@ -4690,10 +4691,14 @@ dh_key_derive_eph_pid ( | |||
4690 | { | 4691 | { |
4691 | struct GNUNET_HashCode km; | 4692 | struct GNUNET_HashCode km; |
4692 | 4693 | ||
4693 | GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_ecdh_eddsa (priv_ephemeral, | 4694 | if (GNUNET_YES != GNUNET_CRYPTO_ecdh_eddsa (priv_ephemeral, |
4694 | &target->public_key, | 4695 | &target->public_key, |
4695 | &km)); | 4696 | &km)) |
4697 | return GNUNET_SYSERR; | ||
4698 | // FIXME: Possibly also add return values here. We are processing | ||
4699 | // Input from other peers... | ||
4696 | dv_setup_key_state_from_km (&km, iv, key); | 4700 | dv_setup_key_state_from_km (&km, iv, key); |
4701 | return GNUNET_OK; | ||
4697 | } | 4702 | } |
4698 | 4703 | ||
4699 | 4704 | ||
@@ -4705,18 +4710,21 @@ dh_key_derive_eph_pid ( | |||
4705 | * @param target the target peer to encrypt to | 4710 | * @param target the target peer to encrypt to |
4706 | * @param iv unique IV to use | 4711 | * @param iv unique IV to use |
4707 | * @param[out] key set to the key material | 4712 | * @param[out] key set to the key material |
4713 | * @return GNUNET_OK on success | ||
4708 | */ | 4714 | */ |
4709 | static void | 4715 | static enum GNUNET_GenericReturnValue |
4710 | dh_key_derive_eph_pub (const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral, | 4716 | dh_key_derive_eph_pub (const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral, |
4711 | const struct GNUNET_ShortHashCode *iv, | 4717 | const struct GNUNET_ShortHashCode *iv, |
4712 | struct DVKeyState *key) | 4718 | struct DVKeyState *key) |
4713 | { | 4719 | { |
4714 | struct GNUNET_HashCode km; | 4720 | struct GNUNET_HashCode km; |
4715 | 4721 | ||
4716 | GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_eddsa_ecdh (GST_my_private_key, | 4722 | if (GNUNET_YES != GNUNET_CRYPTO_eddsa_ecdh (GST_my_private_key, |
4717 | pub_ephemeral, | 4723 | pub_ephemeral, |
4718 | &km)); | 4724 | &km)) |
4725 | return GNUNET_SYSERR; | ||
4719 | dv_setup_key_state_from_km (&km, iv, key); | 4726 | dv_setup_key_state_from_km (&km, iv, key); |
4727 | return GNUNET_OK; | ||
4720 | } | 4728 | } |
4721 | 4729 | ||
4722 | 4730 | ||
@@ -4850,7 +4858,11 @@ encapsulate_for_dv (struct DistanceVector *dv, | |||
4850 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, | 4858 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, |
4851 | &box_hdr.iv, | 4859 | &box_hdr.iv, |
4852 | sizeof(box_hdr.iv)); | 4860 | sizeof(box_hdr.iv)); |
4853 | dh_key_derive_eph_pid (&dv->private_key, &dv->target, &box_hdr.iv, key); | 4861 | // We are creating this key, so this must work. |
4862 | GNUNET_assert (GNUNET_OK == | ||
4863 | dh_key_derive_eph_pid (&dv->private_key, | ||
4864 | &dv->target, | ||
4865 | &box_hdr.iv, key)); | ||
4854 | payload_hdr.sender = GST_my_identity; | 4866 | payload_hdr.sender = GST_my_identity; |
4855 | payload_hdr.monotonic_time = GNUNET_TIME_absolute_hton (dv->monotime); | 4867 | payload_hdr.monotonic_time = GNUNET_TIME_absolute_hton (dv->monotime); |
4856 | dv_encrypt (key, &payload_hdr, enc, sizeof(payload_hdr)); | 4868 | dv_encrypt (key, &payload_hdr, enc, sizeof(payload_hdr)); |
@@ -8228,7 +8240,14 @@ handle_dv_box (void *cls, const struct TransportDVBoxMessage *dvb) | |||
8228 | GNUNET_NO); | 8240 | GNUNET_NO); |
8229 | cmc->total_hops = ntohs (dvb->total_hops); | 8241 | cmc->total_hops = ntohs (dvb->total_hops); |
8230 | 8242 | ||
8231 | dh_key_derive_eph_pub (&dvb->ephemeral_key, &dvb->iv, &key); | 8243 | // DH key derivation with received DV, could be garbage. |
8244 | if (GNUNET_OK != | ||
8245 | dh_key_derive_eph_pub (&dvb->ephemeral_key, &dvb->iv, &key)) | ||
8246 | { | ||
8247 | GNUNET_break_op (0); | ||
8248 | finish_cmc_handling (cmc); | ||
8249 | return; | ||
8250 | } | ||
8232 | hdr = (const char *) &dvb[1]; | 8251 | hdr = (const char *) &dvb[1]; |
8233 | hdr_len = ntohs (dvb->orig_size) - sizeof(*dvb) - sizeof(struct | 8252 | hdr_len = ntohs (dvb->orig_size) - sizeof(*dvb) - sizeof(struct |
8234 | GNUNET_PeerIdentity) | 8253 | GNUNET_PeerIdentity) |