Skip to content

Commit 904cdca

Browse files
committed
Enable native SSL support in ext/phar
SSL support in ext/phar is enabled either as native (using the system's OpenSSL and its Crypto library linked directly) or as a wrapper provided by ext/openssl. Native OpenSSL support previously couldn't be enabled when building with shared openssl extension: ./configure --with-openssl=shared --enable-phar=shared or: ./configure --with-openssl=shared --enable-phar Some PHP packages build both of these extensions as shared and it makes sense to provide native OpenSSL support in ext/phar also when ext/openssl is build as shared. Shared phar extension with native OpenSSL enabled now gets libcrypto linked directly: ldd modules/phar.so linux-vdso.so.1 libcrypto.so.3 => /lib/x86_64-linux-gnu/libcrypto.so.3 libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 /lib64/ld-linux-x86-64.so.2 The new --with-phar-ssl Autotools configure option enables the SSL support in phar when building without openssl extension or in edge cases when building with phpize: ./configure --with-phar --with-phar-ssl --without-openssl Windows already includes similar option (--enable-phar-native-ssl). This links phar extension with OpenSSL library on Windows instead of the static libeay32, which is not present in Windows OpenSSL builds anymore. Changed tests: - ext/phar/tests/**/phar_setsignaturealgo2.phpt - needs ext/openssl enabled due to openssl_get_privatekey(). - ext/phar/tests/phar_setsignaturealgo.phpt - test for ext/phar with native OpenSSL support and ext/openssl disabled.
1 parent 4d46f26 commit 904cdca

7 files changed

+132
-22
lines changed

UPGRADING.INTERNALS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ PHP 8.4 INTERNALS UPGRADE NOTES
126126
--with-ftp-ssl and --with-mysqlnd-ssl.
127127
- New configure option --with-openssl-legacy-provider to enable OpenSSL
128128
legacy provider.
129+
- New configure option --with-phar-ssl to explicitly enable SSL support in
130+
phar extension when building without openssl extension. When building with
131+
openssl extension (shared or static), SSL support is enabled implicitly.
129132
- COOKIE_IO_FUNCTIONS_T symbol has been removed (use cookie_io_functions_t).
130133
- HAVE_SOCKADDR_UN_SUN_LEN symbol renamed to HAVE_STRUCT_SOCKADDR_UN_SUN_LEN.
131134
- HAVE_UTSNAME_DOMAINNAME symbol renamed to HAVE_STRUCT_UTSNAME_DOMAINNAME.

ext/phar/config.m4

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ PHP_ARG_ENABLE([phar],
44
[Disable phar support])],
55
[yes])
66

