@@ -912,6 +912,29 @@ void TLSWrap::EnableSessionCallbacks(
912
912
wrap);
913
913
}
914
914
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
+ }
915
938
916
939
void TLSWrap::DestroySSL (const FunctionCallbackInfo<Value>& args) {
917
940
TLSWrap* wrap;
@@ -1057,6 +1080,8 @@ void TLSWrap::Initialize(Local<Object> target,
1057
1080
1058
1081
env->SetMethod (target, " wrap" , TLSWrap::Wrap);
1059
1082
1083
+ NODE_DEFINE_CONSTANT (target, HAVE_SSL_TRACE);
1084
+
1060
1085
Local<FunctionTemplate> t = BaseObject::MakeLazilyInitializedJSTemplate (env);
1061
1086
Local<String> tlsWrapString =
1062
1087
FIXED_ONE_BYTE_STRING (env->isolate (), " TLSWrap" );
@@ -1080,6 +1105,7 @@ void TLSWrap::Initialize(Local<Object> target,
1080
1105
env->SetProtoMethod (t, " start" , Start);
1081
1106
env->SetProtoMethod (t, " setVerifyMode" , SetVerifyMode);
1082
1107
env->SetProtoMethod (t, " enableSessionCallbacks" , EnableSessionCallbacks);
1108
+ env->SetProtoMethod (t, " enableTrace" , EnableTrace);
1083
1109
env->SetProtoMethod (t, " destroySSL" , DestroySSL);
1084
1110
env->SetProtoMethod (t, " enableCertCb" , EnableCertCb);
1085
1111
0 commit comments