handle offline signature for Datagram2
Some checks failed
Build Debian packages / bookworm (push) Has been cancelled
Build Debian packages / bullseye (push) Has been cancelled
Build Debian packages / trixie (push) Has been cancelled
Build on FreeBSD / with UPnP (push) Has been cancelled
Build on OSX / With USE_UPNP=no (push) Has been cancelled
Build on OSX / With USE_UPNP=yes (push) Has been cancelled
Build on Windows / clang-x86_64 (push) Has been cancelled
Build on Windows / i686 (push) Has been cancelled
Build on Windows / ucrt-x86_64 (push) Has been cancelled
Build on Windows / x86_64 (push) Has been cancelled
Build on Windows / CMake clang-x86_64 (push) Has been cancelled
Build on Windows / CMake i686 (push) Has been cancelled
Build on Windows / CMake ucrt-x86_64 (push) Has been cancelled
Build on Windows / CMake x86_64 (push) Has been cancelled
Build on Windows / XP (push) Has been cancelled
Build on Ubuntu / Make with USE_UPNP=no (push) Has been cancelled
Build on Ubuntu / Make with USE_UPNP=yes (push) Has been cancelled
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Has been cancelled
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Has been cancelled
Build containers / Building container for linux/amd64 (push) Has been cancelled
Build containers / Building container for linux/arm64 (push) Has been cancelled
Build containers / Building container for linux/arm/v7 (push) Has been cancelled
Build containers / Building container for linux/386 (push) Has been cancelled
Build containers / Pushing merged manifest (push) Has been cancelled

This commit is contained in:
orignal 2025-07-26 16:05:57 -04:00
parent d5769080c8
commit f1ca24fec2

View file

@ -195,31 +195,39 @@ namespace datagram
} }
} }
} }
if (!verified)
{
std::vector<uint8_t> signedData (len + 32 - identityLen - signatureLen);
memcpy (signedData.data (), identity.GetIdentHash (), 32);
memcpy (signedData.data () + 32, buf + identityLen, signedData.size () - 32);
if (!identity.Verify (signedData.data (), signedData.size (), buf + len - signatureLen))
{
LogPrint (eLogWarning, "Datagram: datagram2 signature verification failed");
return;
}
}
uint16_t flags = bufbe16toh (buf + identityLen); uint16_t flags = bufbe16toh (buf + identityLen);
size_t offset = identityLen + 2; size_t offset = identityLen + 2;
if (flags & DATAGRAM2_FLAG_OPTIONS) if (flags & DATAGRAM2_FLAG_OPTIONS)
offset += bufbe16toh (buf + offset) + 2; offset += bufbe16toh (buf + offset) + 2;
if (offset > len - signatureLen) if (offset > len)
{ {
LogPrint (eLogWarning, "Datagram: datagram2 is too short ", len - signatureLen, " expected ", offset); LogPrint (eLogWarning, "Datagram: datagram2 is too short ", len, " expected ", offset);
return; return;
} }
if (!verified)
{
std::shared_ptr<i2p::crypto::Verifier> transientVerifier;
if (flags & DATAGRAM2_FLAG_OFFLINE_SIGNATURE) if (flags & DATAGRAM2_FLAG_OFFLINE_SIGNATURE)
{ {
LogPrint (eLogWarning, "Datagram: datagram2 offline signature is not supported"); transientVerifier = i2p::data::ProcessOfflineSignature (&identity, buf, len, offset);
if (!transientVerifier)
{
LogPrint (eLogWarning, "Datagram: datagram2 offline signature failed");
return; return;
} }
signatureLen = transientVerifier->GetSignatureLen ();
}
std::vector<uint8_t> signedData (len + 32 - identityLen - signatureLen);
memcpy (signedData.data (), identity.GetIdentHash (), 32);
memcpy (signedData.data () + 32, buf + identityLen, signedData.size () - 32);
verified = transientVerifier ? transientVerifier->Verify (signedData.data (), signedData.size (), buf + len - signatureLen) :
identity.Verify (signedData.data (), signedData.size (), buf + len - signatureLen);
if (!verified)
{
LogPrint (eLogWarning, "Datagram: datagram2 signature verification failed");
return;
}
}
auto session = ObtainSession (identity.GetIdentHash()); auto session = ObtainSession (identity.GetIdentHash());
session->SetVersion (eDatagramV2); session->SetVersion (eDatagramV2);