Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ Type: End-of-Life
<a id="DEP0106"></a>
### DEP0106: crypto.createCipher and crypto.createDecipher

Type: Documentation-only
Type: Runtime

Using [`crypto.createCipher()`][] and [`crypto.createDecipher()`][] should be
avoided as they use a weak key derivation function (MD5 with no salt) and static
Expand Down
12 changes: 10 additions & 2 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ function createVerify(algorithm, options) {
module.exports = exports = {
// Methods
_toBuf: toBuf,
createCipher,
createCipheriv,
createDecipher,
createDecipheriv,
createDiffieHellman,
createDiffieHellmanGroup,
Expand Down Expand Up @@ -209,6 +207,16 @@ function getFipsForced() {
}

Object.defineProperties(exports, {
createCipher: {
enumerable: false,
value: deprecate(createCipher,
'crypto.createCipher is deprecated.', 'DEP0106')
},
createDecipher: {
enumerable: false,
value: deprecate(createDecipher,
'crypto.createDecipher is deprecated.', 'DEP0106')
},
// crypto.fips is deprecated. DEP0093. Use crypto.getFips()/crypto.setFips()
fips: {
get: !fipsMode ? getFipsDisabled :
Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-crypto-authenticated.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ const expectedWarnings = common.hasFipsCrypto ?
['Use Cipheriv for counter mode of aes-256-ccm', common.noWarnCode]
];

const expectedDeprecationWarnings = ['crypto.DEFAULT_ENCODING is deprecated.',
'DEP0091'];
const expectedDeprecationWarnings = [
['crypto.DEFAULT_ENCODING is deprecated.', 'DEP0091'],
['crypto.createCipher is deprecated.', 'DEP0106']
];

common.expectWarning({
Warning: expectedWarnings,
Expand Down
13 changes: 9 additions & 4 deletions test/parallel/test-crypto-cipher-decipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ if (common.hasFipsCrypto)
const crypto = require('crypto');
const assert = require('assert');

common.expectWarning({
Warning: [
['Use Cipheriv for counter mode of aes-256-gcm', common.noWarnCode]
],
DeprecationWarning: [
['crypto.createCipher is deprecated.', 'DEP0106']
]
});

function testCipher1(key) {
// Test encryption and decryption
const plaintext = 'Keep this a secret? No! Tell everyone about node.js!';
Expand Down Expand Up @@ -235,10 +244,6 @@ testCipher2(Buffer.from('0123456789abcdef'));
const aadbuf = Buffer.from('aadbuf');
const data = Buffer.from('test-crypto-cipher-decipher');

common.expectWarning('Warning',
'Use Cipheriv for counter mode of aes-256-gcm',
common.noWarnCode);

const cipher = crypto.createCipher('aes-256-gcm', key);
cipher.setAAD(aadbuf);
cipher.setAutoPadding();
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-process-emit-warning-from-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ const crypto = require('crypto');
const key = '0123456789';

{
common.expectWarning('Warning',
'Use Cipheriv for counter mode of aes-256-gcm',
common.noWarnCode);
common.expectWarning('DeprecationWarning',
'crypto.createCipher is deprecated.',
'DEP0106');

// Emits regular warning expected by expectWarning()
crypto.createCipher('aes-256-gcm', key);
crypto.createCipher('aes-256-cbc', key);
Copy link
Member

Choose a reason for hiding this comment

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

This test checks EmitWarning in C++ code, evident from the file name. Instead of changing the message we should look for another warning.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh right, I can make this work either way, thanks for the hint!

}

const realEmitWarning = process.emitWarning;
Expand Down