Skip to content

Commit 32e6d08

Browse files
nehebnikic
authored andcommitted
Fix compilation without deprecated OpenSSL 1.1 APIs
1 parent 8f4e24e commit 32e6d08

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

ext/ftp/php_ftp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,14 @@ static void ftp_destructor_ftpbuf(zend_resource *rsrc)
318318
PHP_MINIT_FUNCTION(ftp)
319319
{
320320
#ifdef HAVE_FTP_SSL
321+
#if OPENSSL_VERSION_NUMBER < 0x10101000 && !defined(LIBRESSL_VERSION_NUMBER)
321322
SSL_library_init();
322323
OpenSSL_add_all_ciphers();
323324
OpenSSL_add_all_digests();
324325
OpenSSL_add_all_algorithms();
325326

326327
SSL_load_error_strings();
328+
#endif
327329
#endif
328330

329331
le_ftpbuf = zend_register_list_destructors_ex(ftp_destructor_ftpbuf, NULL, le_ftpbuf_name, module_number);

ext/openssl/openssl.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,12 @@ static int X509_get_signature_nid(const X509 *x)
705705

706706
#endif
707707

708+
#define OpenSSL_version SSLeay_version
709+
#define OPENSSL_VERSION SSLEAY_VERSION
710+
#define X509_getm_notBefore X509_get_notBefore
711+
#define X509_getm_notAfter X509_get_notAfter
712+
#define EVP_CIPHER_CTX_reset EVP_CIPHER_CTX_cleanup
713+
708714
#endif
709715
/* }}} */
710716

@@ -1617,7 +1623,7 @@ PHP_MINFO_FUNCTION(openssl)
16171623
{
16181624
php_info_print_table_start();
16191625
php_info_print_table_row(2, "OpenSSL support", "enabled");
1620-
php_info_print_table_row(2, "OpenSSL Library Version", SSLeay_version(SSLEAY_VERSION));
1626+
php_info_print_table_row(2, "OpenSSL Library Version", OpenSSL_version(OPENSSL_VERSION));
16211627
php_info_print_table_row(2, "OpenSSL Header Version", OPENSSL_VERSION_TEXT);
16221628
php_info_print_table_row(2, "Openssl default config", default_ssl_conf_filename);
16231629
php_info_print_table_end();
@@ -2420,11 +2426,11 @@ PHP_FUNCTION(openssl_x509_parse)
24202426
add_assoc_string(return_value, "serialNumberHex", hex_serial);
24212427
OPENSSL_free(hex_serial);
24222428

2423-
php_openssl_add_assoc_asn1_string(return_value, "validFrom", X509_get_notBefore(cert));
2424-
php_openssl_add_assoc_asn1_string(return_value, "validTo", X509_get_notAfter(cert));
2429+
php_openssl_add_assoc_asn1_string(return_value, "validFrom", X509_getm_notBefore(cert));
2430+
php_openssl_add_assoc_asn1_string(return_value, "validTo", X509_getm_notAfter(cert));
24252431

2426-
add_assoc_long(return_value, "validFrom_time_t", php_openssl_asn1_time_to_time_t(X509_get_notBefore(cert)));
2427-
add_assoc_long(return_value, "validTo_time_t", php_openssl_asn1_time_to_time_t(X509_get_notAfter(cert)));
2432+
add_assoc_long(return_value, "validFrom_time_t", php_openssl_asn1_time_to_time_t(X509_getm_notBefore(cert)));
2433+
add_assoc_long(return_value, "validTo_time_t", php_openssl_asn1_time_to_time_t(X509_getm_notAfter(cert)));
24282434

24292435
tmpstr = (char *)X509_alias_get0(cert, NULL);
24302436
if (tmpstr) {
@@ -3525,8 +3531,8 @@ PHP_FUNCTION(openssl_csr_sign)
35253531
php_openssl_store_errors();
35263532
goto cleanup;
35273533
}
3528-
X509_gmtime_adj(X509_get_notBefore(new_cert), 0);
3529-
X509_gmtime_adj(X509_get_notAfter(new_cert), 60*60*24*(long)num_days);
3534+
X509_gmtime_adj(X509_getm_notBefore(new_cert), 0);
3535+
X509_gmtime_adj(X509_getm_notAfter(new_cert), 60*60*24*(long)num_days);
35303536
i = X509_set_pubkey(new_cert, key);
35313537
if (!i) {
35323538
php_openssl_store_errors();
@@ -6197,7 +6203,7 @@ PHP_FUNCTION(openssl_seal)
61976203

61986204
/* allocate one byte extra to make room for \0 */
61996205
buf = emalloc(data_len + EVP_CIPHER_CTX_block_size(ctx));
6200-
EVP_CIPHER_CTX_cleanup(ctx);
6206+
EVP_CIPHER_CTX_reset(ctx);
62016207

62026208
if (EVP_SealInit(ctx, cipher, eks, eksl, &iv_buf[0], pkeys, nkeys) <= 0 ||
62036209
!EVP_SealUpdate(ctx, buf, &len1, (unsigned char *)data, (int)data_len) ||
@@ -6739,7 +6745,7 @@ PHP_OPENSSL_API zend_string* php_openssl_encrypt(char *data, size_t data_len, ch
67396745
if (free_iv) {
67406746
efree(iv);
67416747
}
6742-
EVP_CIPHER_CTX_cleanup(cipher_ctx);
6748+
EVP_CIPHER_CTX_reset(cipher_ctx);
67436749
EVP_CIPHER_CTX_free(cipher_ctx);
67446750
return outbuf;
67456751
}
@@ -6834,7 +6840,7 @@ PHP_OPENSSL_API zend_string* php_openssl_decrypt(char *data, size_t data_len, ch
68346840
if (base64_str) {
68356841
zend_string_release_ex(base64_str, 0);
68366842
}
6837-
EVP_CIPHER_CTX_cleanup(cipher_ctx);
6843+
EVP_CIPHER_CTX_reset(cipher_ctx);
68386844
EVP_CIPHER_CTX_free(cipher_ctx);
68396845
return outbuf;
68406846
}

ext/openssl/xp_ssl.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,19 @@
6060
#define STREAM_CRYPTO_METHOD_TLSv1_2 (1<<5)
6161
#define STREAM_CRYPTO_METHOD_TLSv1_3 (1<<6)
6262

63+
#ifndef OPENSSL_NO_TLS1_METHOD
64+
#define HAVE_TLS1 1
65+
#endif
66+
67+
#ifndef OPENSSL_NO_TLS1_1_METHOD
6368
#define HAVE_TLS11 1
69+
#endif
70+
71+
#ifndef OPENSSL_NO_TLS1_2_METHOD
6472
#define HAVE_TLS12 1
65-
#if OPENSSL_VERSION_NUMBER >= 0x10101000
73+
#endif
74+
75+
#if OPENSSL_VERSION_NUMBER >= 0x10101000 && !defined(OPENSSL_NO_TLS1_3)
6676
#define HAVE_TLS13 1
6777
#endif
6878

@@ -995,9 +1005,11 @@ static int php_openssl_get_crypto_method_ctx_flags(int method_flags) /* {{{ */
9951005
ssl_ctx_options |= SSL_OP_NO_SSLv3;
9961006
}
9971007
#endif
1008+
#ifdef HAVE_TLS1
9981009
if (!(method_flags & STREAM_CRYPTO_METHOD_TLSv1_0)) {
9991010
ssl_ctx_options |= SSL_OP_NO_TLSv1;
10001011
}
1012+
#endif
10011013
#ifdef HAVE_TLS11
10021014
if (!(method_flags & STREAM_CRYPTO_METHOD_TLSv1_1)) {
10031015
ssl_ctx_options |= SSL_OP_NO_TLSv1_1;

0 commit comments

Comments
 (0)