Skip to content

keygen: fix over-stripping of ED25519 public key bytes - #1515

Open
Soulstears2539 wants to merge 1 commit into
mscdex:masterfrom
Soulstears2539:fix/ed25519-pubkey-leading-zero-strip
Open

keygen: fix over-stripping of ED25519 public key bytes#1515
Soulstears2539 wants to merge 1 commit into
mscdex:masterfrom
Soulstears2539:fix/ed25519-pubkey-leading-zero-strip

Conversation

@Soulstears2539

Copy link
Copy Markdown

Fixes #1514.

Summary

parseDERs() in lib/keygen.js removed all leading 0x00 bytes from
the ED25519 SubjectPublicKeyInfo BIT STRING content instead of exactly
the one mandatory "unused bits" marker byte. Whenever the raw 32-byte
public key itself happened to start with 0x00 (~1/256 keys), the loop
over-stripped real key material, producing a truncated key that
parseKey() then correctly rejected as Malformed OpenSSH public key.

Fix

Strip exactly one byte when it is 0x00, not a variable-length run.

Note: the analogous ec (ECDSA) case uses the same style of loop but is
not affected, since the byte immediately following the leading 0x00 is
always the fixed 0x04 uncompressed-point marker (never zero), so that
loop always stops after exactly one byte regardless of the X/Y coordinate
values. Left unchanged.

Testing

  • Repro loop (generateKeyPairSync('ed25519') + parseKey()) over
    20000 iterations: 85 failures before the fix, 0 failures after.
  • test/test-keygen.js (existing suite) passes unchanged.

parseDERs() removed *all* leading 0x00 bytes from the ED25519
SubjectPublicKeyInfo BIT STRING content instead of exactly the one
mandatory 'unused bits' marker byte. Whenever the raw 32-byte public
key itself happened to start with 0x00 (~1/256 keys), the loop
over-stripped real key material, producing a truncated key that
parseKey() then correctly rejected as 'Malformed OpenSSH public key'.

Fixes mscdex#1514.
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.

generateKeyPairSync('ed25519') + parseKey()

1 participant