2018-11-12 16:43:40 +00:00
|
|
|
#include <llarp/messages/exit.hpp>
|
|
|
|
#include <llarp/routing/handler.hpp>
|
|
|
|
|
|
|
|
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
|
|
|
|
CloseExitMessage::DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf)
|
|
|
|
{
|
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
|
|
|
|
CloseExitMessage::Verify(llarp_crypto* c, const llarp::PubKey& pk) const
|
|
|
|
{
|
2018-11-14 21:31:21 +00:00
|
|
|
byte_t tmp[512] = {0};
|
2018-11-14 18:02:27 +00:00
|
|
|
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
|
|
|
|
CloseExitMessage copy;
|
|
|
|
copy = *this;
|
|
|
|
copy.Z.Zero();
|
|
|
|
if(!copy.BEncode(&buf))
|
|
|
|
return false;
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return c->verify(pk, buf, Z);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CloseExitMessage::Sign(llarp_crypto* c, const llarp::SecretKey& sk)
|
|
|
|
{
|
2018-11-14 21:31:21 +00:00
|
|
|
byte_t tmp[512] = {0};
|
2018-11-14 18:02:27 +00:00
|
|
|
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
|
|
|
|
Z.Zero();
|
|
|
|
Y.Randomize();
|
|
|
|
if(!BEncode(&buf))
|
|
|
|
return false;
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return c->sign(Z, sk, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseExitMessage&
|
|
|
|
CloseExitMessage::operator=(const CloseExitMessage& other)
|
|
|
|
{
|
|
|
|
S = other.S;
|
|
|
|
version = other.version;
|
|
|
|
Y = other.Y;
|
|
|
|
Z = other.Z;
|
|
|
|
return *this;
|
2018-11-12 16:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CloseExitMessage::HandleMessage(IMessageHandler* h, llarp_router* r) const
|
|
|
|
{
|
|
|
|
return h->HandleCloseExitMessage(this, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace routing
|
|
|
|
} // namespace llarp
|