Skip to content

Commit f2b2b1c

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. Windows already includes similar option (--enable-phar-native-ssl): ./configure --with-phar --with-phar-ssl --without-openssl 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 a6b5439 commit f2b2b1c

6 files changed

+129
-14
lines changed

UPGRADING.INTERNALS

+3
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ PHP 8.4 INTERNALS UPGRADE NOTES
142142
- PDO extensions in php-src don't have the include flag -I$pdo_cv_inc_path
143143
directory anymore.
144144
- M4 macro PHP_SETUP_OPENSSL doesn't accept the 3rd argument anymore.
145+
- Added configure option --with-phar-ssl to explicitly enable SSL support
146+
in phar when not building with openssl extension. When building with
147+
openssl extension (shared or static), SSL support is enabled implicitly.
145148

146149
c. Windows build system changes
147150
- The configure options --with-oci8-11g, --with-oci8-12c, --with-oci8-19 have

ext/phar/config.m4

+21-11
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,29 @@ 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, util.c tar.c zip.c stream.c func_interceptors.c dirstream.c phar.c phar_object.c phar_path_check.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
9-
AC_MSG_CHECKING([for phar openssl support])
10-
if test "$PHP_OPENSSL_SHARED" = "yes"; then
11-
AC_MSG_RESULT([no (shared openssl)])
12-
else
13-
if test "$PHP_OPENSSL" = "yes"; then
14-
AC_MSG_RESULT([yes])
15-
AC_DEFINE(PHAR_HAVE_OPENSSL,1,[ ])
16-
else
17-
AC_MSG_RESULT([no])
18-
fi
19-
fi
18+
19+
dnl Empty variable means 'no' (for phpize builds).
20+
AS_VAR_IF([PHP_OPENSSL],, [PHP_OPENSSL=no])
21+
22+
AS_IF([test "$PHP_OPENSSL" != no || test "$PHP_PHAR_SSL" != no], [dnl
23+
PHP_SETUP_OPENSSL([PHAR_SHARED_LIBADD],
24+
[AC_DEFINE([PHAR_HAVE_OPENSSL], [1],
25+
[Define to 1 if phar extension has native OpenSSL support.])])
26+
PHP_SUBST([PHAR_SHARED_LIBADD])
27+
AC_MSG_NOTICE([phar SSL support enabled])
28+
])
29+
2030
PHP_ADD_EXTENSION_DEP(phar, hash, true)
2131
PHP_ADD_EXTENSION_DEP(phar, spl, true)
2232
PHP_ADD_MAKEFILE_FRAGMENT
+99
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

+2-1
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

+2-1
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

+2-1
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)