From 595b2619fd2aa81be39c46b803c045c4ded3e7a4 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 9 Jan 2016 19:24:52 -0500 Subject: [PATCH] fixed misalignment for timestamp --- SSUSession.cpp | 15 +++++---------- SSUSession.h | 4 +--- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/SSUSession.cpp b/SSUSession.cpp index a91ecc2d..f5e1f6e6 100644 --- a/SSUSession.cpp +++ b/SSUSession.cpp @@ -655,11 +655,10 @@ namespace transport LogPrint (eLogError, "SSU: Unexpected packet length ", len); return; } - //TODO: we are using a dirty solution here but should work for now SSUHeader * header = (SSUHeader *)buf; memcpy (header->iv, iv, 16); header->flag = payloadType << 4; // MSB is 0 - htobe32buf (&(header->time), i2p::util::GetSecondsSinceEpoch ()); + htobe32buf (header->time, i2p::util::GetSecondsSinceEpoch ()); uint8_t * encrypted = &header->flag; uint16_t encryptedLen = len - (encrypted - buf); i2p::crypto::CBCEncryption encryption; @@ -679,12 +678,11 @@ namespace transport LogPrint (eLogError, "SSU: Unexpected packet length ", len); return; } - //TODO: we are using a dirty solution here but should work for now SSUHeader * header = (SSUHeader *)buf; RAND_bytes (header->iv, 16); // random iv m_SessionKeyEncryption.SetIV (header->iv); header->flag = payloadType << 4; // MSB is 0 - htobe32buf (&(header->time), i2p::util::GetSecondsSinceEpoch ()); + htobe32buf (header->time, i2p::util::GetSecondsSinceEpoch ()); uint8_t * encrypted = &header->flag; uint16_t encryptedLen = len - (encrypted - buf); m_SessionKeyEncryption.Encrypt (encrypted, encryptedLen, encrypted); @@ -700,8 +698,7 @@ namespace transport { LogPrint (eLogError, "SSU: Unexpected packet length ", len); return; - } - //TODO: since we are accessing a uint8_t this is unlikely to crash due to alignment but should be improved + } SSUHeader * header = (SSUHeader *)buf; uint8_t * encrypted = &header->flag; uint16_t encryptedLen = len - (encrypted - buf); @@ -717,8 +714,7 @@ namespace transport { LogPrint (eLogError, "SSU: Unexpected packet length ", len); return; - } - //TODO: since we are accessing a uint8_t this is unlikely to crash due to alignment but should be improved + } SSUHeader * header = (SSUHeader *)buf; uint8_t * encrypted = &header->flag; uint16_t encryptedLen = len - (encrypted - buf); @@ -735,8 +731,7 @@ namespace transport { LogPrint (eLogError, "SSU: Unexpected packet length ", len); return false; - } - //TODO: since we are accessing a uint8_t this is unlikely to crash due to alignment but should be improved + } SSUHeader * header = (SSUHeader *)buf; uint8_t * encrypted = &header->flag; uint16_t encryptedLen = len - (encrypted - buf); diff --git a/SSUSession.h b/SSUSession.h index 59e834a0..be1a455f 100644 --- a/SSUSession.h +++ b/SSUSession.h @@ -14,18 +14,16 @@ namespace i2p namespace transport { const uint8_t SSU_HEADER_EXTENDED_OPTIONS_INCLUDED = 0x04; -#pragma pack(1) struct SSUHeader { uint8_t mac[16]; uint8_t iv[16]; uint8_t flag; - uint32_t time; + uint8_t time[4]; uint8_t GetPayloadType () const { return flag >> 4; }; bool IsExtendedOptions () const { return flag & SSU_HEADER_EXTENDED_OPTIONS_INCLUDED; }; }; -#pragma pack() const int SSU_CONNECT_TIMEOUT = 5; // 5 seconds const int SSU_TERMINATION_TIMEOUT = 330; // 5.5 minutes