Skip to content

Commit 68c3d09

Browse files
committed
Fix bug #76174 (openssl extension fails to build with LibreSSL 2.7)
1 parent bc6ddb7 commit 68c3d09

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ PHP NEWS
99
- OpenSSL:
1010
. Fixed bug #76296 (openssl_pkey_get_public does not respect open_basedir).
1111
(Erik Lax, Jakub Zelenka)
12+
. Fixed bug #76174 (openssl extension fails to build with LibreSSL 2.7).
13+
(Jakub Zelenka)
1214

1315
- Standard:
1416
. Fixed bug #76335 ("link(): Bad file descriptor" with non-ASCII path).

ext/openssl/openssl.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
#ifdef HAVE_OPENSSL_MD2_H
7474
#define OPENSSL_ALGO_MD2 4
7575
#endif
76-
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined (LIBRESSL_VERSION_NUMBER)
76+
#if PHP_OPENSSL_API_VERSION < 0x10100
7777
#define OPENSSL_ALGO_DSS1 5
7878
#endif
7979
#define OPENSSL_ALGO_SHA224 6
@@ -560,7 +560,7 @@ ZEND_GET_MODULE(openssl)
560560
#endif
561561

562562
/* {{{ OpenSSL compatibility functions and macros */
563-
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined (LIBRESSL_VERSION_NUMBER)
563+
#if PHP_OPENSSL_API_VERSION < 0x10100
564564
#define EVP_PKEY_get0_RSA(_pkey) _pkey->pkey.rsa
565565
#define EVP_PKEY_get0_DH(_pkey) _pkey->pkey.dh
566566
#define EVP_PKEY_get0_DSA(_pkey) _pkey->pkey.dsa
@@ -677,7 +677,7 @@ static const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *asn1)
677677
return M_ASN1_STRING_data(asn1);
678678
}
679679

680-
#if OPENSSL_VERSION_NUMBER < 0x10002000L || defined (LIBRESSL_VERSION_NUMBER)
680+
#if PHP_OPENSSL_API_VERSION < 0x10002
681681

682682
static int X509_get_signature_nid(const X509 *x)
683683
{
@@ -1237,7 +1237,7 @@ static void php_openssl_dispose_config(struct php_x509_request * req) /* {{{ */
12371237
}
12381238
/* }}} */
12391239

1240-
#if defined(PHP_WIN32) || (OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER))
1240+
#if defined(PHP_WIN32) || PHP_OPENSSL_API_VERSION >= 0x10100
12411241
#define PHP_OPENSSL_RAND_ADD_TIME() ((void) 0)
12421242
#else
12431243
#define PHP_OPENSSL_RAND_ADD_TIME() php_openssl_rand_add_timeval()
@@ -1324,7 +1324,7 @@ static EVP_MD * php_openssl_get_evp_md_from_algo(zend_long algo) { /* {{{ */
13241324
mdtype = (EVP_MD *) EVP_md2();
13251325
break;
13261326
#endif
1327-
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined (LIBRESSL_VERSION_NUMBER)
1327+
#if PHP_OPENSSL_API_VERSION < 0x10100
13281328
case OPENSSL_ALGO_DSS1:
13291329
mdtype = (EVP_MD *) EVP_dss1();
13301330
break;
@@ -1450,7 +1450,7 @@ PHP_MINIT_FUNCTION(openssl)
14501450
#ifdef HAVE_OPENSSL_MD2_H
14511451
REGISTER_LONG_CONSTANT("OPENSSL_ALGO_MD2", OPENSSL_ALGO_MD2, CONST_CS|CONST_PERSISTENT);
14521452
#endif
1453-
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined (LIBRESSL_VERSION_NUMBER)
1453+
#if PHP_OPENSSL_API_VERSION < 0x10100
14541454
REGISTER_LONG_CONSTANT("OPENSSL_ALGO_DSS1", OPENSSL_ALGO_DSS1, CONST_CS|CONST_PERSISTENT);
14551455
#endif
14561456
REGISTER_LONG_CONSTANT("OPENSSL_ALGO_SHA224", OPENSSL_ALGO_SHA224, CONST_CS|CONST_PERSISTENT);
@@ -3620,7 +3620,7 @@ PHP_FUNCTION(openssl_csr_get_public_key)
36203620
RETURN_FALSE;
36213621
}
36223622

