From b48682012d8d23c479dbc1158270847238ae2e9b Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 14 Jun 2015 10:37:15 -0400 Subject: [PATCH] verify adler checksum --- NTCPSession.cpp | 11 +++++++++-- NTCPSession.h | 2 -- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/NTCPSession.cpp b/NTCPSession.cpp index 4d718450..c5dac0a2 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -2,6 +2,7 @@ #include #include "I2PEndian.h" #include +#include #include "base64.h" #include "Log.h" #include "Timestamp.h" @@ -587,7 +588,13 @@ namespace transport if (m_NextMessageOffset >= m_NextMessage->len + 4) // +checksum { // we have a complete I2NP message - m_Handler.PutNextMessage (m_NextMessage); + if (CryptoPP::Adler32().VerifyDigest (m_NextMessage->buf + m_NextMessageOffset - 4, m_NextMessage->buf, m_NextMessageOffset - 4)) + m_Handler.PutNextMessage (m_NextMessage); + else + { + LogPrint (eLogWarning, "Incorrect adler checksum of NTCP message. Dropped"); + DeleteI2NPMessage (m_NextMessage); + } m_NextMessage = nullptr; } return true; @@ -629,7 +636,7 @@ namespace transport int padding = 0; if (rem > 0) padding = 16 - rem; // TODO: fill padding - m_Adler.CalculateDigest (sendBuffer + len + 2 + padding, sendBuffer, len + 2+ padding); + CryptoPP::Adler32().CalculateDigest (sendBuffer + len + 2 + padding, sendBuffer, len + 2+ padding); int l = len + padding + 6; m_Encryption.Encrypt(sendBuffer, l, sendBuffer); diff --git a/NTCPSession.h b/NTCPSession.h index 85a0aeb7..8e3e9073 100644 --- a/NTCPSession.h +++ b/NTCPSession.h @@ -9,7 +9,6 @@ #include #include #include -#include #include "aes.h" #include "Identity.h" #include "RouterInfo.h" @@ -116,7 +115,6 @@ namespace transport i2p::crypto::CBCDecryption m_Decryption; i2p::crypto::CBCEncryption m_Encryption; - CryptoPP::Adler32 m_Adler; struct Establisher {