Skip to content

Commit 46cd178

Browse files
authored
fix: der2raw sLength is s byte length (#634)
Raw signature (also see ISO/IEC 7816-8 / IEEE P1363) are the static size concatenation of the r and s value. These values MUST be 0 padded to the correct length. This fixes the occasional `Invalid Signature` in browsers. This impacts ~1% of messages. These messages are valid and can now be decrypted.
1 parent 22af746 commit 46cd178

File tree

3 files changed

+281
-1433
lines changed

3 files changed

+281
-1433
lines changed

modules/integration-browser/src/testDecryptFixture.ts

+1-12
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ export const bitFlippedDerTagsVectors = [
3737
'f673bdf3-40a8-4551-bc7f-866b289e4d03', // Bit 3370 flipped
3838
]
3939

40-
// The signatures on these messages fail to verify due to
41-
// a known but yet to be fully diagnosed browser-specific issue.
42-
// The error message is `Error: Invalid Signature`
43-
export const unverifiableSignatureVectors = [
44-
'2ad4430c-1b2e-46b3-a71d-a8e458f28a69',
45-
'e3b4ce89-a5f4-4194-9bc5-2984cf1d2a88',
46-
]
47-
4840
/*The contract for the two test*DecryptFixture methods:
4941
* If the decryption is NOT supported,
5042
* FAILED with err.message in notSupportedDecryptMessages
@@ -164,10 +156,7 @@ export function evaluateTestResultIgnoreUnsupported(
164156
{ err, name, result }: TestVectorResult,
165157
_expect: (x: any) => any
166158
): void {
167-
if (
168-
bitFlippedDerTagsVectors.includes(name) ||
169-
unverifiableSignatureVectors.includes(name)
170-
) {
159+
if (bitFlippedDerTagsVectors.includes(name)) {
171160
return _expect(result).toEqual(false)
172161
}
173162
if (err && err['message']) {

modules/serialize/src/ecdsa_signature.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function der2raw(
5252
)
5353

5454
const rLength = r.byteLength()
55-
const sLength = r.byteLength()
55+
const sLength = s.byteLength()
5656

5757
return concatBuffers(
5858
new Uint8Array(_keyLengthBytes - rLength),

0 commit comments

Comments
 (0)