7+
PHP_ARG_WITH([phar-ssl],
8+
[whether to explicitly enable SSL support for phar],
9+
[AS_HELP_STRING([--with-phar-ssl],
10+
[Explicitly enable SSL support in phar extension when building without
11+
openssl extension. If openssl extension is enabled at the configure step,
12+
SSL is enabled implicitly.])],
13+
[no],
14+
[no])
15+
716
if test "$PHP_PHAR" != "no"; then
817
PHP_NEW_EXTENSION([phar], m4_normalize([
918
dirstream.c
@@ -18,17 +27,18 @@ if test "$PHP_PHAR" != "no"; then
1827
]),
1928
[$ext_shared],,
2029
[-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
21-
AC_MSG_CHECKING([for phar openssl support])
22-
if test "$PHP_OPENSSL_SHARED" = "yes"; then
23-
AC_MSG_RESULT([no (shared openssl)])
24-
else
25-
if test "$PHP_OPENSSL" = "yes"; then
26-
AC_MSG_RESULT([yes])
27-
AC_DEFINE(PHAR_HAVE_OPENSSL,1,[ ])
28-
else
29-
AC_MSG_RESULT([no])
30-
fi
31-
fi
30+
31+
dnl Empty variable means 'no' (for phpize builds).
32+
AS_VAR_IF([PHP_OPENSSL],, [PHP_OPENSSL=no])
33+
34+
AS_IF([test "x$PHP_OPENSSL" != xno || test "x$PHP_PHAR_SSL" != xno], [dnl
35+
PHP_SETUP_OPENSSL([PHAR_SHARED_LIBADD],
36+
[AC_DEFINE([PHAR_HAVE_OPENSSL], [1],
37+
[Define to 1 if phar extension has native OpenSSL support.])])
38+
PHP_SUBST([PHAR_SHARED_LIBADD])
39+
AC_MSG_NOTICE([phar SSL support enabled])
40+
])
41+
3242
PHP_ADD_EXTENSION_DEP(phar, hash)
3343
PHP_ADD_EXTENSION_DEP(phar, spl)
3444
PHP_ADD_MAKEFILE_FRAGMENT

ext/phar/config.w32

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@ if (PHP_PHAR != "no") {
1313
ADD_FLAG("CFLAGS_PHAR", "/D COMPILE_DL_PHAR ");
1414
}
1515
if (PHP_PHAR_NATIVE_SSL != "no") {
16-
if (CHECK_LIB("libeay32st.lib", "phar")) {
17-
/* We don't really need GDI for this, but there's no
18-
way to avoid linking it in the static openssl build */
19-
ADD_FLAG("LIBS_PHAR", "libeay32st.lib gdi32.lib");
20-
if (PHP_DEBUG == "no") {
21-
/* Silence irrelevant-to-us warning in release builds */
22-
ADD_FLAG("LDFLAGS_PHAR", "/IGNORE:4089 ");
23-
}
16+
var ret = SETUP_OPENSSL("phar", PHP_PHAR);
17+
18+
if (ret >= 2) {
2419
AC_DEFINE('PHAR_HAVE_OPENSSL', 1);
2520
STDOUT.WriteLine(' Native OpenSSL support in Phar enabled');
2621
} else {
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
--TEST--
2+
Phar::setSignatureAlgorithm() with native OpenSSL and without ext/openssl
3+
--EXTENSIONS--
4+
phar
5+
--SKIPIF--
6+
<?php
7+
if (extension_loaded("openssl")) die("skip ext/openssl must be disabled for this test");
8+
$arr = Phar::getSupportedSignatures();
9+
if (!in_array("OpenSSL", $arr)) die("skip openssl support required");
10+
?>
11+
--INI--
12+
phar.require_hash=0
13+
phar.readonly=0
14+
--FILE--
15+
<?php
16+
$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar';
17+
$p = new Phar($fname);
18+
$p['file1.txt'] = 'hi';
19+
var_dump($p->getSignature());
20+
$p->setSignatureAlgorithm(Phar::MD5);
21+
var_dump($p->getSignature());
22+
$p->setSignatureAlgorithm(Phar::SHA1);
23+
var_dump($p->getSignature());
24+
try {
25+
$p->setSignatureAlgorithm(Phar::SHA256);
26+
var_dump($p->getSignature());
27+
} catch (Exception $e) {
28+
echo $e->getMessage();
29+
}
30+
try {
31+
$p->setSignatureAlgorithm(Phar::SHA512);
32+
var_dump($p->getSignature());
33+
} catch (Exception $e) {
34+
echo $e->getMessage();
35+
}
36+
try {
37+
$pkey = '-----BEGIN PRIVATE KEY-----
38+
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMDcANSIpkgSF6Rh
39+
KHM8JncsVuCsO5XjiMf3g50lB+poJAG9leoygbVtY55h9tzeI7SAdZbdIoHbtJ/V
40+
kGdzlzX5jMGbH1sWKk5fZbai4pLZigd4ihH2V4M27jKrAGy6CAU8ZU/Ez2KQQj5g
41+
A4ZVMJ3iZXlqCmRWwcs0lZvP+c9XAgMBAAECgYAaJLioFu4TjwBNdC47kMfWF9if
42+
FDnvk6yTDuZ0gvSTvhJDeiO8X6Rdp7p9WeJRBnvomBFYphlraREPKbAtlenFVuIY
43+
v10O9BjxkQ0O1Y7L2ztMO3E2LFtmWgoGimAnsbUHTkuB61Hd2AWdA7C357eQ67vZ
44+
GlLu2HIFpSbzMcJFIQJBAPD6Hm7ETuL0ILwofImXAahHbwpmCtKmjvjJaFD5vWXP
45+
FD6uTbBOgUP+n5Y17+d/vxhSX9yrQueAIodju3bbxUsCQQDM4fMCO4OUYbMroql7
46+
ruIqBd34akrA+v2JoV+bMAE6RHBC6DgsI3uySbMJfmnPGoxlbXE0gKN4ONawwDd3
47+
gTKlAkEAnJc8DWidhpdzajG488Pf/NUmkBBNOiOnxn1Cv1P6Ql01X6HutAHfuCqO
48+
05KLKdj2ebyVtJTJrhuy1F33pL4dTwJBAKnIEB3ofahnshdV64cALJFQXVpvktUK
49+
6TG1Vcn/ZPUJI9J+J5aELQxYwJH8fOhQAspGgEpW06Bb0aWVFCHnIbUCQBFVhu+P
50+
RcHLpdSl7lZmws1bCnDUmt5GzKBw9diHxuyfGEJ0c0clDTWVEMyO80u0jxrliMkT
51+
8h5bvpPaY8KIlkg=
52+
-----END PRIVATE KEY-----';
53+
$p->setSignatureAlgorithm(Phar::OPENSSL, $pkey);
54+
var_dump($p->getSignature());
55+
} catch (Exception $e) {
56+
echo $e->getMessage();
57+
}
58+
?>
59+
--CLEAN--
60+
<?php
61+
unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar');
62+
?>
63+
--EXPECTF--
64+
array(2) {
65+
["hash"]=>
66+
string(%d) "%s"
67+
["hash_type"]=>
68+
string(7) "SHA-256"
69+
}
70+
array(2) {
71+
["hash"]=>
72+
string(%d) "%s"
73+
["hash_type"]=>
74+
string(3) "MD5"
75+
}
76+
array(2) {
77+
["hash"]=>
78+
string(%d) "%s"
79+
["hash_type"]=>
80+
string(5) "SHA-1"
81+
}
82+
array(2) {
83+
["hash"]=>
84+
string(%d) "%s"
85+
["hash_type"]=>
86+
string(7) "SHA-256"
87+
}
88+
array(2) {
89+
["hash"]=>
90+
string(%d) "%s"
91+
["hash_type"]=>
92+
string(7) "SHA-512"
93+
}
94+
array(2) {
95+
["hash"]=>
96+
string(%d) "%s"
97+
["hash_type"]=>
98+
string(7) "OpenSSL"
99+
}

ext/phar/tests/phar_setsignaturealgo2.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
--TEST--
2-
Phar::setSupportedSignatures() with hash
2+
Phar::setSignatureAlgorithm() with hash
33
--EXTENSIONS--
4+
openssl
45
phar
56
--SKIPIF--
67
<?php

ext/phar/tests/tar/phar_setsignaturealgo2.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
--TEST--
2-
Phar::setSupportedSignatures() with hash, tar-based
2+
Phar::setSignatureAlgorithm() with hash, tar-based
33
--EXTENSIONS--
4+
openssl
45
phar
56
--SKIPIF--
67
<?php

ext/phar/tests/zip/phar_setsignaturealgo2.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
--TEST--
2-
Phar::setSupportedSignatures() with hash, zip-based
2+
Phar::setSignatureAlgorithm() with hash, zip-based
33
--EXTENSIONS--
4+
openssl
45
phar
56
--SKIPIF--
67
<?php

0 commit comments

Comments
 (0)