Skip to content

Commit 8c69e06

Browse files
committed
tls: return an OpenSSL error from renegotiate
A generic error lacks any of the context or detail of the underlying OpenSSL error, so throw from C++, and report the OpenSSL error to the callback. PR-URL: #26868 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent bcbd35a commit 8c69e06

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

doc/api/errors.md

-5
Original file line numberDiff line numberDiff line change
@@ -1771,11 +1771,6 @@ Valid TLS protocol versions are `'TLSv1'`, `'TLSv1.1'`, or `'TLSv1.2'`.
17711771
Attempting to set a TLS protocol `minVersion` or `maxVersion` conflicts with an
17721772
attempt to set the `secureProtocol` explicitly. Use one mechanism or the other.
17731773

1774-
<a id="ERR_TLS_RENEGOTIATE"></a>
1775-
### ERR_TLS_RENEGOTIATE
1776-
1777-
An attempt to renegotiate the TLS session failed.
1778-
17791774
<a id="ERR_TLS_RENEGOTIATION_DISABLED"></a>
17801775
### ERR_TLS_RENEGOTIATION_DISABLED
17811776

doc/api/tls.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1046,9 +1046,10 @@ added: v0.11.8
10461046
`true`.
10471047
* `requestCert`
10481048
* `callback` {Function} If `renegotiate()` returned `true`, callback is
1049-
attached once to the `'secure'` event. If it returned `false`, it will be
1050-
called in the next tick with `ERR_TLS_RENEGOTIATE`, unless the `tlsSocket`
1051-
has been destroyed, in which case it will not be called at all.
1049+
attached once to the `'secure'` event. If `renegotiate()` returned `false`,
1050+
`callback` will be called in the next tick with an error, unless the
1051+
`tlsSocket` has been destroyed, in which case `callback` will not be called
1052+
at all.
10521053

10531054
* Returns: {boolean} `true` if renegotiation was initiated, `false` otherwise.
10541055

lib/_tls_wrap.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ const {
4848
ERR_SOCKET_CLOSED,
4949
ERR_TLS_DH_PARAM_SIZE,
5050
ERR_TLS_HANDSHAKE_TIMEOUT,
51-
ERR_TLS_RENEGOTIATE,
5251
ERR_TLS_RENEGOTIATION_DISABLED,
5352
ERR_TLS_REQUIRED_SERVER_NAME,
5453
ERR_TLS_SESSION_ATTACK,
@@ -661,9 +660,11 @@ TLSSocket.prototype.renegotiate = function(options, callback) {
661660
// Ensure that we'll cycle through internal openssl's state
662661
this.write('');
663662

664-
if (!this._handle.renegotiate()) {
663+
try {
664+
this._handle.renegotiate();
665+
} catch (err) {
665666
if (callback) {
666-
process.nextTick(callback, new ERR_TLS_RENEGOTIATE());
667+
process.nextTick(callback, err);
667668
}
668669
return false;
669670
}

lib/internal/errors.js

-1
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,6 @@ E('ERR_TLS_INVALID_PROTOCOL_VERSION',
10461046
'%j is not a valid %s TLS protocol version', TypeError);
10471047
E('ERR_TLS_PROTOCOL_VERSION_CONFLICT',
10481048
'TLS protocol version %j conflicts with secureProtocol %j', TypeError);
1049-
E('ERR_TLS_RENEGOTIATE', 'Attempt to renegotiate TLS session failed', Error);
10501049
E('ERR_TLS_RENEGOTIATION_DISABLED',
10511050
'TLS session renegotiation disabled for this socket', Error);
10521051

src/node_crypto.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -2339,9 +2339,9 @@ void SSLWrap<Base>::Renegotiate(const FunctionCallbackInfo<Value>& args) {
23392339

23402340
ClearErrorOnReturn clear_error_on_return;
23412341

2342-
// TODO(@sam-github) Return/throw an error, don't discard the SSL error info.
2343-
bool yes = SSL_renegotiate(w->ssl_.get()) == 1;
2344-
args.GetReturnValue().Set(yes);
2342+
if (SSL_renegotiate(w->ssl_.get()) != 1) {
2343+
return ThrowCryptoError(w->ssl_env(), ERR_get_error());
2344+
}
23452345
}
23462346

23472347

test/parallel/test-tls-client-renegotiation-13.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ connect({
2828
assert.strictEqual(client.getProtocol(), 'TLSv1.3');
2929

3030
const ok = client.renegotiate({}, common.mustCall((err) => {
31-
assert(err.code, 'ERR_TLS_RENEGOTIATE');
32-
assert(err.message, 'Attempt to renegotiate TLS session failed');
31+
assert.throws(() => { throw err; }, {
32+
message: 'error:1420410A:SSL routines:SSL_renegotiate:wrong ssl version',
33+
code: 'ERR_SSL_WRONG_SSL_VERSION',
34+
library: 'SSL routines',
35+
reason: 'wrong ssl version',
36+
});
3337
cleanup();
3438
}));
3539

0 commit comments

Comments
 (0)