From 69a551391c7147342fa53b7253f8fb21316dbc62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sun, 27 Feb 2022 15:07:42 +0100 Subject: [PATCH] src: simplify TLSWrap::SetSession PR-URL: https://github.com/nodejs/node/pull/42087 Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: Darshan Sen --- src/crypto/crypto_common.cc | 15 --------------- src/crypto/crypto_common.h | 7 ------- src/crypto/crypto_tls.cc | 6 +++--- 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc index f318dcf6fa195d..f3497f8ee008a7 100644 --- a/src/crypto/crypto_common.cc +++ b/src/crypto/crypto_common.cc @@ -112,27 +112,12 @@ MaybeLocal GetSSLOCSPResponse( return ret; } -bool SetTLSSession( - const SSLPointer& ssl, - const unsigned char* buf, - size_t length) { - SSLSessionPointer s(d2i_SSL_SESSION(nullptr, &buf, length)); - return s == nullptr ? false : SetTLSSession(ssl, s); -} - bool SetTLSSession( const SSLPointer& ssl, const SSLSessionPointer& session) { return session != nullptr && SSL_set_session(ssl.get(), session.get()) == 1; } -SSLSessionPointer GetTLSSession(Local val) { - if (!val->IsArrayBufferView()) - return SSLSessionPointer(); - ArrayBufferViewContents sbuf(val.As()); - return GetTLSSession(sbuf.data(), sbuf.length()); -} - SSLSessionPointer GetTLSSession(const unsigned char* buf, size_t length) { return SSLSessionPointer(d2i_SSL_SESSION(nullptr, &buf, length)); } diff --git a/src/crypto/crypto_common.h b/src/crypto/crypto_common.h index 7cf72022230c8e..e0956395e91c18 100644 --- a/src/crypto/crypto_common.h +++ b/src/crypto/crypto_common.h @@ -42,17 +42,10 @@ v8::MaybeLocal GetSSLOCSPResponse( SSL* ssl, v8::Local default_value); -bool SetTLSSession( - const SSLPointer& ssl, - const unsigned char* buf, - size_t length); - bool SetTLSSession( const SSLPointer& ssl, const SSLSessionPointer& session); -SSLSessionPointer GetTLSSession(v8::Local val); - SSLSessionPointer GetTLSSession(const unsigned char* buf, size_t length); long VerifyPeerCertificate( // NOLINT(runtime/int) diff --git a/src/crypto/crypto_tls.cc b/src/crypto/crypto_tls.cc index cfe760adb3af1d..72b49e05f0cb0d 100644 --- a/src/crypto/crypto_tls.cc +++ b/src/crypto/crypto_tls.cc @@ -1667,10 +1667,10 @@ void TLSWrap::SetSession(const FunctionCallbackInfo& args) { return THROW_ERR_MISSING_ARGS(env, "Session argument is mandatory"); THROW_AND_RETURN_IF_NOT_BUFFER(env, args[0], "Session"); - - SSLSessionPointer sess = GetTLSSession(args[0]); + ArrayBufferViewContents sbuf(args[0]); + SSLSessionPointer sess = GetTLSSession(sbuf.data(), sbuf.length()); if (sess == nullptr) - return; + return; // TODO(tniessen): figure out error handling if (!SetTLSSession(w->ssl_, sess)) return env->ThrowError("SSL_set_session error");