Skip to content

Commit c6bbae4

Browse files
tniessencodebytere
authored andcommittedMar 30, 2020
crypto: fix ieee-p1363 for createVerify
Fixes: #31866 PR-URL: #31876 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 9251307 commit c6bbae4

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed
 

‎src/node_crypto.cc

+4-8
Original file line numberDiff line numberDiff line change
@@ -5320,8 +5320,7 @@ void Verify::VerifyUpdate(const FunctionCallbackInfo<Value>& args) {
53205320

53215321

53225322
SignBase::Error Verify::VerifyFinal(const ManagedEVPPKey& pkey,
5323-
const char* sig,
5324-
int siglen,
5323+
const ByteSource& sig,
53255324
int padding,
53265325
const Maybe<int>& saltlen,
53275326
bool* verify_result) {
@@ -5342,11 +5341,8 @@ SignBase::Error Verify::VerifyFinal(const ManagedEVPPKey& pkey,
53425341
ApplyRSAOptions(pkey, pkctx.get(), padding, saltlen) &&
53435342
EVP_PKEY_CTX_set_signature_md(pkctx.get(),
53445343
EVP_MD_CTX_md(mdctx.get())) > 0) {
5345-
const int r = EVP_PKEY_verify(pkctx.get(),
5346-
reinterpret_cast<const unsigned char*>(sig),
5347-
siglen,
5348-
m,
5349-
m_len);
5344+
const unsigned char* s = reinterpret_cast<const unsigned char*>(sig.get());
5345+
const int r = EVP_PKEY_verify(pkctx.get(), s, sig.size(), m, m_len);
53505346
*verify_result = r == 1;
53515347
}
53525348

@@ -5391,7 +5387,7 @@ void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) {
53915387
}
53925388

53935389
bool verify_result;
5394-
Error err = verify->VerifyFinal(pkey, hbuf.data(), hbuf.length(), padding,
5390+
Error err = verify->VerifyFinal(pkey, signature, padding,
53955391
salt_len, &verify_result);
53965392
if (err != kSignOk)
53975393
return verify->CheckThrow(err);

‎src/node_crypto.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,7 @@ class Verify : public SignBase {
699699
static void Initialize(Environment* env, v8::Local<v8::Object> target);
700700

701701
Error VerifyFinal(const ManagedEVPPKey& key,
702-
const char* sig,
703-
int siglen,
702+
const ByteSource& sig,
704703
int padding,
705704
const v8::Maybe<int>& saltlen,
706705
bool* verify_result);

‎test/parallel/test-crypto-sign-verify.js

+11
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ common.expectsError(
527527
// Unlike DER signatures, IEEE P1363 signatures have a predictable length.
528528
assert.strictEqual(sig.length, length);
529529
assert.strictEqual(crypto.verify('sha1', data, opts, sig), true);
530+
assert.strictEqual(crypto.createVerify('sha1')
531+
.update(data)
532+
.verify(opts, sig), true);
530533

531534
// Test invalid signature lengths.
532535
for (const i of [-2, -1, 1, 2, 4, 8]) {
@@ -552,6 +555,14 @@ common.expectsError(
552555
ok
553556
);
554557

558+
assert.strictEqual(
559+
crypto.createVerify('sha256').update(data).verify({
560+
key: fixtures.readKey('ec-key.pem'),
561+
dsaEncoding: 'ieee-p1363'
562+
}, extSig),
563+
ok
564+
);
565+
555566
extSig[Math.floor(Math.random() * extSig.length)] ^= 1;
556567
}
557568

0 commit comments

Comments
 (0)
Please sign in to comment.