2018-12-12 02:52:51 +00:00
|
|
|
#include <messages/exit.hpp>
|
2019-01-13 22:39:10 +00:00
|
|
|
|
2018-12-12 02:04:32 +00:00
|
|
|
#include <routing/handler.hpp>
|
2018-11-12 16:43:40 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace routing
|
|
|
|
{
|
|
|
|
bool
|
2018-12-11 00:53:11 +00:00
|
|
|
ObtainExitMessage::Sign(llarp::Crypto* c, const llarp::SecretKey& sk)
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
2019-02-02 23:12:42 +00:00
|
|
|
std::array< byte_t, 1024 > tmp;
|
|
|
|
llarp_buffer_t buf(tmp);
|
|
|
|
I = llarp::seckey_topublic(sk);
|
2018-11-12 16:43:40 +00:00
|
|
|
Z.Zero();
|
|
|
|
if(!BEncode(&buf))
|
2019-01-02 01:04:04 +00:00
|
|
|
{
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
2019-01-02 01:04:04 +00:00
|
|
|
}
|
2018-11-12 16:43:40 +00:00
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return c->sign(Z, sk, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-12-11 00:53:11 +00:00
|
|
|
ObtainExitMessage::Verify(llarp::Crypto* c) const
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
2019-02-02 23:12:42 +00:00
|
|
|
std::array< byte_t, 1024 > tmp;
|
|
|
|
llarp_buffer_t buf(tmp);
|
2018-11-12 16:43:40 +00:00
|
|
|
ObtainExitMessage copy;
|
|
|
|
copy = *this;
|
|
|
|
copy.Z.Zero();
|
|
|
|
if(!copy.BEncode(&buf))
|
2019-01-02 01:04:04 +00:00
|
|
|
{
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
2019-01-02 01:04:04 +00:00
|
|
|
}
|
2018-11-12 16:43:40 +00:00
|
|
|
// rewind buffer
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return c->verify(I, buf, Z);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ObtainExitMessage::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
|
|
|
if(!bencode_start_dict(buf))
|
|
|
|
return false;
|
2018-11-14 20:26:13 +00:00
|
|
|
if(!BEncodeWriteDictMsgType(buf, "A", "O"))
|
2018-11-12 16:43:40 +00:00
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictArray("B", B, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictInt("E", E, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictEntry("I", I, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictInt("S", S, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictInt("T", T, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictInt("V", version, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictArray("W", W, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictInt("X", X, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictEntry("Z", Z, buf))
|
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-02-02 23:12:42 +00:00
|
|
|
ObtainExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
|
|
|
bool read = false;
|
|
|
|
if(!BEncodeMaybeReadDictList("B", B, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("E", E, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictEntry("I", I, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictList("W", W, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("X", X, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-12-10 16:26:46 +00:00
|
|
|
ObtainExitMessage::HandleMessage(IMessageHandler* h, llarp::Router* r) const
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
|
|
|
return h->HandleObtainExitMessage(this, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace routing
|
2018-12-10 16:26:46 +00:00
|
|
|
} // namespace llarp
|