use correct intro in tag tracking

pull/15/head
Jeff Becker 6 years ago
parent 9ffcf66e58
commit 217f4a0d3f
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -224,11 +224,22 @@ namespace llarp
{
virtual ~IBEncodeMessage(){};
IBEncodeMessage(uint64_t v = LLARP_PROTO_VERSION)
{
version = v;
}
virtual bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val) = 0;
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val)
{
return false;
}
virtual bool
BEncode(llarp_buffer_t* buf) const = 0;
BEncode(llarp_buffer_t* buf) const
{
return false;
}
virtual bool
BDecode(llarp_buffer_t* buf)
@ -240,7 +251,7 @@ namespace llarp
}
// TODO: check for shadowed values elsewhere
uint64_t version = LLARP_PROTO_VERSION;
uint64_t version = 0;
static bool
OnKey(dict_reader* r, llarp_buffer_t* k)

@ -21,8 +21,7 @@ namespace llarp
{
}
virtual bool
BEncode(llarp_buffer_t* buf) const = 0;
virtual ~IMessage(){};
virtual bool
HandleMessage(IMessageHandler* h, llarp_router* r) const = 0;

@ -72,7 +72,9 @@ namespace llarp
version = other.version;
}
ProtocolFrame();
ProtocolFrame() : llarp::routing::IMessage()
{
}
~ProtocolFrame();

@ -836,13 +836,8 @@ namespace llarp
{
if(i)
{
if(currentIntroSet.OtherIsNewer(*i) || currentIntroSet.I != i->I)
{
currentIntroSet = *i;
ShiftIntroduction();
}
else
llarp::LogInfo("we got a stale introset, dropping it");
currentIntroSet = *i;
ShiftIntroduction();
}
updatingIntroSet = false;
return true;
@ -904,6 +899,7 @@ namespace llarp
llarp::LogError("failed to encrypt and sign");
return false;
}
llarp::LogInfo(Name(), " send ", data.sz, " via ", intro);
return p->SendRoutingMessage(&transfer, Router());
}
}
@ -965,7 +961,7 @@ namespace llarp
remoteIntro.Clear();
for(const auto& intro : currentIntroSet.I)
{
if(remoteIntro.expiresAt < intro.expiresAt)
if(remoteIntro.expiresAt < intro.expiresAt && intro.router == orig)
{
shifted = orig != intro.router;
remoteIntro = intro;
@ -1028,7 +1024,7 @@ namespace llarp
AsyncKeyExchange* self = static_cast< AsyncKeyExchange* >(user);
// put values
self->handler->PutCachedSessionKeyFor(self->msg.tag, self->sharedKey);
self->handler->PutIntroFor(self->msg.tag, self->msg.introReply);
self->handler->PutIntroFor(self->msg.tag, self->intro);
self->handler->PutSenderFor(self->msg.tag, self->remote);
self->hook(self->frame);
delete self;

@ -199,11 +199,11 @@ namespace llarp
ProtocolMessage* msg;
const Identity& m_LocalIdentity;
IDataHandler* handler;
const ProtocolFrame* frame;
const ProtocolFrame frame;
AsyncFrameDecrypt(llarp_logic* l, llarp_crypto* c,
const Identity& localIdent, IDataHandler* h,
ProtocolMessage* m, const ProtocolFrame* f)
ProtocolMessage* m, const ProtocolFrame& f)
: crypto(c)
, logic(l)
, msg(m)
@ -221,18 +221,18 @@ namespace llarp
SharedSecret K;
SharedSecret sharedKey;
// copy
ProtocolFrame frame(*self->frame);
if(!crypto->pqe_decrypt(self->frame->C, K,
ProtocolFrame frame(self->frame);
if(!crypto->pqe_decrypt(self->frame.C, K,
pq_keypair_to_secret(self->m_LocalIdentity.pq)))
{
llarp::LogError("pqke failed C=", self->frame->C);
llarp::LogError("pqke failed C=", self->frame.C);
delete self->msg;
delete self;
return;
}
// decrypt
auto buf = frame.D.Buffer();
crypto->xchacha20(*buf, K, self->frame->N);
crypto->xchacha20(*buf, K, self->frame.N);
if(!self->msg->BDecode(buf))
{
llarp::LogError("failed to decode inner protocol message");
@ -242,11 +242,11 @@ namespace llarp
return;
}
// verify signature of outer message after we parsed the inner message
if(!self->frame->Verify(crypto, self->msg->sender))
if(!self->frame.Verify(crypto, self->msg->sender))
{
llarp::LogError("intro frame has invalid signature Z=",
self->frame->Z, " from ", self->msg->sender.Addr());
self->frame->Dump< MAX_PROTOCOL_MESSAGE_SIZE >();
llarp::LogError("intro frame has invalid signature Z=", self->frame.Z,
" from ", self->msg->sender.Addr());
self->frame.Dump< MAX_PROTOCOL_MESSAGE_SIZE >();
self->msg->Dump< MAX_PROTOCOL_MESSAGE_SIZE >();
delete self->msg;
delete self;
@ -256,11 +256,11 @@ namespace llarp
// K
memcpy(tmp, K, 32);
// PKE (A, B, N)
if(!self->m_LocalIdentity.KeyExchange(
crypto->dh_server, tmp + 32, self->msg->sender, self->frame->N))
if(!self->m_LocalIdentity.KeyExchange(crypto->dh_server, tmp + 32,
self->msg->sender, self->frame.N))
{
llarp::LogError("x25519 key exchange failed");
self->frame->Dump< MAX_PROTOCOL_MESSAGE_SIZE >();
self->frame.Dump< MAX_PROTOCOL_MESSAGE_SIZE >();
delete self->msg;
delete self;
return;
@ -303,7 +303,7 @@ namespace llarp
ProtocolMessage* msg = new ProtocolMessage();
// we need to dh
auto dh =
new AsyncFrameDecrypt(logic, c, localIdent, handler, msg, this);
new AsyncFrameDecrypt(logic, c, localIdent, handler, msg, *this);
llarp_threadpool_queue_job(worker, {dh, &AsyncFrameDecrypt::Work});
return true;
}
@ -336,12 +336,6 @@ namespace llarp
return true;
}
ProtocolFrame::ProtocolFrame() : llarp::routing::IMessage()
{
T.Zero();
C.Zero();
}
bool
ProtocolFrame::operator==(const ProtocolFrame& other) const
{

Loading…
Cancel
Save