handle protocol discard

pull/388/head
Jeff Becker 5 years ago
parent df17866ff7
commit 280d85d478
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -978,12 +978,43 @@ namespace llarp
return false;
}
void
Endpoint::RemoveConvoTag(const ConvoTag& t)
{
m_Sessions.erase(t);
}
bool
Endpoint::HandleHiddenServiceFrame(path::Path* p,
const ProtocolFrame* frame)
{
return frame->AsyncDecryptAndVerify(EndpointLogic(), Crypto(), p->RXID(),
Worker(), m_Identity, m_DataHandler);
if(frame->R)
{
// handle discard
ServiceInfo si;
if(!GetSenderFor(frame->T, si))
return false;
// verify source
if(!frame->Verify(Crypto(), si))
return false;
// remove convotag it doesn't exist
RemoveConvoTag(frame->T);
return true;
}
if(!frame->AsyncDecryptAndVerify(EndpointLogic(), Crypto(), p->RXID(),
Worker(), m_Identity, m_DataHandler))
{
// send discard
ProtocolFrame f;
f.R = 1;
f.T = frame->T;
f.F = p->intro.pathID;
if(!f.Sign(Crypto(), m_Identity))
return false;
const routing::PathTransferMessage d(f, frame->F);
return p->SendRoutingMessage(&d, router);
}
return true;
}
Endpoint::SendContext::SendContext(const ServiceInfo& ident,

@ -393,6 +393,9 @@ namespace llarp
bool
GetIntroFor(const ConvoTag& remote, Introduction& intro) const override;
void
RemoveConvoTag(const ConvoTag& remote) override;
void
PutReplyIntroFor(const ConvoTag& remote,
const Introduction& intro) override;

@ -25,6 +25,9 @@ namespace llarp
PutCachedSessionKeyFor(const ConvoTag& remote,
const SharedSecret& secret) = 0;
virtual void
RemoveConvoTag(const ConvoTag& remote) = 0;
virtual void
PutSenderFor(const ConvoTag& remote, const ServiceInfo& si) = 0;

@ -105,14 +105,23 @@ namespace llarp
if(!BEncodeWriteDictEntry("C", C, buf))
return false;
}
if(!BEncodeWriteDictEntry("D", D, buf))
return false;
if(D.size() > 0)
{
if(!BEncodeWriteDictEntry("D", D, buf))
return false;
}
if(!BEncodeWriteDictEntry("F", F, buf))
return false;
if(!BEncodeWriteDictEntry("N", N, buf))
return false;
if(!N.IsZero())
{
if(!BEncodeWriteDictEntry("N", N, buf))
return false;
}
if(R)
{
if(!BEncodeWriteDictInt("R", R, buf))
return false;
}
if(!T.IsZero())
{
if(!BEncodeWriteDictEntry("T", T, buf))
@ -148,6 +157,8 @@ namespace llarp
return false;
if(!BEncodeMaybeReadDictInt("S", S, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("R", R, read, key, val))
return false;
if(!BEncodeMaybeReadDictEntry("T", T, read, key, val))
return false;
if(!BEncodeMaybeReadVersion("V", version, LLARP_PROTO_VERSION, read, key,
@ -169,6 +180,25 @@ namespace llarp
return msg.BDecode(buf);
}
bool
ProtocolFrame::Sign(llarp::Crypto* crypto, const Identity& localIdent)
{
Z.Zero();
std::array< byte_t, MAX_PROTOCOL_MESSAGE_SIZE > tmp;
llarp_buffer_t buf(tmp);
// encode
if(!BEncode(&buf))
{
llarp::LogError("message too big to encode");
return false;
}
// rewind
buf.sz = buf.cur - buf.base;
buf.cur = buf.base;
// sign
return localIdent.Sign(crypto, Z, buf);
}
bool
ProtocolFrame::EncryptAndSign(llarp::Crypto* crypto,
const ProtocolMessage& msg,
@ -313,6 +343,7 @@ namespace llarp
N = other.N;
Z = other.Z;
T = other.T;
R = other.R;
S = other.S;
version = other.version;
return *this;

@ -65,6 +65,7 @@ namespace llarp
using Encrypted_t = Encrypted< 2048 >;
PQCipherBlock C;
Encrypted_t D;
uint64_t R;
KeyExchangeNonce N;
Signature Z;
PathID_t F;
@ -74,6 +75,7 @@ namespace llarp
: routing::IMessage()
, C(other.C)
, D(other.D)
, R(other.R)
, N(other.N)
, Z(other.Z)
, F(other.F)
@ -106,6 +108,9 @@ namespace llarp
EncryptAndSign(Crypto* c, const ProtocolMessage& msg,
const SharedSecret& sharedkey, const Identity& localIdent);
bool
Sign(Crypto* c, const Identity& localIdent);
bool
AsyncDecryptAndVerify(Logic* logic, Crypto* c, const PathID_t& srcpath,
llarp_threadpool* worker,
@ -131,6 +136,7 @@ namespace llarp
T.Zero();
N.Zero();
Z.Zero();
R = 0;
}
bool

Loading…
Cancel
Save