add an extra failsafe check to checksig before normalizing DER sig length.
This commit is contained in:
parent
86cebb7e3b
commit
1f2e1fb6d5
@ -292,7 +292,10 @@ script.concat = function concat(scripts) {
|
|||||||
return s;
|
return s;
|
||||||
};
|
};
|
||||||
|
|
||||||
script.checksig = function checksig(msg, sig, key) {
|
script.checksig = function checksig(msg, sig, key, flags) {
|
||||||
|
if (flags == null)
|
||||||
|
flags = constants.flags.STANDARD_VERIFY_FLAGS;
|
||||||
|
|
||||||
if (key.getPublic)
|
if (key.getPublic)
|
||||||
key = key.getPublic();
|
key = key.getPublic();
|
||||||
|
|
||||||
@ -306,8 +309,13 @@ script.checksig = function checksig(msg, sig, key) {
|
|||||||
|
|
||||||
// Attempt to normalize the signature
|
// Attempt to normalize the signature
|
||||||
// length before passing to elliptic.
|
// length before passing to elliptic.
|
||||||
|
// Note: We only do this for historical data!
|
||||||
// https://github.com/indutny/elliptic/issues/78
|
// https://github.com/indutny/elliptic/issues/78
|
||||||
sig = script.normalizeDER(sig);
|
if (!((flags & constants.flags.VERIFY_DERSIG)
|
||||||
|
|| (flags & constants.flags.VERIFY_LOW_S)
|
||||||
|
|| (flags & constants.flags.VERIFY_STRICTENC))) {
|
||||||
|
sig = script.normalizeDER(sig);
|
||||||
|
}
|
||||||
|
|
||||||
// Use a try catch in case there are
|
// Use a try catch in case there are
|
||||||
// any uncaught errors for bad inputs in verify().
|
// any uncaught errors for bad inputs in verify().
|
||||||
@ -898,7 +906,7 @@ script.execute = function execute(data, stack, tx, index, flags, recurse) {
|
|||||||
|
|
||||||
hash = tx.signatureHash(index, subscript, type);
|
hash = tx.signatureHash(index, subscript, type);
|
||||||
|
|
||||||
res = script.checksig(hash, sig, key);
|
res = script.checksig(hash, sig, key, flags);
|
||||||
if (o === 'checksigverify') {
|
if (o === 'checksigverify') {
|
||||||
if (!res)
|
if (!res)
|
||||||
return false;
|
return false;
|
||||||
@ -959,7 +967,7 @@ script.execute = function execute(data, stack, tx, index, flags, recurse) {
|
|||||||
|
|
||||||
res = false;
|
res = false;
|
||||||
for (; !res && j < n; j++)
|
for (; !res && j < n; j++)
|
||||||
res = script.checksig(hash, sig, keys[j]);
|
res = script.checksig(hash, sig, keys[j], flags);
|
||||||
|
|
||||||
if (res)
|
if (res)
|
||||||
succ++;
|
succ++;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user