Skip to content

Commit 39dd3a4

Browse files
committed
crypto: deprecate useless crypto APIs
The APIs were probably exposed by accident. getAuthTag and setAuthTag are not a usual getter/setter pair: Getting the authentication tag only makes sense in the context of encryption, setting it only makes sense in the context of decryption. Currently, both functions throw. Neither has been documented publicly. PR-URL: #22126 Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 34f56e2 commit 39dd3a4

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

Diff for: doc/api/deprecations.md

+10
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,16 @@ accessed outside of Node.js core: `Socket.prototype._handle`,
10211021
`Socket.prototype._healthCheck()`, `Socket.prototype._stopReceiving()`, and
10221022
`dgram._createSocketHandle()`.
10231023
1024+
<a id="DEP0113"></a>
1025+
### DEP0113: Cipher.setAuthTag(), Decipher.getAuthTag()
1026+
1027+
Type: Runtime
1028+
1029+
With the current crypto API, having `Cipher.setAuthTag()` and
1030+
`Decipher.getAuthTag()` is not helpful and both functions will throw an error
1031+
when called. They have never been documented and will be removed in a future
1032+
release.
1033+
10241034
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
10251035
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
10261036
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array

Diff for: lib/internal/crypto/cipher.js

+27-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const assert = require('assert');
3131
const LazyTransform = require('internal/streams/lazy_transform');
3232

3333
const { inherits } = require('util');
34-
const { normalizeEncoding } = require('internal/util');
34+
const { deprecate, normalizeEncoding } = require('internal/util');
3535

3636
// Lazy loaded for startup performance.
3737
let StringDecoder;
@@ -194,7 +194,7 @@ Cipher.prototype.getAuthTag = function getAuthTag() {
194194
};
195195

196196

197-
Cipher.prototype.setAuthTag = function setAuthTag(tagbuf) {
197+
function setAuthTag(tagbuf) {
198198
if (!isArrayBufferView(tagbuf)) {
199199
throw new ERR_INVALID_ARG_TYPE('buffer',
200200
['Buffer', 'TypedArray', 'DataView'],
@@ -203,7 +203,14 @@ Cipher.prototype.setAuthTag = function setAuthTag(tagbuf) {
203203
if (!this._handle.setAuthTag(tagbuf))
204204
throw new ERR_CRYPTO_INVALID_STATE('setAuthTag');
205205
return this;
206-
};
206+
}
207+
208+
Object.defineProperty(Cipher.prototype, 'setAuthTag', {
209+
get: deprecate(() => setAuthTag,
210+
'Cipher.setAuthTag is deprecated and will be removed in a ' +
211+
'future version of Node.js.',
212+
'DEP0113')
213+
});
207214

208215
Cipher.prototype.setAAD = function setAAD(aadbuf, options) {
209216
if (!isArrayBufferView(aadbuf)) {
@@ -231,8 +238,23 @@ function addCipherPrototypeFunctions(constructor) {
231238
constructor.prototype.update = Cipher.prototype.update;
232239
constructor.prototype.final = Cipher.prototype.final;
233240
constructor.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
234-
constructor.prototype.getAuthTag = Cipher.prototype.getAuthTag;
235-
constructor.prototype.setAuthTag = Cipher.prototype.setAuthTag;
241+
if (constructor === Cipheriv) {
242+
constructor.prototype.getAuthTag = Cipher.prototype.getAuthTag;
243+
Object.defineProperty(constructor.prototype, 'setAuthTag', {
244+
get: deprecate(() => setAuthTag,
245+
'Cipher.setAuthTag is deprecated and will be removed in ' +
246+
'a future version of Node.js.',
247+
'DEP0113')
248+
});
249+
} else {
250+
constructor.prototype.setAuthTag = setAuthTag;
251+
Object.defineProperty(constructor.prototype, 'getAuthTag', {
252+
get: deprecate(() => constructor.prototype.getAuthTag,
253+
'Decipher.getAuthTag is deprecated and will be removed ' +
254+
'in a future version of Node.js.',
255+
'DEP0113')
256+
});
257+
}
236258
constructor.prototype.setAAD = Cipher.prototype.setAAD;
237259
}
238260

Diff for: test/parallel/test-crypto-authenticated.js

-21
Original file line numberDiff line numberDiff line change
@@ -207,27 +207,6 @@ for (const test of TEST_CASES) {
207207
assert.throws(function() { encrypt.getAuthTag(); }, errMessages.state);
208208
}
209209

210-
{
211-
// trying to set tag on encryption object:
212-
const encrypt = crypto.createCipheriv(test.algo,
213-
Buffer.from(test.key, 'hex'),
214-
Buffer.from(test.iv, 'hex'),
215-
options);
216-
assert.throws(() => { encrypt.setAuthTag(Buffer.from(test.tag, 'hex')); },
217-
errMessages.state);
218-
}
219-
220-
{
221-
if (!isCCM || !common.hasFipsCrypto) {
222-
// trying to read tag from decryption object:
223-
const decrypt = crypto.createDecipheriv(test.algo,
224-
Buffer.from(test.key, 'hex'),
225-
Buffer.from(test.iv, 'hex'),
226-
options);
227-
assert.throws(function() { decrypt.getAuthTag(); }, errMessages.state);
228-
}
229-
}
230-
231210
{
232211
// trying to create cipher with incorrect IV length
233212
assert.throws(function() {

0 commit comments

Comments
 (0)