2019-01-10 19:41:51 +00:00
|
|
|
#include <service/protocol.hpp>
|
|
|
|
|
2018-12-12 02:04:32 +00:00
|
|
|
#include <routing/handler.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/buffer.hpp>
|
2019-01-11 01:19:36 +00:00
|
|
|
#include <util/logic.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/mem.hpp>
|
2018-07-19 04:58:39 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
2018-07-22 23:14:29 +00:00
|
|
|
ProtocolMessage::ProtocolMessage()
|
2018-07-19 04:58:39 +00:00
|
|
|
{
|
2018-08-09 19:02:17 +00:00
|
|
|
tag.Zero();
|
2018-07-19 04:58:39 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 19:02:17 +00:00
|
|
|
ProtocolMessage::ProtocolMessage(const ConvoTag& t) : tag(t)
|
2018-07-19 04:58:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-08-09 19:02:17 +00:00
|
|
|
ProtocolMessage::~ProtocolMessage()
|
2018-07-19 04:58:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-01 01:58:06 +00:00
|
|
|
ProtocolMessage::PutBuffer(const llarp_buffer_t& buf)
|
2018-07-19 04:58:39 +00:00
|
|
|
{
|
|
|
|
payload.resize(buf.sz);
|
|
|
|
memcpy(payload.data(), buf.base, buf.sz);
|
|
|
|
}
|
2018-07-22 23:14:29 +00:00
|
|
|
|
2018-08-09 19:02:17 +00:00
|
|
|
void
|
|
|
|
ProtocolMessage::ProcessAsync(void* user)
|
|
|
|
{
|
|
|
|
ProtocolMessage* self = static_cast< ProtocolMessage* >(user);
|
2018-09-18 21:32:17 +00:00
|
|
|
if(!self->handler->HandleDataMessage(self->srcPath, self))
|
|
|
|
llarp::LogWarn("failed to handle data message from ", self->srcPath);
|
2018-08-09 19:02:17 +00:00
|
|
|
delete self;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-02-01 01:58:06 +00:00
|
|
|
ProtocolMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
2018-08-09 19:02:17 +00:00
|
|
|
{
|
|
|
|
bool read = false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("a", proto, read, k, buf))
|
|
|
|
return false;
|
2019-02-17 12:13:34 +00:00
|
|
|
if(k == "d")
|
2018-08-09 19:02:17 +00:00
|
|
|
{
|
|
|
|
llarp_buffer_t strbuf;
|
|
|
|
if(!bencode_read_string(buf, &strbuf))
|
|
|
|
return false;
|
|
|
|
PutBuffer(strbuf);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(!BEncodeMaybeReadDictEntry("i", introReply, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictEntry("s", sender, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictEntry("t", tag, read, k, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("v", version, read, k, buf))
|
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ProtocolMessage::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
|
|
|
if(!bencode_start_dict(buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictInt("a", proto, buf))
|
|
|
|
return false;
|
|
|
|
if(!bencode_write_bytestring(buf, "d", 1))
|
|
|
|
return false;
|
|
|
|
if(!bencode_write_bytestring(buf, payload.data(), payload.size()))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictEntry("i", introReply, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictEntry("s", sender, buf))
|
|
|
|
return false;
|
|
|
|
if(!tag.IsZero())
|
|
|
|
{
|
|
|
|
if(!BEncodeWriteDictEntry("t", tag, buf))
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-17 15:32:37 +00:00
|
|
|
if(!BEncodeWriteDictInt("v", version, buf))
|
2018-08-09 19:02:17 +00:00
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
2018-07-22 23:14:29 +00:00
|
|
|
ProtocolFrame::~ProtocolFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ProtocolFrame::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
|
|
|
if(!bencode_start_dict(buf))
|
|
|
|
return false;
|
2018-08-13 23:22:31 +00:00
|
|
|
|
2018-08-12 17:22:29 +00:00
|
|
|
if(!BEncodeWriteDictMsgType(buf, "A", "H"))
|
|
|
|
return false;
|
2018-08-13 23:22:31 +00:00
|
|
|
if(!C.IsZero())
|
2018-07-22 23:14:29 +00:00
|
|
|
{
|
2018-08-13 23:22:31 +00:00
|
|
|
if(!BEncodeWriteDictEntry("C", C, buf))
|
2018-07-22 23:14:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-08-13 23:22:31 +00:00
|
|
|
if(!BEncodeWriteDictEntry("D", D, buf))
|
2018-07-22 23:14:29 +00:00
|
|
|
return false;
|
2018-08-13 23:22:31 +00:00
|
|
|
|
|
|
|
if(!BEncodeWriteDictEntry("N", N, buf))
|
2018-07-22 23:14:29 +00:00
|
|
|
return false;
|
2018-08-13 23:22:31 +00:00
|
|
|
if(!T.IsZero())
|
2018-08-09 19:02:17 +00:00
|
|
|
{
|
|
|
|
if(!BEncodeWriteDictEntry("T", T, buf))
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-23 21:59:43 +00:00
|
|
|
if(!BEncodeWriteDictInt("V", version, buf))
|
2018-07-22 23:14:29 +00:00
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictEntry("Z", Z, buf))
|
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-02-01 01:58:06 +00:00
|
|
|
ProtocolFrame::DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val)
|
2018-07-22 23:14:29 +00:00
|
|
|
{
|
|
|
|
bool read = false;
|
2019-02-17 12:13:34 +00:00
|
|
|
if(key == "A")
|
2018-08-12 17:22:29 +00:00
|
|
|
{
|
|
|
|
llarp_buffer_t strbuf;
|
|
|
|
if(!bencode_read_string(val, &strbuf))
|
|
|
|
return false;
|
|
|
|
if(strbuf.sz != 1)
|
|
|
|
return false;
|
|
|
|
return *strbuf.cur == 'H';
|
|
|
|
}
|
2018-07-22 23:14:29 +00:00
|
|
|
if(!BEncodeMaybeReadDictEntry("D", D, read, key, val))
|
|
|
|
return false;
|
2018-08-13 23:22:31 +00:00
|
|
|
if(!BEncodeMaybeReadDictEntry("C", C, read, key, val))
|
2018-07-22 23:14:29 +00:00
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictEntry("N", N, read, key, val))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("S", S, read, key, val))
|
|
|
|
return false;
|
2018-08-09 19:02:17 +00:00
|
|
|
if(!BEncodeMaybeReadDictEntry("T", T, read, key, val))
|
|
|
|
return false;
|
2018-07-22 23:14:29 +00:00
|
|
|
if(!BEncodeMaybeReadVersion("V", version, LLARP_PROTO_VERSION, read, key,
|
|
|
|
val))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictEntry("Z", Z, read, key, val))
|
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
2018-08-09 19:02:17 +00:00
|
|
|
bool
|
2018-12-11 00:53:11 +00:00
|
|
|
ProtocolFrame::DecryptPayloadInto(llarp::Crypto* crypto,
|
2019-01-02 01:04:04 +00:00
|
|
|
const SharedSecret& sharedkey,
|
2018-08-13 23:22:31 +00:00
|
|
|
ProtocolMessage& msg) const
|
2018-08-09 19:02:17 +00:00
|
|
|
{
|
2018-12-20 16:49:05 +00:00
|
|
|
Encrypted_t tmp = D;
|
|
|
|
auto buf = tmp.Buffer();
|
2018-09-18 00:18:33 +00:00
|
|
|
crypto->xchacha20(*buf, sharedkey, N);
|
|
|
|
return msg.BDecode(buf);
|
2018-08-09 19:02:17 +00:00
|
|
|
}
|
|
|
|
|
2018-07-22 23:14:29 +00:00
|
|
|
bool
|
2018-12-11 00:53:11 +00:00
|
|
|
ProtocolFrame::EncryptAndSign(llarp::Crypto* crypto,
|
2018-08-13 23:22:31 +00:00
|
|
|
const ProtocolMessage& msg,
|
2019-01-02 01:04:04 +00:00
|
|
|
const SharedSecret& sessionKey,
|
2018-08-13 23:22:31 +00:00
|
|
|
const Identity& localIdent)
|
2018-07-22 23:14:29 +00:00
|
|
|
{
|
2019-02-02 23:12:42 +00:00
|
|
|
std::array< byte_t, MAX_PROTOCOL_MESSAGE_SIZE > tmp;
|
|
|
|
llarp_buffer_t buf(tmp);
|
2018-08-14 21:17:18 +00:00
|
|
|
// encode message
|
|
|
|
if(!msg.BEncode(&buf))
|
2018-09-19 17:04:55 +00:00
|
|
|
{
|
|
|
|
llarp::LogError("message too big to encode");
|
2018-08-14 21:17:18 +00:00
|
|
|
return false;
|
2018-09-19 17:04:55 +00:00
|
|
|
}
|
2018-08-14 21:17:18 +00:00
|
|
|
// rewind
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
buf.cur = buf.base;
|
|
|
|
// encrypt
|
|
|
|
crypto->xchacha20(buf, sessionKey, N);
|
|
|
|
// put encrypted buffer
|
|
|
|
D = buf;
|
|
|
|
// zero out signature
|
|
|
|
Z.Zero();
|
2019-02-02 23:12:42 +00:00
|
|
|
llarp_buffer_t buf2(tmp);
|
2018-08-14 21:17:18 +00:00
|
|
|
// encode frame
|
2018-09-21 12:47:07 +00:00
|
|
|
if(!BEncode(&buf2))
|
2018-09-19 17:04:55 +00:00
|
|
|
{
|
|
|
|
llarp::LogError("frame too big to encode");
|
2018-09-21 12:47:07 +00:00
|
|
|
llarp::DumpBuffer(buf2);
|
2018-07-22 23:14:29 +00:00
|
|
|
return false;
|
2018-09-19 17:04:55 +00:00
|
|
|
}
|
2018-07-22 23:14:29 +00:00
|
|
|
// rewind
|
2018-09-21 12:47:07 +00:00
|
|
|
buf2.sz = buf2.cur - buf2.base;
|
|
|
|
buf2.cur = buf2.base;
|
2018-07-22 23:14:29 +00:00
|
|
|
// sign
|
2018-09-21 12:47:07 +00:00
|
|
|
if(!localIdent.Sign(crypto, Z, buf2))
|
2018-09-19 17:04:55 +00:00
|
|
|
{
|
|
|
|
llarp::LogError("failed to sign? wtf?!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2018-07-22 23:14:29 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 21:17:18 +00:00
|
|
|
struct AsyncFrameDecrypt
|
2018-08-09 19:02:17 +00:00
|
|
|
{
|
2018-12-13 16:14:44 +00:00
|
|
|
llarp::Crypto* crypto;
|
2018-12-10 14:14:55 +00:00
|
|
|
llarp::Logic* logic;
|
2018-08-09 19:02:17 +00:00
|
|
|
ProtocolMessage* msg;
|
2018-08-13 23:22:31 +00:00
|
|
|
const Identity& m_LocalIdentity;
|
2018-08-09 19:02:17 +00:00
|
|
|
IDataHandler* handler;
|
2018-09-17 16:12:42 +00:00
|
|
|
const ProtocolFrame frame;
|
2018-08-09 19:02:17 +00:00
|
|
|
|
2018-12-11 00:53:11 +00:00
|
|
|
AsyncFrameDecrypt(llarp::Logic* l, llarp::Crypto* c,
|
2018-08-14 21:17:18 +00:00
|
|
|
const Identity& localIdent, IDataHandler* h,
|
2018-09-17 16:12:42 +00:00
|
|
|
ProtocolMessage* m, const ProtocolFrame& f)
|
2018-08-09 19:02:17 +00:00
|
|
|
: crypto(c)
|
|
|
|
, logic(l)
|
|
|
|
, msg(m)
|
2018-08-13 23:22:31 +00:00
|
|
|
, m_LocalIdentity(localIdent)
|
2018-08-09 19:02:17 +00:00
|
|
|
, handler(h)
|
2018-08-13 23:22:31 +00:00
|
|
|
, frame(f)
|
2018-08-09 19:02:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Work(void* user)
|
|
|
|
{
|
2018-08-14 21:17:18 +00:00
|
|
|
AsyncFrameDecrypt* self = static_cast< AsyncFrameDecrypt* >(user);
|
|
|
|
auto crypto = self->crypto;
|
2018-08-13 23:22:31 +00:00
|
|
|
SharedSecret K;
|
|
|
|
SharedSecret sharedKey;
|
|
|
|
// copy
|
2018-09-17 16:12:42 +00:00
|
|
|
ProtocolFrame frame(self->frame);
|
|
|
|
if(!crypto->pqe_decrypt(self->frame.C, K,
|
2018-08-13 23:22:31 +00:00
|
|
|
pq_keypair_to_secret(self->m_LocalIdentity.pq)))
|
2018-08-09 19:02:17 +00:00
|
|
|
{
|
2018-09-17 16:12:42 +00:00
|
|
|
llarp::LogError("pqke failed C=", self->frame.C);
|
2018-08-09 19:02:17 +00:00
|
|
|
delete self->msg;
|
|
|
|
delete self;
|
|
|
|
return;
|
|
|
|
}
|
2018-08-14 21:17:18 +00:00
|
|
|
// decrypt
|
|
|
|
auto buf = frame.D.Buffer();
|
2018-09-17 16:12:42 +00:00
|
|
|
crypto->xchacha20(*buf, K, self->frame.N);
|
2018-08-09 19:02:17 +00:00
|
|
|
if(!self->msg->BDecode(buf))
|
|
|
|
{
|
|
|
|
llarp::LogError("failed to decode inner protocol message");
|
2018-08-12 17:22:29 +00:00
|
|
|
llarp::DumpBuffer(*buf);
|
2018-08-09 19:02:17 +00:00
|
|
|
delete self->msg;
|
|
|
|
delete self;
|
|
|
|
return;
|
|
|
|
}
|
2018-08-13 23:22:31 +00:00
|
|
|
// verify signature of outer message after we parsed the inner message
|
2018-09-17 16:12:42 +00:00
|
|
|
if(!self->frame.Verify(crypto, self->msg->sender))
|
2018-08-13 23:22:31 +00:00
|
|
|
{
|
2018-09-17 16:12:42 +00:00
|
|
|
llarp::LogError("intro frame has invalid signature Z=", self->frame.Z,
|
|
|
|
" from ", self->msg->sender.Addr());
|
|
|
|
self->frame.Dump< MAX_PROTOCOL_MESSAGE_SIZE >();
|
2018-09-17 15:32:37 +00:00
|
|
|
self->msg->Dump< MAX_PROTOCOL_MESSAGE_SIZE >();
|
2018-08-13 23:22:31 +00:00
|
|
|
delete self->msg;
|
|
|
|
delete self;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// PKE (A, B, N)
|
2019-01-02 01:04:03 +00:00
|
|
|
SharedSecret sharedSecret;
|
2019-01-26 15:40:58 +00:00
|
|
|
using namespace std::placeholders;
|
|
|
|
path_dh_func dh_server =
|
|
|
|
std::bind(&Crypto::dh_server, self->crypto, _1, _2, _3, _4);
|
|
|
|
|
|
|
|
if(!self->m_LocalIdentity.KeyExchange(dh_server, sharedSecret,
|
2018-09-17 16:12:42 +00:00
|
|
|
self->msg->sender, self->frame.N))
|
2018-08-13 23:22:31 +00:00
|
|
|
{
|
|
|
|
llarp::LogError("x25519 key exchange failed");
|
2018-09-17 16:12:42 +00:00
|
|
|
self->frame.Dump< MAX_PROTOCOL_MESSAGE_SIZE >();
|
2018-08-13 23:22:31 +00:00
|
|
|
delete self->msg;
|
|
|
|
delete self;
|
|
|
|
return;
|
|
|
|
}
|
2019-01-02 01:04:03 +00:00
|
|
|
std::array< byte_t, 64 > tmp;
|
|
|
|
// K
|
|
|
|
std::copy(K.begin(), K.end(), tmp.begin());
|
2018-08-13 23:22:31 +00:00
|
|
|
// S = HS( K + PKE( A, B, N))
|
2019-01-02 01:04:03 +00:00
|
|
|
std::copy(sharedSecret.begin(), sharedSecret.end(), tmp.begin() + 32);
|
2019-02-02 23:12:42 +00:00
|
|
|
crypto->shorthash(sharedKey, llarp_buffer_t(tmp));
|
2018-08-13 23:22:31 +00:00
|
|
|
|
2018-08-09 19:02:17 +00:00
|
|
|
self->handler->PutIntroFor(self->msg->tag, self->msg->introReply);
|
|
|
|
self->handler->PutSenderFor(self->msg->tag, self->msg->sender);
|
2018-08-13 23:22:31 +00:00
|
|
|
self->handler->PutCachedSessionKeyFor(self->msg->tag, sharedKey);
|
|
|
|
|
2018-08-09 19:02:17 +00:00
|
|
|
self->msg->handler = self->handler;
|
2018-12-10 14:14:55 +00:00
|
|
|
self->logic->queue_job({self->msg, &ProtocolMessage::ProcessAsync});
|
2018-08-09 19:02:17 +00:00
|
|
|
delete self;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-14 21:17:18 +00:00
|
|
|
ProtocolFrame&
|
|
|
|
ProtocolFrame::operator=(const ProtocolFrame& other)
|
|
|
|
{
|
2018-09-14 13:43:42 +00:00
|
|
|
C = other.C;
|
|
|
|
D = other.D;
|
|
|
|
N = other.N;
|
|
|
|
Z = other.Z;
|
|
|
|
T = other.T;
|
2018-09-17 13:28:26 +00:00
|
|
|
S = other.S;
|
2018-09-14 13:43:42 +00:00
|
|
|
version = other.version;
|
2018-08-14 21:17:18 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-08-09 19:02:17 +00:00
|
|
|
bool
|
2018-12-11 00:53:11 +00:00
|
|
|
ProtocolFrame::AsyncDecryptAndVerify(llarp::Logic* logic, llarp::Crypto* c,
|
2018-09-18 21:32:17 +00:00
|
|
|
const PathID_t& srcPath,
|
2018-08-09 19:02:17 +00:00
|
|
|
llarp_threadpool* worker,
|
2018-08-13 23:22:31 +00:00
|
|
|
const Identity& localIdent,
|
2018-08-09 19:02:17 +00:00
|
|
|
IDataHandler* handler) const
|
|
|
|
{
|
2018-08-14 21:17:18 +00:00
|
|
|
if(T.IsZero())
|
2018-08-09 19:02:17 +00:00
|
|
|
{
|
2018-09-26 10:52:57 +00:00
|
|
|
llarp::LogInfo("Got protocol frame with new convo");
|
2018-08-09 19:02:17 +00:00
|
|
|
ProtocolMessage* msg = new ProtocolMessage();
|
2018-09-18 21:32:17 +00:00
|
|
|
msg->srcPath = srcPath;
|
2018-08-09 19:02:17 +00:00
|
|
|
// we need to dh
|
2018-08-14 21:17:18 +00:00
|
|
|
auto dh =
|
2018-09-17 16:12:42 +00:00
|
|
|
new AsyncFrameDecrypt(logic, c, localIdent, handler, msg, *this);
|
2018-08-14 21:17:18 +00:00
|
|
|
llarp_threadpool_queue_job(worker, {dh, &AsyncFrameDecrypt::Work});
|
2018-08-09 19:02:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-01-02 01:04:04 +00:00
|
|
|
SharedSecret shared;
|
2018-08-09 19:02:17 +00:00
|
|
|
if(!handler->GetCachedSessionKeyFor(T, shared))
|
|
|
|
{
|
|
|
|
llarp::LogError("No cached session for T=", T);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ServiceInfo si;
|
|
|
|
if(!handler->GetSenderFor(T, si))
|
|
|
|
{
|
|
|
|
llarp::LogError("No sender for T=", T);
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-13 23:22:31 +00:00
|
|
|
if(!Verify(c, si))
|
2018-08-09 19:02:17 +00:00
|
|
|
{
|
2018-09-17 15:32:37 +00:00
|
|
|
llarp::LogError("Signature failure from ", si.Addr());
|
2018-08-09 19:02:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ProtocolMessage* msg = new ProtocolMessage();
|
2018-08-13 23:22:31 +00:00
|
|
|
if(!DecryptPayloadInto(c, shared, *msg))
|
2018-08-09 19:02:17 +00:00
|
|
|
{
|
|
|
|
llarp::LogError("failed to decrypt message");
|
|
|
|
delete msg;
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-18 21:32:17 +00:00
|
|
|
msg->srcPath = srcPath;
|
2018-08-09 19:02:17 +00:00
|
|
|
msg->handler = handler;
|
2018-12-10 14:14:55 +00:00
|
|
|
logic->queue_job({msg, &ProtocolMessage::ProcessAsync});
|
2018-08-09 19:02:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-17 15:32:37 +00:00
|
|
|
bool
|
|
|
|
ProtocolFrame::operator==(const ProtocolFrame& other) const
|
|
|
|
{
|
|
|
|
return C == other.C && D == other.D && N == other.N && Z == other.Z
|
|
|
|
&& T == other.T && S == other.S && version == other.version;
|
|
|
|
}
|
|
|
|
|
2018-07-22 23:14:29 +00:00
|
|
|
bool
|
2018-12-11 00:53:11 +00:00
|
|
|
ProtocolFrame::Verify(llarp::Crypto* crypto, const ServiceInfo& from) const
|
2018-07-22 23:14:29 +00:00
|
|
|
{
|
2018-09-17 13:28:26 +00:00
|
|
|
ProtocolFrame copy(*this);
|
2018-07-22 23:14:29 +00:00
|
|
|
// save signature
|
|
|
|
// zero out signature for verify
|
2018-08-09 19:02:17 +00:00
|
|
|
copy.Z.Zero();
|
2018-07-22 23:14:29 +00:00
|
|
|
// serialize
|
2019-02-02 23:12:42 +00:00
|
|
|
std::array< byte_t, MAX_PROTOCOL_MESSAGE_SIZE > tmp;
|
|
|
|
llarp_buffer_t buf(tmp);
|
2018-09-17 15:32:37 +00:00
|
|
|
if(!copy.BEncode(&buf))
|
2018-07-22 23:14:29 +00:00
|
|
|
{
|
2018-09-17 15:32:37 +00:00
|
|
|
llarp::LogError("bencode fail");
|
|
|
|
return false;
|
2018-07-22 23:14:29 +00:00
|
|
|
}
|
2018-09-17 15:32:37 +00:00
|
|
|
|
|
|
|
// rewind buffer
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
buf.cur = buf.base;
|
|
|
|
// verify
|
|
|
|
return from.Verify(crypto, buf, Z);
|
2018-07-22 23:14:29 +00:00
|
|
|
}
|
|
|
|
|
2018-07-23 07:38:29 +00:00
|
|
|
bool
|
|
|
|
ProtocolFrame::HandleMessage(llarp::routing::IMessageHandler* h,
|
2019-02-11 19:45:42 +00:00
|
|
|
__attribute__((unused))
|
|
|
|
AbstractRouter* r) const
|
2018-07-23 07:38:29 +00:00
|
|
|
{
|
|
|
|
return h->HandleHiddenServiceFrame(this);
|
|
|
|
}
|
|
|
|
|
2018-07-19 04:58:39 +00:00
|
|
|
} // namespace service
|
2018-09-14 13:43:42 +00:00
|
|
|
} // namespace llarp
|