From 7b5bf07e7946a5621bfb620121fdce5a6c6b19e8 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Tue, 31 Dec 2024 14:25:58 -0800 Subject: [PATCH] src: colocate GetSSLOCSPResponse with callsite Only used one place so move it out of crypto-common --- src/crypto/crypto_common.cc | 19 ------------------- src/crypto/crypto_common.h | 5 ----- src/crypto/crypto_tls.cc | 16 +++++++++++++++- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc index 4bdb6c232238b51..eeacbf35186219f 100644 --- a/src/crypto/crypto_common.cc +++ b/src/crypto/crypto_common.cc @@ -43,25 +43,6 @@ using v8::Value; namespace crypto { -MaybeLocal GetSSLOCSPResponse( - Environment* env, - SSL* ssl, - Local default_value) { - const unsigned char* resp; - int len = SSL_get_tlsext_status_ocsp_resp(ssl, &resp); - if (resp == nullptr) - return default_value; - - Local ret; - MaybeLocal maybe_buffer = - Buffer::Copy(env, reinterpret_cast(resp), len); - - if (!maybe_buffer.ToLocal(&ret)) - return MaybeLocal(); - - return ret; -} - bool SetTLSSession( const SSLPointer& ssl, const SSLSessionPointer& session) { diff --git a/src/crypto/crypto_common.h b/src/crypto/crypto_common.h index b49a0e8eb5a9fec..e264137ac5767a2 100644 --- a/src/crypto/crypto_common.h +++ b/src/crypto/crypto_common.h @@ -22,11 +22,6 @@ namespace node { namespace crypto { -v8::MaybeLocal GetSSLOCSPResponse( - Environment* env, - SSL* ssl, - v8::Local default_value); - bool SetTLSSession( const SSLPointer& ssl, const SSLSessionPointer& session); diff --git a/src/crypto/crypto_tls.cc b/src/crypto/crypto_tls.cc index 9c7ce8495214997..2ab407b5c9700af 100644 --- a/src/crypto/crypto_tls.cc +++ b/src/crypto/crypto_tls.cc @@ -303,6 +303,20 @@ int SelectALPNCallback( : SSL_TLSEXT_ERR_ALERT_FATAL; } +MaybeLocal GetSSLOCSPResponse(Environment* env, SSL* ssl) { + const unsigned char* resp; + int len = SSL_get_tlsext_status_ocsp_resp(ssl, &resp); + if (resp == nullptr) return Null(env->isolate()); + + Local ret; + MaybeLocal maybe_buffer = + Buffer::Copy(env, reinterpret_cast(resp), len); + + if (!maybe_buffer.ToLocal(&ret)) return MaybeLocal(); + + return ret; +} + int TLSExtStatusCallback(SSL* s, void* arg) { TLSWrap* w = static_cast(SSL_get_app_data(s)); Environment* env = w->env(); @@ -311,7 +325,7 @@ int TLSExtStatusCallback(SSL* s, void* arg) { if (w->is_client()) { // Incoming response Local arg; - if (GetSSLOCSPResponse(env, s, Null(env->isolate())).ToLocal(&arg)) + if (GetSSLOCSPResponse(env, s).ToLocal(&arg)) w->MakeCallback(env->onocspresponse_string(), 1, &arg); // No async acceptance is possible, so always return 1 to accept the