Skip to content

Commit b98787f

Browse files
IlyasShabiaduh95
authored andcommitted
src: reuse crypto GetCipherInfo in DTLS session
Signed-off-by: ishabi <ilyasshabi94@gmail.com> PR-URL: #66022 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent aa531a3 commit b98787f

1 file changed

Lines changed: 3 additions & 25 deletions

File tree

src/dtls/dtls_session.cc

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <aliased_struct-inl.h>
88
#include <async_wrap-inl.h>
99
#include <base_object-inl.h>
10+
#include <crypto/crypto_common.h>
1011
#include <crypto/crypto_x509.h>
1112
#include <env-inl.h>
1213
#include <memory_tracker-inl.h>
@@ -1034,31 +1035,8 @@ void DTLSSession::GetCipher(const FunctionCallbackInfo<Value>& args) {
10341035
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());
10351036
Environment* env = session->env();
10361037

1037-
const SSL_CIPHER* cipher = SSL_get_current_cipher(session->ssl_.get());
1038-
if (cipher == nullptr) return;
1039-
1040-
// Build the three strings up front so a failure leaves the return value
1041-
// untouched rather than a half-populated object.
1042-
Local<Value> name;
1043-
Local<Value> standard_name;
1044-
Local<Value> version;
1045-
if (!ToV8Value(env->context(), SSL_CIPHER_get_name(cipher)).ToLocal(&name) ||
1046-
!ToV8Value(env->context(), SSL_CIPHER_standard_name(cipher))
1047-
.ToLocal(&standard_name) ||
1048-
!ToV8Value(env->context(), SSL_CIPHER_get_version(cipher))
1049-
.ToLocal(&version)) {
1050-
return;
1051-
}
1052-
1053-
Local<Object> info = Object::New(env->isolate());
1054-
info->Set(env->context(), env->name_string(), name).Check();
1055-
info->Set(env->context(),
1056-
FIXED_ONE_BYTE_STRING(env->isolate(), "standardName"),
1057-
standard_name)
1058-
.Check();
1059-
info->Set(env->context(), env->version_string(), version).Check();
1060-
1061-
args.GetReturnValue().Set(info);
1038+
args.GetReturnValue().Set(
1039+
crypto::GetCipherInfo(env, session->ssl_).FromMaybe(Local<Object>()));
10621040
}
10631041

10641042
void DTLSSession::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {

0 commit comments

Comments
 (0)