From e0f80c9f91b347f7a59369d80e1f3a5969f16c48 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 6 Mar 2015 11:33:54 -0500 Subject: [PATCH] save and check token --- I2PControl.cpp | 15 +++++++++++++-- I2PControl.h | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/I2PControl.cpp b/I2PControl.cpp index c39164a2..4954f804 100644 --- a/I2PControl.cpp +++ b/I2PControl.cpp @@ -169,7 +169,16 @@ namespace client LogPrint (eLogInfo, v.first); if (!v.first.empty()) { - if (v.first != I2P_CONTROL_PARAM_TOKEN) // exclude Token. TODO: verify it + if (v.first == I2P_CONTROL_PARAM_TOKEN) + { + if (!m_Tokens.count (v.second.data ())) + { + LogPrint (eLogWarning, "Unknown token ", v.second.data ()); + return; + } + + } + else params[v.first] = v.second.data (); } } @@ -252,7 +261,9 @@ namespace client if (password != m_Password) LogPrint (eLogError, "I2PControl Authenticate Invalid password ", password, " expected ", m_Password); results[I2P_CONTROL_PARAM_API] = api; - results[I2P_CONTROL_PARAM_TOKEN] = boost::lexical_cast(i2p::util::GetSecondsSinceEpoch ()); + std::string token = boost::lexical_cast(i2p::util::GetSecondsSinceEpoch ()); + m_Tokens.insert (token); + results[I2P_CONTROL_PARAM_TOKEN] = token; } void I2PControlService::EchoHandler (const std::map& params, std::map& results) diff --git a/I2PControl.h b/I2PControl.h index 96bc7d1b..f7e76949 100644 --- a/I2PControl.h +++ b/I2PControl.h @@ -7,6 +7,7 @@ #include #include #include +#include #include namespace i2p @@ -120,6 +121,7 @@ namespace client boost::asio::io_service m_Service; boost::asio::ip::tcp::acceptor m_Acceptor; boost::asio::deadline_timer m_ShutdownTimer; + std::set m_Tokens; std::map m_MethodHandlers; std::map m_I2PControlHandlers;