Skip to content

Commit

Permalink
src: simplify TLSWrap::SetSession
Browse files Browse the repository at this point in the history
PR-URL: #42087
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
  • Loading branch information
tniessen authored and sxa committed Mar 7, 2022
1 parent 97f5ced commit f0558d8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
15 changes: 0 additions & 15 deletions src/crypto/crypto_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,12 @@ MaybeLocal<Value> 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<Value> val) {
if (!val->IsArrayBufferView())
return SSLSessionPointer();
ArrayBufferViewContents<unsigned char> sbuf(val.As<ArrayBufferView>());
return GetTLSSession(sbuf.data(), sbuf.length());
}

SSLSessionPointer GetTLSSession(const unsigned char* buf, size_t length) {
return SSLSessionPointer(d2i_SSL_SESSION(nullptr, &buf, length));
}
Expand Down
7 changes: 0 additions & 7 deletions src/crypto/crypto_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,10 @@ v8::MaybeLocal<v8::Value> GetSSLOCSPResponse(
SSL* ssl,
v8::Local<v8::Value> 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<v8::Value> val);

SSLSessionPointer GetTLSSession(const unsigned char* buf, size_t length);

long VerifyPeerCertificate( // NOLINT(runtime/int)
Expand Down
6 changes: 3 additions & 3 deletions src/crypto/crypto_tls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1667,10 +1667,10 @@ void TLSWrap::SetSession(const FunctionCallbackInfo<Value>& 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<unsigned char> 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");
Expand Down

0 comments on commit f0558d8

Please sign in to comment.