2018-12-12 02:52:51 +00:00
|
|
|
#include <messages/exit.hpp>
|
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
|
|
|
|
UpdateExitMessage::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
2018-11-14 12:23:08 +00:00
|
|
|
if(!bencode_start_dict(buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictMsgType(buf, "A", "V"))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictEntry("P", P, 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(!BEncodeWriteDictEntry("Z", Z, buf))
|
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
2018-11-12 16:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UpdateExitMessage::DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf)
|
|
|
|
{
|
2018-11-14 12:23:08 +00:00
|
|
|
bool read = 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(!BEncodeMaybeReadDictEntry("P", P, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-12-11 00:53:11 +00:00
|
|
|
UpdateExitMessage::Verify(llarp::Crypto* c, const llarp::PubKey& pk) const
|
2018-11-14 12:23:08 +00:00
|
|
|
|
|
|
|
{
|
2018-11-14 21:31:21 +00:00
|
|
|
byte_t tmp[512] = {0};
|
2018-11-14 12:23:08 +00:00
|
|
|
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
|
|
|
|
UpdateExitMessage copy;
|
|
|
|
copy = *this;
|
|
|
|
copy.Z.Zero();
|
|
|
|
if(!copy.BEncode(&buf))
|
|
|
|
return false;
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return c->verify(pk, buf, Z);
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateExitMessage&
|
|
|
|
UpdateExitMessage::operator=(const UpdateExitMessage& other)
|
|
|
|
{
|
|
|
|
P = other.P;
|
|
|
|
S = other.S;
|
|
|
|
T = other.T;
|
|
|
|
version = other.version;
|
2018-11-14 18:02:27 +00:00
|
|
|
Y = other.Y;
|
2018-11-14 12:23:08 +00:00
|
|
|
Z = other.Z;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-12-11 00:53:11 +00:00
|
|
|
UpdateExitMessage::Sign(llarp::Crypto* c, const llarp::SecretKey& sk)
|
2018-11-14 12:23:08 +00:00
|
|
|
{
|
2018-11-14 21:31:21 +00:00
|
|
|
byte_t tmp[512] = {0};
|
2018-11-14 12:23:08 +00:00
|
|
|
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
|
2018-11-14 18:02:27 +00:00
|
|
|
Y.Randomize();
|
2018-11-14 12:23:08 +00:00
|
|
|
if(!BEncode(&buf))
|
|
|
|
return false;
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return c->sign(Z, sk, buf);
|
2018-11-12 16:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-12-10 16:26:46 +00:00
|
|
|
UpdateExitMessage::HandleMessage(IMessageHandler* h, llarp::Router* r) const
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
|
|
|
return h->HandleUpdateExitMessage(this, r);
|
|
|
|
}
|
|
|
|
|
2018-11-14 12:23:08 +00:00
|
|
|
bool
|
|
|
|
UpdateExitVerifyMessage::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
|
|
|
if(!bencode_start_dict(buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictMsgType(buf, "A", "V"))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictInt("S", S, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictInt("T", T, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictInt("V", version, buf))
|
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UpdateExitVerifyMessage::DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf)
|
|
|
|
{
|
|
|
|
bool read = 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;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UpdateExitVerifyMessage::HandleMessage(IMessageHandler* h,
|
2018-12-10 16:26:46 +00:00
|
|
|
llarp::Router* r) const
|
2018-11-14 12:23:08 +00:00
|
|
|
{
|
|
|
|
return h->HandleUpdateExitVerifyMessage(this, r);
|
|
|
|
}
|
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
} // namespace routing
|
2018-12-10 16:26:46 +00:00
|
|
|
} // namespace llarp
|