2021-03-09 22:24:35 +00:00
|
|
|
#include "exit_messages.hpp"
|
2019-06-15 14:55:13 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/crypto/crypto.hpp>
|
|
|
|
#include <llarp/routing/handler.hpp>
|
2019-06-15 14:55:13 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace routing
|
|
|
|
{
|
|
|
|
bool
|
|
|
|
ObtainExitMessage::Sign(const llarp::SecretKey& sk)
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
std::array<byte_t, 1024> tmp;
|
2019-06-15 14:55:13 +00:00
|
|
|
llarp_buffer_t buf(tmp);
|
|
|
|
I = seckey_topublic(sk);
|
|
|
|
Z.Zero();
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncode(&buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return CryptoManager::instance()->sign(Z, sk, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ObtainExitMessage::Verify() const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
std::array<byte_t, 1024> tmp;
|
2019-06-15 14:55:13 +00:00
|
|
|
llarp_buffer_t buf(tmp);
|
|
|
|
ObtainExitMessage copy;
|
|
|
|
copy = *this;
|
|
|
|
copy.Z.Zero();
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!copy.BEncode(&buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// rewind buffer
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return CryptoManager::instance()->verify(I, buf, Z);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ObtainExitMessage::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!bencode_start_dict(buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictMsgType(buf, "A", "O"))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictArray("B", B, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("E", E, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictEntry("I", I, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("S", S, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("T", T, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("V", version, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictArray("W", W, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("X", X, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictEntry("Z", Z, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ObtainExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
|
|
|
{
|
|
|
|
bool read = false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictList("B", B, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("E", E, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("I", I, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictList("W", W, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("X", X, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
ObtainExitMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
|
2019-06-15 14:55:13 +00:00
|
|
|
{
|
|
|
|
return h->HandleObtainExitMessage(*this, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GrantExitMessage::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!bencode_start_dict(buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictMsgType(buf, "A", "G"))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("S", S, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("T", T, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("V", version, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictEntry("Y", Y, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictEntry("Z", Z, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GrantExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
|
|
|
{
|
|
|
|
bool read = false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("Y", Y, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GrantExitMessage::Verify(const llarp::PubKey& pk) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
std::array<byte_t, 512> tmp;
|
2019-06-15 14:55:13 +00:00
|
|
|
llarp_buffer_t buf(tmp);
|
|
|
|
GrantExitMessage copy;
|
|
|
|
copy = *this;
|
|
|
|
copy.Z.Zero();
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!copy.BEncode(&buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return CryptoManager::instance()->verify(pk, buf, Z);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GrantExitMessage::Sign(const llarp::SecretKey& sk)
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
std::array<byte_t, 512> tmp;
|
2019-06-15 14:55:13 +00:00
|
|
|
llarp_buffer_t buf(tmp);
|
|
|
|
Z.Zero();
|
|
|
|
Y.Randomize();
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncode(&buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return CryptoManager::instance()->sign(Z, sk, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GrantExitMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
|
|
|
|
{
|
|
|
|
return h->HandleGrantExitMessage(*this, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
RejectExitMessage::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!bencode_start_dict(buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictMsgType(buf, "A", "J"))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("B", B, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictList("R", R, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("S", S, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("T", T, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("V", version, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictEntry("Y", Y, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictEntry("Z", Z, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
RejectExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
|
|
|
{
|
|
|
|
bool read = false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("B", B, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictList("R", R, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("Y", Y, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
RejectExitMessage::Sign(const llarp::SecretKey& sk)
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
std::array<byte_t, 512> tmp;
|
2019-06-15 14:55:13 +00:00
|
|
|
llarp_buffer_t buf(tmp);
|
|
|
|
Z.Zero();
|
|
|
|
Y.Randomize();
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncode(&buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return CryptoManager::instance()->sign(Z, sk, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
RejectExitMessage::Verify(const llarp::PubKey& pk) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
std::array<byte_t, 512> tmp;
|
2019-06-15 14:55:13 +00:00
|
|
|
llarp_buffer_t buf(tmp);
|
|
|
|
RejectExitMessage copy;
|
|
|
|
copy = *this;
|
|
|
|
copy.Z.Zero();
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!copy.BEncode(&buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return CryptoManager::instance()->verify(pk, buf, Z);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
RejectExitMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
|
2019-06-15 14:55:13 +00:00
|
|
|
{
|
|
|
|
return h->HandleRejectExitMessage(*this, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UpdateExitMessage::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!bencode_start_dict(buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictMsgType(buf, "A", "V"))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictEntry("P", P, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("S", S, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("T", T, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("V", version, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictEntry("Z", Z, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UpdateExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
|
|
|
{
|
|
|
|
bool read = false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("P", P, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UpdateExitMessage::Verify(const llarp::PubKey& pk) const
|
|
|
|
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
std::array<byte_t, 512> tmp;
|
2019-06-15 14:55:13 +00:00
|
|
|
llarp_buffer_t buf(tmp);
|
|
|
|
UpdateExitMessage copy;
|
|
|
|
copy = *this;
|
|
|
|
copy.Z.Zero();
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!copy.BEncode(&buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return CryptoManager::instance()->verify(pk, buf, Z);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UpdateExitMessage::Sign(const llarp::SecretKey& sk)
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
std::array<byte_t, 512> tmp;
|
2019-06-15 14:55:13 +00:00
|
|
|
llarp_buffer_t buf(tmp);
|
|
|
|
Y.Randomize();
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncode(&buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return CryptoManager::instance()->sign(Z, sk, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
UpdateExitMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
|
2019-06-15 14:55:13 +00:00
|
|
|
{
|
|
|
|
return h->HandleUpdateExitMessage(*this, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UpdateExitVerifyMessage::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!bencode_start_dict(buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictMsgType(buf, "A", "V"))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("S", S, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("T", T, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("V", version, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
UpdateExitVerifyMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
2019-06-15 14:55:13 +00:00
|
|
|
{
|
|
|
|
bool read = false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
UpdateExitVerifyMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
|
2019-06-15 14:55:13 +00:00
|
|
|
{
|
|
|
|
return h->HandleUpdateExitVerifyMessage(*this, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CloseExitMessage::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!bencode_start_dict(buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictMsgType(buf, "A", "C"))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("S", S, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("V", version, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictEntry("Y", Y, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictEntry("Z", Z, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CloseExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
|
|
|
{
|
|
|
|
bool read = false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("Y", Y, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CloseExitMessage::Verify(const llarp::PubKey& pk) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
std::array<byte_t, 512> tmp;
|
2019-06-15 14:55:13 +00:00
|
|
|
llarp_buffer_t buf(tmp);
|
|
|
|
CloseExitMessage copy;
|
|
|
|
copy = *this;
|
|
|
|
copy.Z.Zero();
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!copy.BEncode(&buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return CryptoManager::instance()->verify(pk, buf, Z);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CloseExitMessage::Sign(const llarp::SecretKey& sk)
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
std::array<byte_t, 512> tmp;
|
2019-06-15 14:55:13 +00:00
|
|
|
llarp_buffer_t buf(tmp);
|
|
|
|
Z.Zero();
|
|
|
|
Y.Randomize();
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncode(&buf))
|
2019-06-15 14:55:13 +00:00
|
|
|
return false;
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
return CryptoManager::instance()->sign(Z, sk, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CloseExitMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
|
|
|
|
{
|
|
|
|
return h->HandleCloseExitMessage(*this, r);
|
|
|
|
}
|
|
|
|
} // namespace routing
|
|
|
|
} // namespace llarp
|