|
| 1 | +From accb61e9c1a005e5c8ff96a8b33893100bb42d11 Mon Sep 17 00:00:00 2001 |
| 2 | +From: =?UTF-8?q?Markus=20Schifferm=C3=BCller?= |
| 3 | + |
| 4 | +Date: Tue, 13 Aug 2024 22:21:52 -0400 |
| 5 | +Subject: [PATCH] lib: DER signature decoding correction |
| 6 | + |
| 7 | +--- |
| 8 | + lib/elliptic/ec/signature.js | 10 ++++++++++ |
| 9 | + lib/elliptic/eddsa/signature.js | 1 + |
| 10 | + 2 files changed, 11 insertions(+) |
| 11 | + |
| 12 | +diff --git a/src/ui/node_modules/elliptic/lib/elliptic/ec/signature.js b/src/ui/node_modules/elliptic/lib/elliptic/ec/signature.js |
| 13 | +index 539df6a2..48e3a26f 100644 |
| 14 | +--- a/src/ui/node_modules/elliptic/lib/elliptic/ec/signature.js |
| 15 | ++++ b/src/ui/node_modules/elliptic/lib/elliptic/ec/signature.js |
| 16 | +@@ -38,6 +38,10 @@ function getLength(buf, p) { |
| 17 | + return false; |
| 18 | + } |
| 19 | + |
| 20 | ++ if(buf[p.place] === 0x00) { |
| 21 | ++ return false; |
| 22 | ++ } |
| 23 | ++ |
| 24 | + var val = 0; |
| 25 | + for (var i = 0, off = p.place; i < octetLen; i++, off++) { |
| 26 | + val <<= 8; |
| 27 | +@@ -86,6 +90,9 @@ Signature.prototype._importDER = function _importDER(data, enc) { |
| 28 | + if (rlen === false) { |
| 29 | + return false; |
| 30 | + } |
| 31 | ++ if ((data[p.place] & 128) !== 0) { |
| 32 | ++ return false; |
| 33 | ++ } |
| 34 | + var r = data.slice(p.place, rlen + p.place); |
| 35 | + p.place += rlen; |
| 36 | + if (data[p.place++] !== 0x02) { |
| 37 | +@@ -98,6 +105,9 @@ Signature.prototype._importDER = function _importDER(data, enc) { |
| 38 | + if (data.length !== slen + p.place) { |
| 39 | + return false; |
| 40 | + } |
| 41 | ++ if ((data[p.place] & 128) !== 0) { |
| 42 | ++ return false; |
| 43 | ++ } |
| 44 | + var s = data.slice(p.place, slen + p.place); |
| 45 | + if (r[0] === 0) { |
| 46 | + if (r[1] & 0x80) { |
| 47 | +diff --git a/src/ui/node_modules/elliptic/lib/elliptic/eddsa/signature.js b/src/ui/node_modules/elliptic/lib/elliptic/eddsa/signature.js |
| 48 | +index 30ebc920..b224ad1c 100644 |
| 49 | +--- a/src/ui/node_modules/elliptic/lib/elliptic/eddsa/signature.js |
| 50 | ++++ b/src/ui/node_modules/elliptic/lib/elliptic/eddsa/signature.js |
| 51 | +@@ -21,6 +21,7 @@ function Signature(eddsa, sig) { |
| 52 | + sig = parseBytes(sig); |
| 53 | + |
| 54 | + if (Array.isArray(sig)) { |
| 55 | ++ assert(sig.length === eddsa.encodingLength * 2, 'Signature has invalid size'); |
| 56 | + sig = { |
| 57 | + R: sig.slice(0, eddsa.encodingLength), |
| 58 | + S: sig.slice(eddsa.encodingLength), |
0 commit comments