Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ri sig #2

Merged
merged 4 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/core/router/info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -706,17 +706,13 @@ void RouterInfo::Verify()
{
try
{
if (!m_Buffer.data())
throw std::runtime_error("RouterInfo: null buffer");
std::size_t const len = m_Buffer.size() - m_RouterIdentity.GetSignatureLen();
std::size_t const len =
m_Buffer.size() - m_RouterIdentity.GetSignatureLen();
if (len < Size::MinUnsignedBuffer)
throw std::length_error("RouterInfo: invalid RouterInfo size");
auto const buf = m_Buffer.data();
const std::uint8_t* buf = m_Buffer.data();
if (!m_RouterIdentity.Verify(buf, len, &buf[len]))
{
m_IsUnreachable = true;
throw std::runtime_error("RouterInfo: signature verification failed");
}
m_IsUnreachable = true;
}
catch (...)
{
Expand Down
8 changes: 1 addition & 7 deletions tests/unit_tests/core/router/info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@

#include "core/router/identity.h"

namespace core = kovri::core;

struct RouterInfoFixture
{
core::PrivateKeys keys = core::PrivateKeys::CreateRandomKeys(
Expand All @@ -46,18 +44,14 @@ BOOST_FIXTURE_TEST_SUITE(RouterInfoTests, RouterInfoFixture)

BOOST_AUTO_TEST_CASE(ValidSignature)
{
// Ensure EdDSA router is created & signature verification succeeds
BOOST_CHECK_NO_THROW(core::RouterInfo r(keys, {{"127.0.0.1", 10701}}, {}));
}

BOOST_AUTO_TEST_CASE(InvalidSignature)
{
// If RI is not built completely, insufficient data will throw
core::RouterInfo router;

// Ensure default constructed router fails verification
BOOST_CHECK_THROW(router.Verify(), std::exception);

// Create router buffer without setting default options
BOOST_CHECK_THROW(router.CreateBuffer(keys), std::exception);
}

Expand Down