Skip to content

Commit

Permalink
src: colocate GetSSLOCSPResponse with callsite
Browse files Browse the repository at this point in the history
Only used one place so move it out of crypto-common
  • Loading branch information
jasnell committed Dec 31, 2024
1 parent bd25380 commit 7b5bf07
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
19 changes: 0 additions & 19 deletions src/crypto/crypto_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,6 @@ using v8::Value;

namespace crypto {

MaybeLocal<Value> GetSSLOCSPResponse(
Environment* env,
SSL* ssl,
Local<Value> default_value) {
const unsigned char* resp;
int len = SSL_get_tlsext_status_ocsp_resp(ssl, &resp);
if (resp == nullptr)
return default_value;

Local<Value> ret;
MaybeLocal<Object> maybe_buffer =
Buffer::Copy(env, reinterpret_cast<const char*>(resp), len);

if (!maybe_buffer.ToLocal(&ret))
return MaybeLocal<Value>();

return ret;
}

bool SetTLSSession(
const SSLPointer& ssl,
const SSLSessionPointer& session) {
Expand Down
5 changes: 0 additions & 5 deletions src/crypto/crypto_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
namespace node {
namespace crypto {

v8::MaybeLocal<v8::Value> GetSSLOCSPResponse(
Environment* env,
SSL* ssl,
v8::Local<v8::Value> default_value);

bool SetTLSSession(
const SSLPointer& ssl,
const SSLSessionPointer& session);
Expand Down
16 changes: 15 additions & 1 deletion src/crypto/crypto_tls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,20 @@ int SelectALPNCallback(
: SSL_TLSEXT_ERR_ALERT_FATAL;
}

MaybeLocal<Value> 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<Value> ret;
MaybeLocal<Object> maybe_buffer =
Buffer::Copy(env, reinterpret_cast<const char*>(resp), len);

if (!maybe_buffer.ToLocal(&ret)) return MaybeLocal<Value>();

return ret;
}

int TLSExtStatusCallback(SSL* s, void* arg) {
TLSWrap* w = static_cast<TLSWrap*>(SSL_get_app_data(s));
Environment* env = w->env();
Expand All @@ -311,7 +325,7 @@ int TLSExtStatusCallback(SSL* s, void* arg) {
if (w->is_client()) {
// Incoming response
Local<Value> 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
Expand Down

0 comments on commit 7b5bf07

Please sign in to comment.