Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

RouterInfo: refactor signature creation and verification #917

Merged
merged 10 commits into from
Jul 3, 2018

Conversation

coneiric
Copy link
Contributor


By submitting this pull-request, I confirm the following:

  • I have read and understood the developer guide in kovri-docs.
  • I have checked that another pull-request for this purpose does not exist.
  • I have considered and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used and that this pull-request may be closed by the will of the maintainer.
  • I give this submission freely under the BSD 3-clause license.

Moves RouterInfo signing into creation, before converting to a buffer. Adds signature verification and unit-test.

m_BufferLen,
reinterpret_cast<std::uint8_t*>(m_Buffer.get()) + m_BufferLen);

m_BufferLen += private_keys.GetPublic().GetSignatureLen();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now you haven't updated m_BufferLen, assuming we'll continue to use this member. (I'd love to have time to resolve the buffer TODO).

Copy link
Contributor Author

@coneiric coneiric Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


`m_BufferLen` doesn't need to be updated here anymore, because the `router_info` stream includes the signature after `CreateRouterInfo` returns. 

So, when it's set on [line 722](https://github.com/monero-project/kovri/pull/917/files/27f03bbdfd4b48e7714abbef348c952102fd646d#diff-b93e1f4bbdfedbfa93b91f9693a4f1ecR722), it's already the correct length.

I'll spend time working on the buffer TODO.

Hopefully, I'll have something ready by the end of this week.

bool success = false;
try
{
std::size_t len = m_BufferLen - m_RouterIdentity.GetSignatureLen();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will do.

std::size_t len = m_BufferLen - m_RouterIdentity.GetSignatureLen();
if (len < Size::MinUnsignedBuffer)
throw std::length_error("RouterInfo: invalid RouterInfo size");
success =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bool'ing isn't necessary, the function should return void. We'll either throw or not depending on outcome of verifier's bool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, wasn't sure if I should carry on the pattern. Will change with your recommendation.

/// @brief Verify RI signature
/// @return Success of signature verification
/// @throws std::length_error if unsigned buffer length is below minimum
bool Verify();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be implemented outside of the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you referring to throwing the length exception? If so, I can add that into the buffer refactor. If not, what do you mean?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually use this function Verify() outside of the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, understood. Maybe at the end of construction (after buffer refactor)? Will look for other places that make sense too.

@anonimal
Copy link
Collaborator

Referencing #627.

coneiric added a commit to coneiric/kovri that referenced this pull request Jun 27, 2018
Sign, and append the signature, during RouterInfo creation.

Referencing monero-project#627 + monero-project#917
coneiric added a commit to coneiric/kovri that referenced this pull request Jun 27, 2018
Verify that a router has a valid signature.

Referencing monero-project#627 + monero-project#917
coneiric added a commit to coneiric/kovri that referenced this pull request Jun 27, 2018
@coneiric
Copy link
Contributor Author

Added your recommended changes, and some tests for invalid signatures.

Was unsure about adding Verify to ReadFromFile. The one place it's called, the path ctor, also calls ReadFromBuffer with signature verification disabled.

Please let me know if you would like me to make further changes.

@coneiric coneiric changed the title RouterInfo: refactor signature creation and verification [WIP] RouterInfo: refactor signature creation and verification Jun 28, 2018
@coneiric
Copy link
Contributor Author

I added the WIP tag, and would like to rebase this on top of #926. The buffer impl there is much cleaner, and rebasing this PR is simpler than the reverse.

coneiric added a commit to coneiric/kovri that referenced this pull request Jul 2, 2018
Sign, and append the signature, during RouterInfo creation.

Referencing monero-project#627 + monero-project#917
coneiric added a commit to coneiric/kovri that referenced this pull request Jul 2, 2018
Verify that a router has a valid signature.

Referencing monero-project#627 + monero-project#917
coneiric added a commit to coneiric/kovri that referenced this pull request Jul 2, 2018
@coneiric
Copy link
Contributor Author

coneiric commented Jul 2, 2018

This PR is now rebased on the buffer utility changes, and will pass build checks after rebasing on a merged #935.

@coneiric coneiric changed the title [WIP] RouterInfo: refactor signature creation and verification RouterInfo: refactor signature creation and verification Jul 2, 2018
Copy link
Collaborator

@anonimal anonimal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase against master and force push so I can base against this branch to apply/build the proper changes.

coneiric added 3 commits July 2, 2018 20:30
Sign, and append the signature, during RouterInfo creation.

Referencing monero-project#627 + monero-project#917
Verify that a router has a valid signature.

Referencing monero-project#627 + monero-project#917
@coneiric
Copy link
Contributor Author

coneiric commented Jul 2, 2018

Please rebase against master and force push so I can base against this branch to apply/build the proper changes.

Changes rebased and pushed. Hopefully, there aren't too many corrections you need to make? Either way, thanks for your help.

anonimal added 4 commits July 2, 2018 23:31
Unclear contract (and auto* may as well be uint8_t*).

Referencing monero-project#917
Buffer is always at least zero initialized.

Referencing monero-project#917
Sanely, we would want to throw here but doing so will stop the router
instead of allowing the RI to become updated.

Referencing monero-project#917
@anonimal anonimal mentioned this pull request Jul 2, 2018
@anonimal
Copy link
Collaborator

anonimal commented Jul 2, 2018

Hopefully, there aren't too many corrections you need to make?

Nope. It's something I should've done in the first place many PRs ago (PR'ing to your fork). coneiric#2 awaits your merge.

coneiric and others added 2 commits July 3, 2018 01:59
Sanely, we would want to throw here but doing so will stop the router
instead of allowing the RI to become updated.

Referencing monero-project#917
Copy link
Collaborator

@anonimal anonimal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RouterInfo: don't throw on invalid RI size
@anonimal anonimal merged commit 8079f44 into monero-project:master Jul 3, 2018
anonimal added a commit that referenced this pull request Jul 3, 2018
237e1f5 RouterInfo: don't throw on invalid RI size (anonimal)
18b3526 RouterInfo: don't throw when RI fails sig verify (anonimal)
ed041ea RouterInfo: remove unnecessary null buffer check (anonimal)
e89e992 RouterInfo: Verify: remove auto for data pointer (anonimal)
580a5b8 Tests: cleanup RI test comments (anonimal)
e850f57 Tests: RouterInfo signature unit-tests (oneiric)
fcee141 RouterInfo: verify signed router (oneiric)
0739336 RouterInfo: sign during router creation (oneiric)
@coneiric coneiric deleted the ri-sig branch July 13, 2018 03:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants