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

Increase auth nonce entropy #1383

Merged
merged 2 commits into from
Apr 10, 2024
Merged

Increase auth nonce entropy #1383

merged 2 commits into from
Apr 10, 2024

Conversation

iamacook
Copy link
Member

@iamacook iamacook commented Apr 9, 2024

Summary

This increases the nonce entropy the auth implementation to match that of the official SiWe implementation (18 characters).

@iamacook iamacook self-assigned this Apr 9, 2024
@coveralls
Copy link

coveralls commented Apr 9, 2024

Pull Request Test Coverage Report for Build 8627601648

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.5%) to 93.179%

Files with Coverage Reduction New Missed Lines %
src/routes/transactions/entities/tests/human-description.builder.ts 2 60.0%
Totals Coverage Status
Change from base Build 8613582353: 0.5%
Covered Lines: 4518
Relevant Lines: 4706

💛 - Coveralls

@iamacook iamacook marked this pull request as ready for review April 9, 2024 11:11
@iamacook iamacook requested a review from a team as a code owner April 9, 2024 11:11
* @see https://github.com/StableLib/stablelib/blob/5243520e343c217b6a751464dec1bc980cb510d8/packages/random/random.ts#L80-L99
*/

private static readonly NONCE_LENGTH = 17;
Copy link
Member

Choose a reason for hiding this comment

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

This generates 34 hex characters strings, as nonce if I'm not wrong. The implementation referenced above produces 96 bits (so 48 hex characters), right? I don't have an opinion about the size, both seem enough, but maybe we can add a comment documenting the decision?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the comment is not clear enough (I tried to simplify/extract explicit code from the example packages). Is there something in particular I could adjust to make it more understandable?

  const ALPHANUMERIC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  const length = Math.ceil(96 / (Math.log(ALPHANUMERIC.length) / Math.LN2)) // 17 characters long

Note: I tested the official package again and calling generateNonce of siwe returned the following: "UhC3yE7xXrVU6t0Qs" which is 17 characters.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see, thanks for explaining, the length matches the official package one then 👍🏻

Copy link
Member Author

Choose a reason for hiding this comment

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

I looked into our implementation and you're correct. I'll mark this as a draft and revisit this now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I adjusted the nonce length to 18 as of b2ccdf2.

As we're using the typed array to generate random values, we can't use 17 as we'd need 8.5 elements. I think it's better to stick with 18 as it's a) more secure and b) simpler than then removing a character after generation, for example. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

It makes perfect sense to me, I think we are free to set the length that fits better here, 18 seems OK to me.

@iamacook iamacook marked this pull request as draft April 10, 2024 07:20
@iamacook iamacook marked this pull request as ready for review April 10, 2024 07:35
@iamacook iamacook merged commit 3358128 into main Apr 10, 2024
16 checks passed
@iamacook iamacook deleted the nonce-entropy branch April 10, 2024 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants