GeezerVison is showing github.com — crypto: runtime-deprecate DEP0203 and DEP0204 · nodejs/node@adac077
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/crypto.md +24-1Lines changed: 24 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2255,12 +2255,20 @@ be listed in the `transferList` argument. | 2255 | 2255 |
| 2256 | 2256 | <!-- YAML | 2257 | 2257 | added: v15.0.0 | | 2258 | +changes: | | 2259 | + - version: REPLACEME | | 2260 | + pr-url: https://github.com/nodejs/node/pull/62453 | | 2261 | + description: Passing a non-extractable CryptoKey as `key` is deprecated. | 2258 | 2262 | --> | 2259 | 2263 |
| 2260 | 2264 | * `key` {CryptoKey} | 2261 | 2265 | * Returns: {KeyObject} | 2262 | 2266 |
| 2263 | | -Example: Converting a `CryptoKey` instance to a `KeyObject`: | | 2267 | +Returns the underlying {KeyObject} of a {CryptoKey}. The returned {KeyObject} | | 2268 | +does not retain any of the restrictions imposed by the Web Crypto API on the | | 2269 | +original {CryptoKey}, such as the allowed key usages, the algorithm or hash | | 2270 | +algorithm bindings, and the extractability flag. In particular, the underlying | | 2271 | +key material of the returned {KeyObject} can always be exported. | 2264 | 2272 |
| 2265 | 2273 | ```mjs | 2266 | 2274 | const { KeyObject } = await import('node:crypto'); | @@ -3522,6 +3530,9 @@ operations. The specific constants currently defined are described in | 3522 | 3530 | <!-- YAML | 3523 | 3531 | added: v0.1.94 | 3524 | 3532 | changes: | | 3533 | + - version: REPLACEME | | 3534 | + pr-url: https://github.com/nodejs/node/pull/62453 | | 3535 | + description: Passing a CryptoKey as `key` is deprecated. | 3525 | 3536 | - version: | 3526 | 3537 | - v17.9.0 | 3527 | 3538 | - v16.17.0 | @@ -3596,6 +3607,9 @@ given IV will be. | 3596 | 3607 | <!-- YAML | 3597 | 3608 | added: v0.1.94 | 3598 | 3609 | changes: | | 3610 | + - version: REPLACEME | | 3611 | + pr-url: https://github.com/nodejs/node/pull/62453 | | 3612 | + description: Passing a CryptoKey as `key` is deprecated. | 3599 | 3613 | - version: | 3600 | 3614 | - v17.9.0 | 3601 | 3615 | - v16.17.0 | @@ -3819,6 +3833,9 @@ input.on('readable', () => { | 3819 | 3833 | <!-- YAML | 3820 | 3834 | added: v0.1.94 | 3821 | 3835 | changes: | | 3836 | + - version: REPLACEME | | 3837 | + pr-url: https://github.com/nodejs/node/pull/62453 | | 3838 | + description: Passing a CryptoKey as `key` is deprecated. | 3822 | 3839 | - version: v15.0.0 | 3823 | 3840 | pr-url: https://github.com/nodejs/node/pull/35093 | 3824 | 3841 | description: The key can also be an ArrayBuffer or CryptoKey. The | @@ -3909,6 +3926,9 @@ input.on('readable', () => { | 3909 | 3926 | <!-- YAML | 3910 | 3927 | added: v11.6.0 | 3911 | 3928 | changes: | | 3929 | + - version: REPLACEME | | 3930 | + pr-url: https://github.com/nodejs/node/pull/62453 | | 3931 | + description: Passing a CryptoKey as `key` is deprecated. | 3912 | 3932 | - version: REPLACEME | 3913 | 3933 | pr-url: https://github.com/nodejs/node/pull/62240 | 3914 | 3934 | description: Added support for `'raw-private'` and `'raw-seed'` | @@ -3957,6 +3977,9 @@ of the passphrase is limited to 1024 bytes. | 3957 | 3977 | <!-- YAML | 3958 | 3978 | added: v11.6.0 | 3959 | 3979 | changes: | | 3980 | + - version: REPLACEME | | 3981 | + pr-url: https://github.com/nodejs/node/pull/62453 | | 3982 | + description: Passing a CryptoKey as `key` is deprecated. | 3960 | 3983 | - version: REPLACEME | 3961 | 3984 | pr-url: https://github.com/nodejs/node/pull/62240 | 3962 | 3985 | description: Added support for `'raw-public'` format. | |
Collapse file Copy file name to clipboardExpand all lines: doc/api/deprecations.md +8-2Lines changed: 8 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -4485,12 +4485,15 @@ const server = http2.createSecureServer({ | 4485 | 4485 |
| 4486 | 4486 | <!-- YAML | 4487 | 4487 | changes: | | 4488 | + - version: REPLACEME | | 4489 | + pr-url: https://github.com/nodejs/node/pull/62453 | | 4490 | + description: Runtime deprecation. | 4488 | 4491 | - version: REPLACEME | 4489 | 4492 | pr-url: https://github.com/nodejs/node/pull/62321 | 4490 | 4493 | description: Documentation-only deprecation. | 4491 | 4494 | --> | 4492 | 4495 |
| 4493 | | -Type: Documentation-only | | 4496 | +Type: Runtime | 4494 | 4497 |
| 4495 | 4498 | Passing a [`CryptoKey`][] to `node:crypto` functions is deprecated and | 4496 | 4499 | will throw an error in a future version. This includes | @@ -4507,12 +4510,15 @@ will throw an error in a future version. This includes | 4507 | 4510 |
| 4508 | 4511 | <!-- YAML | 4509 | 4512 | changes: | | 4513 | + - version: REPLACEME | | 4514 | + pr-url: https://github.com/nodejs/node/pull/62453 | | 4515 | + description: Runtime deprecation. | 4510 | 4516 | - version: REPLACEME | 4511 | 4517 | pr-url: https://github.com/nodejs/node/pull/62321 | 4512 | 4518 | description: Documentation-only deprecation. | 4513 | 4519 | --> | 4514 | 4520 |
| 4515 | | -Type: Documentation-only | | 4521 | +Type: Runtime | 4516 | 4522 |
| 4517 | 4523 | Passing a non-extractable [`CryptoKey`][] to [`KeyObject.from()`][] is | 4518 | 4524 | deprecated and will throw an error in a future version. | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/keys.js +31-7Lines changed: 31 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -74,6 +74,7 @@ const { | 74 | 74 |
| 75 | 75 | const { | 76 | 76 | customInspectSymbol: kInspect, | | 77 | + getDeprecationWarningEmitter, | 77 | 78 | kEnumerableProperty, | 78 | 79 | lazyDOMException, | 79 | 80 | } = require('internal/util'); | @@ -89,6 +90,18 @@ const kKeyUsages = Symbol('kKeyUsages'); | 89 | 90 | const kCachedAlgorithm = Symbol('kCachedAlgorithm'); | 90 | 91 | const kCachedKeyUsages = Symbol('kCachedKeyUsages'); | 91 | 92 |
| | 93 | +const emitDEP0203 = getDeprecationWarningEmitter( | | 94 | + 'DEP0203', | | 95 | + 'Passing a CryptoKey to node:crypto functions is deprecated.', | | 96 | +); | | 97 | + | | 98 | +const maybeEmitDEP0204 = getDeprecationWarningEmitter( | | 99 | + 'DEP0204', | | 100 | + 'Passing a non-extractable CryptoKey to KeyObject.from() is deprecated.', | | 101 | + undefined, | | 102 | + false, | | 103 | + (key) => !key[kExtractable], | | 104 | +); | 92 | 105 |
| 93 | 106 | // Key input contexts. | 94 | 107 | const kConsumePublic = 0; | @@ -140,6 +153,7 @@ const { | 140 | 153 | static from(key) { | 141 | 154 | if (!isCryptoKey(key)) | 142 | 155 | throw new ERR_INVALID_ARG_TYPE('key', 'CryptoKey', key); | | 156 | + maybeEmitDEP0204(key); | 143 | 157 | return key[kKeyObject]; | 144 | 158 | } | 145 | 159 |
| @@ -796,21 +810,28 @@ function prepareAsymmetricKey(key, ctx) { | 796 | 810 | if (isKeyObject(key)) { | 797 | 811 | // Best case: A key object, as simple as that. | 798 | 812 | return { data: getKeyObjectHandle(key, ctx) }; | 799 | | - } else if (isCryptoKey(key)) { | | 813 | + } | | 814 | + if (isCryptoKey(key)) { | | 815 | + emitDEP0203(); | 800 | 816 | return { data: getKeyObjectHandle(key[kKeyObject], ctx) }; | 801 | | - } else if (isStringOrBuffer(key)) { | | 817 | + } | | 818 | + if (isStringOrBuffer(key)) { | 802 | 819 | // Expect PEM by default, mostly for backward compatibility. | 803 | 820 | return { format: kKeyFormatPEM, data: getArrayBufferOrView(key, 'key') }; | 804 | | - } else if (typeof key === 'object') { | | 821 | + } | | 822 | + if (typeof key === 'object') { | 805 | 823 | const { key: data, encoding, format } = key; | 806 | 824 |
| 807 | 825 | // The 'key' property can be a KeyObject as well to allow specifying | 808 | 826 | // additional options such as padding along with the key. | 809 | | - if (isKeyObject(data)) | | 827 | + if (isKeyObject(data)) { | 810 | 828 | return { data: getKeyObjectHandle(data, ctx) }; | 811 | | - else if (isCryptoKey(data)) | | 829 | + } | | 830 | + if (isCryptoKey(data)) { | | 831 | + emitDEP0203(); | 812 | 832 | return { data: getKeyObjectHandle(data[kKeyObject], ctx) }; | 813 | | - else if (format === 'jwk') { | | 833 | + } | | 834 | + if (format === 'jwk') { | 814 | 835 | validateObject(data, 'key.key'); | 815 | 836 | return { data: getKeyObjectHandleFromJwk(data, ctx), format: 'jwk' }; | 816 | 837 | } else if (format === 'raw-public' || format === 'raw-private' || | @@ -836,6 +857,7 @@ function prepareAsymmetricKey(key, ctx) { | 836 | 857 | ...parseKeyEncoding(key, undefined, isPublic), | 837 | 858 | }; | 838 | 859 | } | | 860 | + | 839 | 861 | throw new ERR_INVALID_ARG_TYPE( | 840 | 862 | 'key', | 841 | 863 | getKeyTypes(ctx !== kCreatePrivate), | @@ -856,7 +878,9 @@ function prepareSecretKey(key, encoding, bufferOnly = false) { | 856 | 878 | if (key.type !== 'secret') | 857 | 879 | throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE(key.type, 'secret'); | 858 | 880 | return key[kHandle]; | 859 | | - } else if (isCryptoKey(key)) { | | 881 | + } | | 882 | + if (isCryptoKey(key)) { | | 883 | + emitDEP0203(); | 860 | 884 | if (key[kKeyType] !== 'secret') | 861 | 885 | throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE(key[kKeyType], 'secret'); | 862 | 886 | return key[kKeyObject][kHandle]; | |
Collapse file Copy file name to clipboard +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | + | | 3 | +const common = require('../common'); | | 4 | +if (!common.hasCrypto) | | 5 | + common.skip('missing crypto'); | | 6 | + | | 7 | +const crypto = require('crypto'); | | 8 | + | | 9 | +common.expectWarning({ | | 10 | + DeprecationWarning: { | | 11 | + DEP0203: 'Passing a CryptoKey to node:crypto functions is deprecated.', | | 12 | + }, | | 13 | +}); | | 14 | + | | 15 | +(async () => { | | 16 | + const key = await globalThis.crypto.subtle.generateKey( | | 17 | + { name: 'AES-CBC', length: 128 }, | | 18 | + true, | | 19 | + ['encrypt'], | | 20 | + ); | | 21 | + | | 22 | + crypto.createCipheriv('aes-128-cbc', key, Buffer.alloc(16)); | | 23 | +})().then(common.mustCall()); |
Collapse file Copy file name to clipboard +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | + | | 3 | +const common = require('../common'); | | 4 | +if (!common.hasCrypto) | | 5 | + common.skip('missing crypto'); | | 6 | + | | 7 | +const { KeyObject } = require('crypto'); | | 8 | + | | 9 | +common.expectWarning({ | | 10 | + DeprecationWarning: { | | 11 | + DEP0204: 'Passing a non-extractable CryptoKey to KeyObject.from() is deprecated.', | | 12 | + }, | | 13 | +}); | | 14 | + | | 15 | +(async () => { | | 16 | + const key = await globalThis.crypto.subtle.generateKey( | | 17 | + { name: 'AES-CBC', length: 128 }, | | 18 | + false, // non-extractable | | 19 | + ['encrypt'], | | 20 | + ); | | 21 | + | | 22 | + KeyObject.from(key); | | 23 | +})().then(common.mustCall()); |
|