-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
crypto: Deprecate createCipher for createCipheriv #13941
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
Changes from 1 commit
cc8976b
3d0b5a5
1e810d0
8f2b81f
7f913ec
b7abe64
b16018a
39a2112
d0f2778
14e0566
3f0fdb2
b0fe314
0025983
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3301,7 +3301,7 @@ void GenerateLegacyKey(const FunctionCallbackInfo<Value>& args) { | |
| } | ||
|
|
||
| THROW_AND_RETURN_IF_NOT_STRING(args[0], "Cipher"); | ||
| THROW_AND_RETURN_IF_NOT_STRING(args[1], "Key"); | ||
| THROW_AND_RETURN_IF_NOT_STRING_OR_BUFFER(args[1], "Key"); | ||
|
|
||
| const node::Utf8Value cipher_type(env->isolate(), args[0]); | ||
| const node::Utf8Value key_value(env->isolate(), args[1]); | ||
|
|
@@ -3324,8 +3324,12 @@ void GenerateLegacyKey(const FunctionCallbackInfo<Value>& args) { | |
| 1, | ||
| key, | ||
| nullptr); | ||
|
|
||
| Local<Object> buf = Buffer::New(env, (char *) key, (unsigned) key_len).ToLocalChecked(); | ||
|
|
||
| Local<Object> buf = Buffer::New(env, | ||
| reinterpret_cast<char *>(key), | ||
| (unsigned) key_len) | ||
| .ToLocalChecked(); | ||
|
|
||
| args.GetReturnValue().Set(buf); | ||
| } | ||
|
|
||
|
|
@@ -3337,7 +3341,7 @@ void GenerateLegacyIV(const FunctionCallbackInfo<Value>& args) { | |
| } | ||
|
|
||
| THROW_AND_RETURN_IF_NOT_STRING(args[0], "Cipher"); | ||
| THROW_AND_RETURN_IF_NOT_STRING(args[1], "Key"); | ||
| THROW_AND_RETURN_IF_NOT_STRING_OR_BUFFER(args[1], "Key"); | ||
|
|
||
| const node::Utf8Value cipher_type(env->isolate(), args[0]); | ||
| const node::Utf8Value key_value(env->isolate(), args[1]); | ||
|
|
@@ -3366,7 +3370,11 @@ void GenerateLegacyIV(const FunctionCallbackInfo<Value>& args) { | |
| nullptr, | ||
| iv); | ||
|
|
||
| Local<Object> buf = Buffer::New(env, (char *) iv, (unsigned) expected_iv_len).ToLocalChecked(); | ||
| Local<Object> buf = Buffer::New(env, | ||
| reinterpret_cast<char *>(iv), | ||
| (unsigned) expected_iv_len) | ||
| .ToLocalChecked(); | ||
|
|
||
| args.GetReturnValue().Set(buf); | ||
| } | ||
|
|
||
|
|
@@ -3416,6 +3424,7 @@ void CipherBase::Init(const char* cipher_type, | |
| } | ||
|
|
||
| unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
| unsigned char iv[EVP_MAX_KEY_LENGTH]; | ||
|
|
||
| int key_len = EVP_BytesToKey(cipher_, | ||
| EVP_md5(), | ||
|
|
@@ -3424,7 +3433,7 @@ void CipherBase::Init(const char* cipher_type, | |
| key_buf_len, | ||
| 1, | ||
| key, | ||
| nullptr); | ||
| iv); | ||
|
|
||
| EVP_CIPHER_CTX_init(&ctx_); | ||
| const bool encrypt = (kind_ == kCipher); | ||
|
|
@@ -3434,7 +3443,9 @@ void CipherBase::Init(const char* cipher_type, | |
| const int iv_len = EVP_CIPHER_iv_length(cipher_); | ||
|
|
||
| if (encrypt && iv_len != 0) { | ||
| return env()->ThrowError("crypto.createCipher() is no longer supported with ciphers that require initialization vectors. Generate a random IV and pass it to crypto.createCipheriv()."); | ||
| return env()->ThrowError("crypto.createCipher() is no longer supported" | ||
| " with ciphers that require initialization vectors. " | ||
| " Generate a random IV and pass it to crypto.createCipheriv()."); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No comments on whether this is something we should do (ping @nodejs/crypto) ... but this is not the correct way of doing it. There are two kinds of deprecations we use: documentation and runtime. A runtime deprecation uses either the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My PR intends to immediately prohibit the use of this API for ciphers that require an IV. The deprecation of this API entirely hasn’t been done yet. I’m guessing that would go in lib/crypto.js?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, and that's the point: Our deprecation policy requires that APIs go through a proper deprecation cycle so this PR would not be able to land as is. The first step is to do a docs or runtime deprecation as a semver-major, which would go into Node.js 9.0.0.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do have provisions for making exceptions for security-related issues but as this is more about protecting users against themselves, it's up for debate whether those provisions apply. I'm personally leaning towards 'acceptable in node 9' (raising an exception, that is) but I won't hold it against anyone who feels differently.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This prohibits users from using not only counter modes but also cbc modes. I'm not sure if the cbc mode has a security issue in this API. |
||
|
|
||
| if (!EVP_CIPHER_CTX_set_key_length(&ctx_, key_len)) { | ||
|
|
@@ -3446,7 +3457,7 @@ void CipherBase::Init(const char* cipher_type, | |
| nullptr, | ||
| nullptr, | ||
| reinterpret_cast<unsigned char*>(key), | ||
| nullptr, | ||
| reinterpret_cast<unsigned char*>(iv), | ||
| kind_ == kCipher); | ||
| initialised_ = true; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
constinstead ofvar.