Repository navigation
Fix SEA.keyid: missing sha1hash import and hashing an empty buffer - #1435
Merged
Merged
Conversation
- sea.js / sea/sea.js: SEA.keyid() calls sha1hash(), but it was never imported in that module, so every call throws 'ReferenceError: sha1hash is not defined'. - sha1 module: 'new ArrayBuffer(b)' with a Buffer argument creates an empty 0-byte ArrayBuffer, so the SHA-1 was always the hash of empty input (da39a3ee...) and every key would get the same KeyID. Pass the Buffer to digest() directly.
Owner
|
embarrassing ! @mikeua thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SEA.keyid()(PGPv4-style KeyID from a public key) is broken in two ways:sha1hashis never imported in the module that definesSEA.keyid(sea.jsbundle andsea/sea.js), so every call throwsReferenceError: sha1hash is not defined.ossl.digest({name: 'SHA-1'}, new ArrayBuffer(b)): passing a Buffer to theArrayBufferconstructor coerces it to a length of 0, so the digest is alwaysda39a3ee…(SHA-1 of empty input) and every key would get the same KeyID.Fix: add
var sha1hash = USE('./sha1')(andrequire('./sha1')in the unbuilt source) next to the other imports, and pass the Buffer todigest()directly, since a Buffer is already a validBufferSource.Checked in Node with WebCrypto: before,
new ArrayBuffer(buf).byteLength === 0and two different inputs give the same hash. After, two different public keys give different 16-hex-char KeyIDs.