FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

crypto: refactor crypto module by jasnell · Pull Request #15231 · nodejs/node · GitHub

/ node Public

crypto: refactor crypto module - #15231

Closed
jasnell wants to merge 1 commit into
nodejs:masterfrom
jasnell:crypto-api
Closed

crypto: refactor crypto module#15231
jasnell wants to merge 1 commit into
nodejs:masterfrom
jasnell:crypto-api

Conversation

jasnell commented Sep 6, 2017
edited
Loading

Copy link
Copy Markdown
Member

Beginning of a larger bit of work on the crypto API and implementation.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

crypto

nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Sep 6, 2017
jasnell added semver-major PRs that contain breaking changes and should be released in the next major version. crypto Issues and PRs related to the crypto subsystem. lib / src Issues and PRs related to general changes in the lib or src directory. and removed lib / src Issues and PRs related to general changes in the lib or src directory. labels Sep 6, 2017

Trott commented Sep 7, 2017

Copy link
Copy Markdown
Member

Should this be labeled in progress?

jasnell commented Sep 7, 2017

Copy link
Copy Markdown
Member Author

haven't decided yet lol.... the rest of what I want to do here should likely go into a separate PR. It's rather extensive

jasnell commented Sep 12, 2017

Copy link
Copy Markdown
Member Author

ping @nodejs/crypto
ping @nodejs/tsc

Copy link
Copy Markdown
Member

@jasnell why is this semver-major?

jasnell commented Sep 12, 2017

Copy link
Copy Markdown
Member Author

While moving things around it also updates to use internal/errors

targos commented Sep 12, 2017

Copy link
Copy Markdown
Member

Is it something that you would like to land before Node 9?

jasnell commented Sep 13, 2017

Copy link
Copy Markdown
Member Author

I'd like to yes.

jasnell requested review from indutny and shigeki September 13, 2017 16:40
Comment thread lib/internal/errors.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

nit: use printf-like syntax?

Comment thread lib/internal/crypto/certificate.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We should probably document these and recommend their usage since it's useless to create an instance of the class. That can be done in another PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Might as well do it in this PR

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Done!

Comment thread lib/internal/crypto/pbkdf2.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

If I'm reading the C++ code correctly, with the previous undefined check, if a digest that is neither undefined nor a string is passed, a default value would be used. That includes null. Is this something that we want to break?

node/src/node_crypto.cc

Lines 5392 to 5403 in bf1ca8f

if (args[4]->IsString()) {
node::Utf8Value digest_name(env->isolate(), args[4]);
digest = EVP_get_digestbyname(*digest_name);
if (digest == nullptr) {
type_error = "Bad digest name";
goto err;
}
}
if (digest == nullptr) {
digest = EVP_sha1();
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

you're right. this should allow digest to be null so it will default. Will fix.

Comment thread lib/internal/errors.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

nit: use printf-like syntax?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I can, yeah, I tend to prefer this way but it's no biggie for me :-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't mind keeping it this way if that's what you prefer 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

nah... I'll change it. It's no biggie and I don't feel strongly about it

jasnell commented Sep 13, 2017

Copy link
Copy Markdown
Member Author

@targos .. updated!

targos commented Sep 13, 2017

Copy link
Copy Markdown
Member

Thanks. LGTM.

A CITGM run wouldn't hurt IMO.

jasnell commented Sep 13, 2017
edited
Loading

Copy link
Copy Markdown
Member Author

jasnell requested a review from sam-github September 13, 2017 21:41

jasnell commented Sep 13, 2017

Copy link
Copy Markdown
Member Author

Not seeing anything of significant concern in CITGM. regular CI is still running.

jasnell commented Sep 13, 2017

Copy link
Copy Markdown
Member Author

Btw, all... A big reason I'm going through all this is to work towards support for async crypto API variants. I will likely only pursue it, however, once async iterators have landed. The following is an example of what I'm looking to achieve:

const crypto = require('crypto');

async function hash(alg, data, enc) {
  const hash = crypto.createHash(alg);
  for await (const chunk of data) {
    hash.update(chunk);
  }
  return hash.digest(enc);
}

var n = 0;
async function* dataIterator() {
  while (n++ < 10)
    yield `testing${n}`;
}

const p = hash('sha256', dataIterator(), 'hex');
p.then(console.log).catch(console.error);

The async hash function above returns a Promise that uses an async iterator to feed data into the hash. async variants of hash, hmac, sign, verify, cipher and decipher are all trivially possible with this approach.

This, of course, does not really do much to help with performance on the TLS side, but it does provide a nice Promise-oriented API.

indutny left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

One question, otherwise LGTM.

Comment thread src/node_crypto.cc Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Huh? Why?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Because it segfaults with a double free without it!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

so this particular line of code was not being exercised previously because the input was always a Uint8Array. The if check above would always be true. If any of thing is passed, however, the Buffer would segfault when it tried to GC due to a double free.

jasnell Sep 14, 2017
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I will say that I'm not entirely sure this is the right approach to take on this! :-) (Copy might be better but I'm not entirely sure about that either)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

(The challenge here, btw, is that we have two TypedArray instances being created that cover the same data space... thinking about it now, copying the data would be best.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@jasnell What happens if the original Uint8Array is freed before this one?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yep, that's the exact weirdness I'm looking at. Looking at it again, I've just changed the if block above to s/isUint8Array/isArrayBufferView and everything works as it should :-)

addaleax mentioned this pull request Sep 14, 2017
3 tasks

jasnell commented Sep 14, 2017

Copy link
Copy Markdown
Member Author

@indutny and @addaleax ... updated!

indutny left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

jasnell commented Sep 15, 2017

Copy link
Copy Markdown
Member Author

Thank you @indutny and @targos ... I will land this on Monday if there are no objections!

jasnell commented Sep 18, 2017

Copy link
Copy Markdown
Member Author

jasnell commented Sep 18, 2017

Copy link
Copy Markdown
Member Author

small linting error fixed. Landing shortly.

* Split single monolithic file into multiple
* Make Certificate methods static
* Allow randomFill(Sync) to use any ArrayBufferView
* Use internal/errors throughout
* Improve arg validation in Hash/Hmac
* Doc updates
jasnell added a commit that referenced this pull request Sep 18, 2017
* Split single monolithic file into multiple
* Make Certificate methods static
* Allow randomFill(Sync) to use any ArrayBufferView
* Use internal/errors throughout
* Improve arg validation in Hash/Hmac
* Doc updates

PR-URL: #15231
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>

jasnell commented Sep 18, 2017

Copy link
Copy Markdown
Member Author

Landed in c75f87c

jasnell closed this Sep 18, 2017
jasnell added the notable-change PRs with changes that should be highlighted in changelogs. label Sep 18, 2017

jasnell commented Sep 18, 2017

Copy link
Copy Markdown
Member Author

The "notable change" here is that randomFill and randomFillSync can now fill any TypedArray with random data, it's not just limited to Buffer and Uint8Array any more.

Qard pushed a commit to Qard/ayo that referenced this pull request Sep 21, 2017
* Split single monolithic file into multiple
* Make Certificate methods static
* Allow randomFill(Sync) to use any ArrayBufferView
* Use internal/errors throughout
* Improve arg validation in Hash/Hmac
* Doc updates

PR-URL: nodejs/node#15231
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Qard pushed a commit to Qard/ayo that referenced this pull request Sep 21, 2017
* Split single monolithic file into multiple
* Make Certificate methods static
* Allow randomFill(Sync) to use any ArrayBufferView
* Use internal/errors throughout
* Improve arg validation in Hash/Hmac
* Doc updates

PR-URL: nodejs/node#15231
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
bengl mentioned this pull request Sep 28, 2017
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

crypto Issues and PRs related to the crypto subsystem. lib / src Issues and PRs related to general changes in the lib or src directory. notable-change PRs with changes that should be highlighted in changelogs. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL