mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-08-26 10:10:24 +01:00
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
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:
parent
d5769080c8
commit
f1ca24fec2
1 changed files with 25 additions and 17 deletions
|
@ -195,30 +195,38 @@ 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 (flags & DATAGRAM2_FLAG_OFFLINE_SIGNATURE)
|
if (!verified)
|
||||||
{
|
{
|
||||||
LogPrint (eLogWarning, "Datagram: datagram2 offline signature is not supported");
|
std::shared_ptr<i2p::crypto::Verifier> transientVerifier;
|
||||||
return;
|
if (flags & DATAGRAM2_FLAG_OFFLINE_SIGNATURE)
|
||||||
|
{
|
||||||
|
transientVerifier = i2p::data::ProcessOfflineSignature (&identity, buf, len, offset);
|
||||||
|
if (!transientVerifier)
|
||||||
|
{
|
||||||
|
LogPrint (eLogWarning, "Datagram: datagram2 offline signature failed");
|
||||||
|
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());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue