Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v10.x Backport] Backport crypto fix to v10 #37009

Closed

Conversation

evanlucas
Copy link
Contributor

This backports 990feafcb to v10.x. This fixes an issue when using stream.pipeline() with an instance of crypto.Hash.

It was fixed in 12.6.0, so this backports to v10.x and adds a test for it.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. v10.x labels Jan 20, 2021
@aduh95
Copy link
Contributor

aduh95 commented Jan 20, 2021

@nodejs/lts

@bhaskarvilles

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

@@ -30,11 +30,17 @@ const crypto = require('crypto');

const stream = require('stream');
const s = new stream.PassThrough();
const h = crypto.createHash('sha1');
const expect = '15987e60950cf22655b9323bc1e281f9c4aff47e';
const h = crypto.createHash('sha3-512');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails when linked against openssl 1.1.0: https://ci.nodejs.org/job/node-test-commit-linux-containered/nodes=ubuntu1804_sharedlibs_openssl110_x64/24809/

15:30:02 not ok 393 parallel/test-crypto-hash-stream-pipe
15:30:02   ---
15:30:02   duration_ms: 0.138
15:30:02   severity: fail
15:30:02   exitcode: 1
15:30:02   stack: |-
15:30:02     internal/crypto/hash.js:33
15:30:02       this._handle = new _Hash(algorithm);
15:30:02                      ^
15:30:02     
15:30:02     Error: Digest method not supported
15:30:02         at new Hash (internal/crypto/hash.js:33:18)
15:30:02         at Object.createHash (crypto.js:101:10)
15:30:02         at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-linux-containered/test/parallel/test-crypto-hash-stream-pipe.js:33:18)
15:30:02         at Module._compile (internal/modules/cjs/loader.js:778:30)
15:30:02         at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
15:30:02         at Module.load (internal/modules/cjs/loader.js:653:32)
15:30:02         at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
15:30:02         at Function.Module._load (internal/modules/cjs/loader.js:585:3)
15:30:02         at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
15:30:02         at startup (internal/bootstrap/node.js:283:19)
15:30:02   ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, I'll amend that shortly. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry that shortly turned into 13 days :[. Should be working now. Thanks!

@jasnell jasnell changed the title Backport crypto fix to v10 [v10.x Backport] Backport crypto fix to v10 Jan 25, 2021
tniessen and others added 2 commits February 4, 2021 05:36
When piping data into an SHA3 hash, EVP_DigestFinal_ex is called in
hash._flush, bypassing safeguards in the JavaScript layer. Calling
hash.digest causes EVP_DigestFinal_ex to be called again, resulting
in a segmentation fault in the SHA3 implementation of OpenSSL.

A relatively easy solution is to cache the result of calling
EVP_DigestFinal_ex until the Hash object is garbage collected.

PR-URL: nodejs#28251
Fixes: nodejs#28245
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This test fails prior to 990feaf being cherry-picked
due to stream.pipeline with a crypto.Hash not working properly.

That bug also seems to have affected md5.
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

richardlau pushed a commit that referenced this pull request Feb 5, 2021
When piping data into an SHA3 hash, EVP_DigestFinal_ex is called in
hash._flush, bypassing safeguards in the JavaScript layer. Calling
hash.digest causes EVP_DigestFinal_ex to be called again, resulting
in a segmentation fault in the SHA3 implementation of OpenSSL.

A relatively easy solution is to cache the result of calling
EVP_DigestFinal_ex until the Hash object is garbage collected.

PR-URL: #28251
Fixes: #28245
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>

PR-URL: #37009
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
richardlau pushed a commit that referenced this pull request Feb 5, 2021
This test fails prior to 990feaf being cherry-picked
due to stream.pipeline with a crypto.Hash not working properly.

That bug also seems to have affected md5.

PR-URL: #37009
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
richardlau pushed a commit that referenced this pull request Feb 5, 2021
When piping data into an SHA3 hash, EVP_DigestFinal_ex is called in
hash._flush, bypassing safeguards in the JavaScript layer. Calling
hash.digest causes EVP_DigestFinal_ex to be called again, resulting
in a segmentation fault in the SHA3 implementation of OpenSSL.

A relatively easy solution is to cache the result of calling
EVP_DigestFinal_ex until the Hash object is garbage collected.

PR-URL: #28251
Fixes: #28245
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>

Backport-PR-URL: #37009
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
richardlau pushed a commit that referenced this pull request Feb 5, 2021
This test fails prior to 990feaf being cherry-picked
due to stream.pipeline with a crypto.Hash not working properly.

That bug also seems to have affected md5.

PR-URL: #37009
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
@richardlau
Copy link
Member

Landed in d6f3694...f55ce7c.

@richardlau richardlau closed this Feb 5, 2021
@richardlau richardlau mentioned this pull request Feb 5, 2021
richardlau pushed a commit that referenced this pull request Feb 8, 2021
When piping data into an SHA3 hash, EVP_DigestFinal_ex is called in
hash._flush, bypassing safeguards in the JavaScript layer. Calling
hash.digest causes EVP_DigestFinal_ex to be called again, resulting
in a segmentation fault in the SHA3 implementation of OpenSSL.

A relatively easy solution is to cache the result of calling
EVP_DigestFinal_ex until the Hash object is garbage collected.

PR-URL: #28251
Fixes: #28245
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>

Backport-PR-URL: #37009
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
richardlau pushed a commit that referenced this pull request Feb 8, 2021
This test fails prior to 990feaf being cherry-picked
due to stream.pipeline with a crypto.Hash not working properly.

That bug also seems to have affected md5.

PR-URL: #37009
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
@richardlau
Copy link
Member

v10.x-staging was rebased for #37278 so the rebased commit hashes for this PR are 68a6b8d...1c6fbd6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants