@@ -523,8 +523,12 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx,
523523 for (int i = 0 ; i < sk_X509_num (extra_certs); i++) {
524524 X509* ca = sk_X509_value (extra_certs, i);
525525
526+ #ifdef LIBRESSL_VERSION_NUMBER
527+ r = SSL_CTX_add_extra_chain_cert (ctx, ca);
528+ #else
526529 // NOTE: Increments reference count on `ca`
527530 r = SSL_CTX_add1_chain_cert (ctx, ca);
531+ #endif // LIBRESSL_VERSION_NUMBER
528532
529533 if (!r) {
530534 ret = 0 ;
@@ -680,7 +684,7 @@ void SecureContext::SetCert(const FunctionCallbackInfo<Value>& args) {
680684}
681685
682686
683- #if OPENSSL_VERSION_NUMBER < 0x10100000L && !defined(OPENSSL_IS_BORINGSSL)
687+ #if ( OPENSSL_VERSION_NUMBER < 0x10100000L && !defined(OPENSSL_IS_BORINGSSL)) || defined(LIBRESSL_VERSION_NUMBER )
684688// This section contains OpenSSL 1.1.0 functions reimplemented for OpenSSL
685689// 1.0.2 so that the following code can be written without lots of #if lines.
686690
@@ -693,7 +697,7 @@ static int X509_up_ref(X509* cert) {
693697 CRYPTO_add (&cert->references , 1 , CRYPTO_LOCK_X509);
694698 return 1 ;
695699}
696- #endif // OPENSSL_VERSION_NUMBER < 0x10100000L && !OPENSSL_IS_BORINGSSL
700+ #endif // ( OPENSSL_VERSION_NUMBER < 0x10100000L && !OPENSSL_IS_BORINGSSL) || defined(LIBRESSL_VERSION_NUMBER)
697701
698702
699703static X509_STORE* NewRootCertStore () {
@@ -1153,7 +1157,7 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo<Value>& args) {
11531157
11541158
11551159void SecureContext::SetFreeListLength (const FunctionCallbackInfo<Value>& args) {
1156- #if OPENSSL_VERSION_NUMBER < 0x10100000L && !defined(OPENSSL_IS_BORINGSSL)
1160+ #if OPENSSL_VERSION_NUMBER < 0x10100000L && !defined(OPENSSL_IS_BORINGSSL) && !defined(LIBRESSL_VERSION_NUMBER)
11571161 // |freelist_max_len| was removed in OpenSSL 1.1.0. In that version OpenSSL
11581162 // mallocs and frees buffers directly, without the use of a freelist.
11591163 SecureContext* wrap;
@@ -1930,6 +1934,10 @@ void SSLWrap<Base>::RequestOCSP(
19301934template <class Base >
19311935void SSLWrap<Base>::GetEphemeralKeyInfo(
19321936 const v8::FunctionCallbackInfo<v8::Value>& args) {
1937+ #ifdef LIBRESSL_VERSION_NUMBER
1938+ Environment* env = Environment::GetCurrent (args);
1939+ env->ThrowError (" getEphemeralKeyInfo() not supported when using LibreSSL" );
1940+ #else
19331941 Base* w;
19341942 ASSIGN_OR_RETURN_UNWRAP (&w, args.Holder ());
19351943 Environment* env = Environment::GetCurrent (args);
@@ -1968,7 +1976,8 @@ void SSLWrap<Base>::GetEphemeralKeyInfo(
19681976 EVP_PKEY_free (key);
19691977 }
19701978
1971- return args.GetReturnValue ().Set (info);
1979+ args.GetReturnValue ().Set (info);
1980+ #endif // LIBRESSL_VERSION_NUMBER
19721981}
19731982
19741983
@@ -2449,8 +2458,9 @@ void SSLWrap<Base>::CertCbDone(const FunctionCallbackInfo<Value>& args) {
24492458 w->sni_context_ .Reset ();
24502459 w->sni_context_ .Reset (env->isolate (), ctx);
24512460
2452- int rv;
2461+ int rv = 1 ;
24532462
2463+ #ifndef LIBRESSL_VERSION_NUMBER
24542464 // NOTE: reference count is not increased by this API methods
24552465 X509* x509 = SSL_CTX_get0_certificate (sc->ctx_ );
24562466 EVP_PKEY* pkey = SSL_CTX_get0_privatekey (sc->ctx_ );
@@ -2463,6 +2473,8 @@ void SSLWrap<Base>::CertCbDone(const FunctionCallbackInfo<Value>& args) {
24632473 rv = SSL_use_PrivateKey (w->ssl_ , pkey);
24642474 if (rv && chain != nullptr )
24652475 rv = SSL_set1_chain (w->ssl_ , chain);
2476+ #endif // LIBRESSL_VERSION_NUMBER
2477+
24662478 if (rv)
24672479 rv = w->SetCACerts (sc);
24682480 if (!rv) {
@@ -2526,9 +2538,11 @@ void SSLWrap<Base>::SetSNIContext(SecureContext* sc) {
25262538
25272539template <class Base >
25282540int SSLWrap<Base>::SetCACerts(SecureContext* sc) {
2541+ #ifndef LIBRESSL_VERSION_NUMBER
25292542 int err = SSL_set1_verify_cert_store (ssl_, SSL_CTX_get_cert_store (sc->ctx_ ));
25302543 if (err != 1 )
25312544 return err;
2545+ #endif // LIBRESSL_VERSION_NUMBER
25322546
25332547 STACK_OF (X509_NAME)* list = SSL_dup_CA_list (
25342548 SSL_CTX_get_client_CA_list (sc->ctx_ ));
@@ -2841,7 +2855,7 @@ inline int VerifyCallback(int preverify_ok, X509_STORE_CTX* ctx) {
28412855 SSL* ssl = static_cast <SSL*>(
28422856 X509_STORE_CTX_get_ex_data (ctx, SSL_get_ex_data_X509_STORE_CTX_idx ()));
28432857
2844- if (SSL_is_server ( ssl) )
2858+ if (ssl-> server )
28452859 return 1 ;
28462860
28472861 // Client needs to check if the server cert is listed in the
@@ -2924,7 +2938,9 @@ void Connection::New(const FunctionCallbackInfo<Value>& args) {
29242938
29252939 InitNPN (sc);
29262940
2941+ #ifndef LIBRESSL_VERSION_NUMBER
29272942 SSL_set_cert_cb (conn->ssl_ , SSLWrap<Connection>::SSLCertCallback, conn);
2943+ #endif // LIBRESSL_VERSION_NUMBER
29282944
29292945#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
29302946 if (is_server) {
@@ -5976,11 +5992,11 @@ void SetEngine(const FunctionCallbackInfo<Value>& args) {
59765992#endif // !OPENSSL_NO_ENGINE
59775993
59785994void GetFipsCrypto (const FunctionCallbackInfo<Value>& args) {
5979- if ( FIPS_mode ()) {
5980- args.GetReturnValue ().Set (1 );
5981- } else {
5982- args.GetReturnValue ().Set (0 );
5983- }
5995+ # ifdef NODE_FIPS_MODE
5996+ args.GetReturnValue ().Set (FIPS_mode () );
5997+ # else
5998+ args.GetReturnValue ().Set (0 );
5999+ # endif
59846000}
59856001
59866002void SetFipsCrypto (const FunctionCallbackInfo<Value>& args) {
0 commit comments