Skip to content

fix: [WLEO-339] Add function to remove leading zero from base64url encoded JWK properties#211

Merged
manuraf merged 5 commits intoeudiw-masterfrom
bugfix/WLEO-339
Apr 4, 2025
Merged

fix: [WLEO-339] Add function to remove leading zero from base64url encoded JWK properties#211
manuraf merged 5 commits intoeudiw-masterfrom
bugfix/WLEO-339

Conversation

@manuraf
Copy link
Copy Markdown
Contributor

@manuraf manuraf commented Apr 1, 2025

Warning

Breaking change for IT Wallet!

List of Changes

  • New helper function, fixBase64WithLeadingZero (with its underlying helper, removeLeadingZeroAndParseB64Url), to sanitize JSON Web Key (JWK) properties. It addresses potential issues with cryptographic operations by processing the base64url encoded key components (x, y, e, and n). The new functions decode the input, remove any unwanted leading zero, and then re-encode the result to ensure proper formatting.
  • It replace fixBase64EncodingOnKey inside CryptoContext

Motivation and Context

The method getPublicKey in the io-react-native-crypto library returns a key with coordinates in base64 format. This base64 format is generated by converting hex to base64 internally, but sometimes the conversion does not conform to the P-256 key standard—which requires exactly 32 bytes—because the hex representation may result in 33 bytes.

The problem stems from the behavior of BigInteger.toByteArray, which, in certain contexts (e.g., ASN.1 DER signatures), prepends a 0x00 byte if the coordinate starts with a value greater than 0x7F to avoid it being interpreted as a negative number.
This PR aims to temporarily bypass the issue within this library by ensuring that any unwanted leading zero is removed during the conversion process.

How Has This Been Tested?

  • Re-issuance Wallet Instance and PID
  • Try a PID Presentation, it should work as the same

Screenshots (if appropriate):

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@github-actions github-actions Bot added the fix label Apr 1, 2025
@manuraf manuraf changed the title fix: [WLEO-339] fix: [WLEO-339] Add function to remove leading zero from base64url encoded JWK properties Apr 1, 2025
@manuraf manuraf marked this pull request as ready for review April 1, 2025 13:54
@manuraf manuraf requested a review from a team as a code owner April 1, 2025 13:54
Comment thread src/utils/crypto.ts
@manuraf manuraf closed this Apr 4, 2025
@manuraf manuraf reopened this Apr 4, 2025
@manuraf manuraf merged commit 1db1798 into eudiw-master Apr 4, 2025
6 checks passed
@manuraf manuraf deleted the bugfix/WLEO-339 branch April 4, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants