Browse Source

save and check token

pull/163/head
orignal 10 years ago
parent
commit
e0f80c9f91
  1. 15
      I2PControl.cpp
  2. 2
      I2PControl.h

15
I2PControl.cpp

@ -169,7 +169,16 @@ namespace client @@ -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 @@ -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<std::string>(i2p::util::GetSecondsSinceEpoch ());
std::string token = boost::lexical_cast<std::string>(i2p::util::GetSecondsSinceEpoch ());
m_Tokens.insert (token);
results[I2P_CONTROL_PARAM_TOKEN] = token;
}
void I2PControlService::EchoHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results)

2
I2PControl.h

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
#include <array>
#include <string>
#include <map>
#include <set>
#include <boost/asio.hpp>
namespace i2p
@ -120,6 +121,7 @@ namespace client @@ -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<std::string> m_Tokens;
std::map<std::string, MethodHandler> m_MethodHandlers;
std::map<std::string, I2PControlRequestHandler> m_I2PControlHandlers;

Loading…
Cancel
Save