AES/ElGamal session tags per local destination

This commit is contained in:
orignal 2014-10-07 16:18:13 -04:00
parent 0af963359a
commit 49d67bada0
6 changed files with 215 additions and 221 deletions

View file

@ -1,6 +1,7 @@
#include <fstream>
#include <algorithm>
#include <cryptopp/dh.h>
#include <cryptopp/gzip.h>
#include "Log.h"
#include "util.h"
#include "Destination.h"
@ -177,22 +178,22 @@ namespace stream
if (buf[9] == 6) // streaming protocol
{
// unzip it
CryptoPP::Gunzip m_Decompressor;
m_Decompressor.Put (buf, length);
m_Decompressor.MessageEnd();
CryptoPP::Gunzip decompressor;
decompressor.Put (buf, length);
decompressor.MessageEnd();
Packet * uncompressed = new Packet;
uncompressed->offset = 0;
uncompressed->len = m_Decompressor.MaxRetrievable ();
uncompressed->len = decompressor.MaxRetrievable ();
if (uncompressed->len <= MAX_PACKET_SIZE)
{
m_Decompressor.Get (uncompressed->buf, uncompressed->len);
decompressor.Get (uncompressed->buf, uncompressed->len);
// then forward to streaming thread
m_Service.post (boost::bind (&StreamingDestination::HandleNextPacket, this, uncompressed));
}
else
{
LogPrint ("Received packet size ", uncompressed->len, " exceeds max packet size. Skipped");
m_Decompressor.Skip ();
decompressor.Skip ();
delete uncompressed;
}
}
@ -203,18 +204,18 @@ namespace stream
I2NPMessage * StreamingDestination::CreateDataMessage (const uint8_t * payload, size_t len)
{
I2NPMessage * msg = NewI2NPShortMessage ();
CryptoPP::Gzip m_Compressor;
CryptoPP::Gzip compressor;
if (len <= COMPRESSION_THRESHOLD_SIZE)
m_Compressor.SetDeflateLevel (CryptoPP::Gzip::MIN_DEFLATE_LEVEL);
compressor.SetDeflateLevel (CryptoPP::Gzip::MIN_DEFLATE_LEVEL);
else
m_Compressor.SetDeflateLevel (CryptoPP::Gzip::DEFAULT_DEFLATE_LEVEL);
m_Compressor.Put (payload, len);
m_Compressor.MessageEnd();
int size = m_Compressor.MaxRetrievable ();
compressor.SetDeflateLevel (CryptoPP::Gzip::DEFAULT_DEFLATE_LEVEL);
compressor.Put (payload, len);
compressor.MessageEnd();
int size = compressor.MaxRetrievable ();
uint8_t * buf = msg->GetPayload ();
*(uint32_t *)buf = htobe32 (size); // length
buf += 4;
m_Compressor.Get (buf, size);
compressor.Get (buf, size);
memset (buf + 4, 0, 4); // source and destination ports. TODO: fill with proper values later
buf[9] = 6; // streaming protocol
msg->len += size + 4;