From 6b7ba5986b684219a41f6853036d6aa57572e0a7 Mon Sep 17 00:00:00 2001 From: rymnc Date: Thu, 1 Sep 2022 09:29:46 +0000 Subject: [PATCH] deploy: ea62e2b7cea936ed364f0026fb4283f94a129303 --- .../vendor/libbacktrace-upstream/libtool | 2 +- .../waku_noise/noise_handshake_processing.nim | 14 +++++++------- waku/v2/protocol/waku_noise/noise_utils.nim | 7 ++++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool index beb9463af..b14e62df8 100755 --- a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool +++ b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool @@ -2,7 +2,7 @@ # libtool - Provide generalized library-building support services. # Generated automatically by config.status (libbacktrace) version-unused -# Libtool was configured on host fv-az308-858: +# Libtool was configured on host fv-az335-655: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, diff --git a/waku/v2/protocol/waku_noise/noise_handshake_processing.nim b/waku/v2/protocol/waku_noise/noise_handshake_processing.nim index d99b3bb63..8d72a50d9 100644 --- a/waku/v2/protocol/waku_noise/noise_handshake_processing.nim +++ b/waku/v2/protocol/waku_noise/noise_handshake_processing.nim @@ -355,7 +355,7 @@ proc processMessagePatternTokens(rng: var BrHmacDrbgContext, hs: var HandshakeSt trace "noise write s" # If the local static key is not set (the handshake state was not properly initialized), we raise an error - if hs.s == default(KeyPair): + if isDefault(hs.s): raise newException(NoisePublicKeyError, "Static key not set") # We encrypt the public part of the static key in case a key is set in the Cipher State @@ -386,7 +386,7 @@ proc processMessagePatternTokens(rng: var BrHmacDrbgContext, hs: var HandshakeSt trace "noise dh ee" # If local and/or remote ephemeral keys are not set, we raise an error - if hs.e == default(KeyPair) or hs.re == default(Curve25519Key): + if isDefault(hs.e) or isDefault(hs.re): raise newException(NoisePublicKeyError, "Local or remote ephemeral key not set") # Calls MixKey(DH(e, re)). @@ -401,11 +401,11 @@ proc processMessagePatternTokens(rng: var BrHmacDrbgContext, hs: var HandshakeSt # We check if keys are correctly set. # If both present, we call MixKey(DH(e, rs)) if initiator, MixKey(DH(s, re)) if responder. if hs.initiator: - if hs.e == default(KeyPair) or hs.rs == default(Curve25519Key): + if isDefault(hs.e) or isDefault(hs.rs): raise newException(NoisePublicKeyError, "Local or remote ephemeral/static key not set") hs.ss.mixKey(dh(hs.e.privateKey, hs.rs)) else: - if hs.re == default(Curve25519Key) or hs.s == default(KeyPair): + if isDefault(hs.re) or isDefault(hs.s): raise newException(NoisePublicKeyError, "Local or remote ephemeral/static key not set") hs.ss.mixKey(dh(hs.s.privateKey, hs.re)) @@ -418,11 +418,11 @@ proc processMessagePatternTokens(rng: var BrHmacDrbgContext, hs: var HandshakeSt # We check if keys are correctly set. # If both present, call MixKey(DH(s, re)) if initiator, MixKey(DH(e, rs)) if responder. if hs.initiator: - if hs.s == default(KeyPair) or hs.re == default(Curve25519Key): + if isDefault(hs.s) or isDefault(hs.re): raise newException(NoiseMalformedHandshake, "Local or remote ephemeral/static key not set") hs.ss.mixKey(dh(hs.s.privateKey, hs.re)) else: - if hs.rs == default(Curve25519Key) or hs.e == default(KeyPair): + if isDefault(hs.rs) or isDefault(hs.e): raise newException(NoiseMalformedHandshake, "Local or remote ephemeral/static key not set") hs.ss.mixKey(dh(hs.e.privateKey, hs.rs)) @@ -433,7 +433,7 @@ proc processMessagePatternTokens(rng: var BrHmacDrbgContext, hs: var HandshakeSt trace "noise dh ss" # If local and/or remote static keys are not set, we raise an error - if hs.s == default(KeyPair) or hs.rs == default(Curve25519Key): + if isDefault(hs.s) or isDefault(hs.rs): raise newException(NoiseMalformedHandshake, "Local or remote static key not set") # Calls MixKey(DH(s, rs)). diff --git a/waku/v2/protocol/waku_noise/noise_utils.nim b/waku/v2/protocol/waku_noise/noise_utils.nim index 9fd30d86f..e58bcbdfa 100644 --- a/waku/v2/protocol/waku_noise/noise_utils.nim +++ b/waku/v2/protocol/waku_noise/noise_utils.nim @@ -57,6 +57,11 @@ proc pkcs7_unpad*(payload: seq[byte], paddingSize: int): seq[byte] = let unpadded = payload[0..payload.high-k.int] return unpadded +# Simple utility that checks if the given variable is "default", +# Therefore, it has not been initialized +proc isDefault*[T](value: T): bool = + value == static(default(T)) + ################################################################# ################################# @@ -406,4 +411,4 @@ proc deserializePayloadV2*(payload: seq[byte]): Result[PayloadV2, cstring] payload2.transportMessage = payload[i..i+transportMessageLen-1] i += transportMessageLen - return ok(payload2) \ No newline at end of file + return ok(payload2)