Skip to content

Throw error for unsupported key algorithms.#61

Draft
davidlehn wants to merge 1 commit into
mainfrom
handle-unknown-prefix
Draft

Throw error for unsupported key algorithms.#61
davidlehn wants to merge 1 commit into
mainfrom
handle-unknown-prefix

Conversation

@davidlehn

Copy link
Copy Markdown
Member

Throw error from AsymmetricKey.getAlgorithm() if an unsupported encoded key algorithm is found. This may be indirectly called from the constructor and other functions.

This helps when unsupported or bad key data is used which would previously be partially processed but with the algorithm field set to undefined leading to later issues that were difficult to debug.

Throw error from `AsymmetricKey.getAlgorithm()` if an unsupported
encoded key algorithm is found. This may be indirectly called from the
constructor and other functions.
@davidlehn davidlehn requested a review from dlongley August 28, 2024 02:50
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 49.86%. Comparing base (deab0b9) to head (d96143c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #61      +/-   ##
==========================================
+ Coverage   49.69%   49.86%   +0.16%     
==========================================
  Files          10       10              
  Lines        1831     1837       +6     
==========================================
+ Hits          910      916       +6     
  Misses        921      921              
Files Coverage Δ
lib/AsymmetricKey.js 79.12% <100.00%> (+0.71%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update deab0b9...d96143c. Read the comment docs.

@davidlehn davidlehn marked this pull request as draft August 28, 2024 04:58
@davidlehn

Copy link
Copy Markdown
Member Author

This needs more work. It's doing encoded base58 prefix checking with the assumption this is equivalent to checking the leading encoded bytes. That is not correct in the case of bls12_381-g2-pub multicodec check for [0xeb, 0x01, ...publickey(96)]. If publickey[0] > 128, then the base58 multibase encoded prefix is zUC7, but if it's <=128, then prefix is zUC6. (Need to check math to see if those are the only values). May be able to map two prefixes to the same algorithm. Or may need to do partial byte decoding for bytes to check. Or perhaps some bit mask or base58 mask of the prefix bytes. Need to check other values and code for this issue as well.

@dlongley

Copy link
Copy Markdown
Member

What about mapping to zUC?

@dlongley

Copy link
Copy Markdown
Member

@davidlehn, this PR needs to be rebased which will bring in the valid zUC6 header ... and then the test vector for a bad key needs to be changed to something else to trigger the test.

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