3623-
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
3623+
#if PHP_OPENSSL_API_VERSION >= 0x10100
36243624
/* Due to changes in OpenSSL 1.1 related to locking when decoding CSR,
36253625
* the pub key is not changed after assigning. It means if we pass
36263626
* a private key, it will be returned including the private part.
@@ -3631,7 +3631,7 @@ PHP_FUNCTION(openssl_csr_get_public_key)
36313631
/* Retrieve the public key from the CSR */
36323632
tpubkey = X509_REQ_get_pubkey(csr);
36333633

3634-
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
3634+
#if PHP_OPENSSL_API_VERSION >= 0x10100
36353635
/* We need to free the CSR as it was duplicated */
36363636
X509_REQ_free(csr);
36373637
#endif

ext/openssl/php_openssl.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ extern zend_module_entry openssl_module_entry;
2929
#include "php_version.h"
3030
#define PHP_OPENSSL_VERSION PHP_VERSION
3131

32+
#include <openssl/opensslv.h>
33+
#if defined(LIBRESSL_VERSION_NUMBER)
34+
/* LibreSSL version check */
35+
#if LIBRESSL_VERSION_NUMBER < 0x20700000L
36+
#define PHP_OPENSSL_API_VERSION 0x10001
37+
#else
38+
#define PHP_OPENSSL_API_VERSION 0x10100
39+
#endif
40+
#else
41+
/* OpenSSL version check */
42+
#if OPENSSL_VERSION_NUMBER < 0x10002000L
43+
#define PHP_OPENSSL_API_VERSION 0x10001
44+
#elif OPENSSL_VERSION_NUMBER < 0x10100000L
45+
#define PHP_OPENSSL_API_VERSION 0x10002
46+
#else
47+
#define PHP_OPENSSL_API_VERSION 0x10100
48+
#endif
49+
#endif
50+
3251
#define OPENSSL_RAW_DATA 1
3352
#define OPENSSL_ZERO_PADDING 2
3453
#define OPENSSL_DONT_ZERO_PAD_KEY 4

ext/openssl/xp_ssl.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
/* Used for peer verification in windows */
9292
#define PHP_X509_NAME_ENTRY_TO_UTF8(ne, i, out) ASN1_STRING_to_UTF8(&out, X509_NAME_ENTRY_get_data(X509_NAME_get_entry(ne, i)))
9393

94-
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined (LIBRESSL_VERSION_NUMBER)
94+
#if PHP_OPENSSL_API_VERSION < 0x10100
9595
static RSA *tmp_rsa_cb(SSL *s, int is_export, int keylength);
9696
#endif
9797

@@ -1128,7 +1128,7 @@ static void init_server_reneg_limit(php_stream *stream, php_openssl_netstream_da
11281128
}
11291129
/* }}} */
11301130

1131-
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined (LIBRESSL_VERSION_NUMBER)
1131+
#if PHP_OPENSSL_API_VERSION < 0x10100
11321132
static RSA *tmp_rsa_cb(SSL *s, int is_export, int keylength)
11331133
{
11341134
BIGNUM *bn = NULL;
@@ -1197,7 +1197,7 @@ static int set_server_dh_param(php_stream * stream, SSL_CTX *ctx) /* {{{ */
11971197
}
11981198
/* }}} */
11991199

1200-
#if defined(HAVE_ECDH) && (OPENSSL_VERSION_NUMBER < 0x10100000L || defined (LIBRESSL_VERSION_NUMBER))
1200+
#if defined(HAVE_ECDH) && PHP_OPENSSL_API_VERSION < 0x10100
12011201
static int set_server_ecdh_curve(php_stream *stream, SSL_CTX *ctx) /* {{{ */
12021202
{
12031203
zval *zvcurve;
@@ -1240,13 +1240,13 @@ static int set_server_specific_opts(php_stream *stream, SSL_CTX *ctx) /* {{{ */
12401240
zval *zv;
12411241
long ssl_ctx_options = SSL_CTX_get_options(ctx);
12421242

1243-
#if defined(HAVE_ECDH) && (OPENSSL_VERSION_NUMBER < 0x10100000L || defined (LIBRESSL_VERSION_NUMBER))
1243+
#if defined(HAVE_ECDH) && PHP_OPENSSL_API_VERSION < 0x10100
12441244
if (set_server_ecdh_curve(stream, ctx) == FAILURE) {
12451245
return FAILURE;
12461246
}
12471247
#endif
12481248

1249-
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined (LIBRESSL_VERSION_NUMBER)
1249+
#if PHP_OPENSSL_API_VERSION < 0x10100
12501250
SSL_CTX_set_tmp_rsa_callback(ctx, tmp_rsa_cb);
12511251
#endif
12521252
/* We now use tmp_rsa_cb to generate a key of appropriate size whenever necessary */

0 commit comments

Comments
 (0)