From 747383a5e651e6380f3df7ed9ad4992701123c95 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 10 Apr 2014 14:13:15 -0400 Subject: [PATCH] check if session key is available --- SSU.cpp | 8 ++++---- SSU.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/SSU.cpp b/SSU.cpp index ac9a02b0..30298269 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -843,11 +843,11 @@ namespace ssu void SSUSession::SendSesionDestroyed () { - uint8_t buf[48 + 18], iv[16]; - CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); - rnd.GenerateBlock (iv, 16); // random iv - if (m_State == eSessionStateEstablished) + if (HasSessionKey ()) { + uint8_t buf[48 + 18], iv[16]; + CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); + rnd.GenerateBlock (iv, 16); // random iv // encrypt message with session key FillHeaderAndEncrypt (PAYLOAD_TYPE_SESSION_DESTROYED, buf, 48, m_SessionKey, iv, m_MacKey); m_Server.Send (buf, 48, m_RemoteEndpoint); diff --git a/SSU.h b/SSU.h index 334fd710..3f7ac96b 100644 --- a/SSU.h +++ b/SSU.h @@ -118,6 +118,7 @@ namespace ssu void Decrypt (uint8_t * buf, size_t len, const uint8_t * aesKey); bool Validate (uint8_t * buf, size_t len, const uint8_t * macKey); const uint8_t * GetIntroKey () const; + bool HasSessionKey () const { return m_State == eSessionStateCreatedReceived || m_State == eSessionStateRequestReceived; }; void ScheduleTermination (); void HandleTerminationTimer (const boost::system::error_code& ecode);