2018-12-12 02:52:51 +00:00
|
|
|
#include <messages/exit.hpp>
|
2018-12-12 02:04:32 +00:00
|
|
|
#include <routing/handler.hpp>
|
2019-02-11 19:45:42 +00:00
|
|
|
#include <crypto/crypto.hpp>
|
2018-11-12 16:43:40 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace routing
|
|
|
|
{
|
|
|
|
bool
|
|
|
|
CloseExitMessage::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
2018-11-14 18:02:27 +00:00
|
|
|
if(!bencode_start_dict(buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictMsgType(buf, "A", "C"))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictInt("S", S, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictInt("V", version, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictEntry("Y", Y, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictEntry("Z", Z, buf))
|
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
2018-11-12 16:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-02-02 23:12:42 +00:00
|
|
|
CloseExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
2018-11-14 18:02:27 +00:00
|
|
|
bool read = false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictEntry("Y", Y, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-05-28 19:45:08 +00:00
|
|
|
CloseExitMessage::Verify(const llarp::PubKey& pk) const
|
2018-11-14 18:02:27 +00:00
|
|
|
{
|
2019-02-02 23:12:42 +00:00
|
|
|
std::array< byte_t, 512 > tmp;
|
|
|
|
llarp_buffer_t buf(tmp);
|
2018-11-14 18:02:27 +00:00
|
|
|
CloseExitMessage copy;
|
|
|
|
copy = *this;
|
|
|
|
copy.Z.Zero();
|
|
|
|
if(!copy.BEncode(&buf))
|
|
|
|
return false;
|
|
|
|
buf.sz = buf.cur - buf.base;
|
2019-05-28 19:45:08 +00:00
|
|
|
return CryptoManager::instance()->verify(pk, buf, Z);
|
2018-11-14 18:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-05-28 19:45:08 +00:00
|
|
|
CloseExitMessage::Sign(const llarp::SecretKey& sk)
|
2018-11-14 18:02:27 +00:00
|
|
|
{
|
2019-02-02 23:12:42 +00:00
|
|
|
std::array< byte_t, 512 > tmp;
|
|
|
|
llarp_buffer_t buf(tmp);
|
2018-11-14 18:02:27 +00:00
|
|
|
Z.Zero();
|
|
|
|
Y.Randomize();
|
|
|
|
if(!BEncode(&buf))
|
|
|
|
return false;
|
|
|
|
buf.sz = buf.cur - buf.base;
|
2019-05-28 19:45:08 +00:00
|
|
|
return CryptoManager::instance()->sign(Z, sk, buf);
|
2018-11-14 18:02:27 +00:00
|
|
|
}
|
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
bool
|
2019-02-11 19:45:42 +00:00
|
|
|
CloseExitMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
2019-04-22 17:38:29 +00:00
|
|
|
return h->HandleCloseExitMessage(*this, r);
|
2018-11-12 16:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace routing
|
2018-12-10 16:26:46 +00:00
|
|
|
} // namespace llarp
|