From ebfa88385054cb79460227298a0249ac851e6eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Wed, 23 Feb 2022 00:53:13 +0000 Subject: [PATCH] src: simplify TLSWrap::SetSession --- 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 dce0774e8fa632..d8df43fb9f5d8c 100644 --- a/src/crypto/crypto_common.cc +++ b/src/crypto/crypto_common.cc @@ -116,27 +116,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 2e7ea236b40184..7d8e7552760e77 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");