Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Set handshake failure reason in EIP8 code paths
Browse files Browse the repository at this point in the history
  • Loading branch information
halfalicious committed Jun 12, 2019
1 parent 06b00ce commit f1f5db3
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions libp2p/RLPxHandshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ void RLPXHandshake::writeAckEIP8()
m_ackCipher.insert(m_ackCipher.begin(), prefix.begin(), prefix.end());

auto self(shared_from_this());
ba::async_write(m_socket->ref(), ba::buffer(m_ackCipher), [this, self](boost::system::error_code ec, std::size_t)
{
transition(ec);
});
ba::async_write(m_socket->ref(), ba::buffer(m_ackCipher),
[this, self](boost::system::error_code ec, std::size_t) {
if (ec)
m_failureReason = TcpError;
transition(ec);
});
}

void RLPXHandshake::setAuthValues(Signature const& _sig, Public const& _remotePubk, h256 const& _remoteNonce, uint64_t _remoteVersion)
Expand Down Expand Up @@ -163,7 +165,10 @@ void RLPXHandshake::readAuthEIP8()
{
bytesConstRef ct(&m_authCipher);
if (ec)
{
m_failureReason = TcpError;
transition(ec);
}
else if (decryptECIES(m_host->m_alias.secret(), ct.cropped(0, 2), ct.cropped(2), m_auth))
{
RLP rlp(m_auth, RLP::ThrowOnFail | RLP::FailIfTooSmall);
Expand All @@ -180,6 +185,7 @@ void RLPXHandshake::readAuthEIP8()
{
LOG(m_logger) << "EIP-8 auth decrypt failed";
m_nextState = Error;
m_failureReason = FrameDecryptionFailure;
transition();
}
});
Expand All @@ -192,7 +198,10 @@ void RLPXHandshake::readAck()
ba::async_read(m_socket->ref(), ba::buffer(m_ackCipher, c_ackCipherSizeBytes),
[this, self](boost::system::error_code ec, std::size_t) {
if (ec)
{
m_failureReason = TcpError;
transition(ec);
}
else if (decryptECIES(m_host->m_alias.secret(), bytesConstRef(&m_ackCipher), m_ack))
{
LOG(m_logger) << "ack from";
Expand All @@ -218,7 +227,10 @@ void RLPXHandshake::readAckEIP8()
{
bytesConstRef ct(&m_ackCipher);
if (ec)
{
m_failureReason = TcpError;
transition(ec);
}
else if (decryptECIES(m_host->m_alias.secret(), ct.cropped(0, 2), ct.cropped(2), m_ack))
{
RLP rlp(m_ack, RLP::ThrowOnFail | RLP::FailIfTooSmall);
Expand All @@ -230,6 +242,7 @@ void RLPXHandshake::readAckEIP8()
else
{
LOG(m_logger) << "EIP-8 ack decrypt failed";
m_failureReason = FrameDecryptionFailure;
m_nextState = Error;
transition();
}
Expand Down

0 comments on commit f1f5db3

Please sign in to comment.