@@ -912,6 +912,29 @@ void TLSWrap::EnableSessionCallbacks(
912912 wrap);
913913}
914914
915+ // Check required capabilities were not excluded from the OpenSSL build:
916+ // - OPENSSL_NO_SSL_TRACE excludes SSL_trace()
917+ // - OPENSSL_NO_STDIO excludes BIO_new_fp()
918+ // HAVE_SSL_TRACE is available on the internal tcp_wrap binding for the tests.
919+ #if defined(OPENSSL_NO_SSL_TRACE) || defined(OPENSSL_NO_STDIO)
920+ # define HAVE_SSL_TRACE 0
921+ #else
922+ # define HAVE_SSL_TRACE 1
923+ #endif
924+
925+ void TLSWrap::EnableTrace (
926+ const FunctionCallbackInfo<Value>& args) {
927+ TLSWrap* wrap;
928+ ASSIGN_OR_RETURN_UNWRAP (&wrap, args.Holder ());
929+
930+ #if HAVE_SSL_TRACE
931+ if (wrap->ssl_ ) {
932+ BIO* b = BIO_new_fp (stderr, BIO_NOCLOSE | BIO_FP_TEXT);
933+ SSL_set_msg_callback (wrap->ssl_ .get (), SSL_trace);
934+ SSL_set_msg_callback_arg (wrap->ssl_ .get (), b);
935+ }
936+ #endif
937+ }
915938
916939void TLSWrap::DestroySSL (const FunctionCallbackInfo<Value>& args) {
917940 TLSWrap* wrap;
@@ -1057,6 +1080,8 @@ void TLSWrap::Initialize(Local<Object> target,
10571080
10581081 env->SetMethod (target, " wrap" , TLSWrap::Wrap);
10591082
1083+ NODE_DEFINE_CONSTANT (target, HAVE_SSL_TRACE);
1084+
10601085 Local<FunctionTemplate> t = BaseObject::MakeLazilyInitializedJSTemplate (env);
10611086 Local<String> tlsWrapString =
10621087 FIXED_ONE_BYTE_STRING (env->isolate (), " TLSWrap" );
@@ -1080,6 +1105,7 @@ void TLSWrap::Initialize(Local<Object> target,
10801105 env->SetProtoMethod (t, " start" , Start);
10811106 env->SetProtoMethod (t, " setVerifyMode" , SetVerifyMode);
10821107 env->SetProtoMethod (t, " enableSessionCallbacks" , EnableSessionCallbacks);
1108+ env->SetProtoMethod (t, " enableTrace" , EnableTrace);
10831109 env->SetProtoMethod (t, " destroySSL" , DestroySSL);
10841110 env->SetProtoMethod (t, " enableCertCb" , EnableCertCb);
10851111
0 commit comments