Skip to content

Commit

Permalink
Use OpenSSL 3.2 across all PHP versions
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Nov 23, 2023
1 parent 4ce0a7f commit 797c936
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
13 changes: 13 additions & 0 deletions layers/openssl3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Patch for OpenSSL 3 support for PHP 8.0
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -1325,7 +1325,9 @@
REGISTER_LONG_CONSTANT("OPENSSL_CMS_NOSIGS", CMS_NOSIGS, CONST_CS|CONST_PERSISTENT);

REGISTER_LONG_CONSTANT("OPENSSL_PKCS1_PADDING", RSA_PKCS1_PADDING, CONST_CS|CONST_PERSISTENT);
+#ifdef RSA_SSLV23_PADDING
REGISTER_LONG_CONSTANT("OPENSSL_SSLV23_PADDING", RSA_SSLV23_PADDING, CONST_CS|CONST_PERSISTENT);
+#endif
REGISTER_LONG_CONSTANT("OPENSSL_NO_PADDING", RSA_NO_PADDING, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("OPENSSL_PKCS1_OAEP_PADDING", RSA_PKCS1_OAEP_PADDING, CONST_CS|CONST_PERSISTENT);

9 changes: 7 additions & 2 deletions php-80/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ RUN set -xe; \
# Needed by:
# - curl
# - php
ENV VERSION_OPENSSL=1.1.1w
RUN yum install -y perl-IPC-Cmd
ENV VERSION_OPENSSL=3.2.0
ENV OPENSSL_BUILD_DIR=${BUILD_DIR}/openssl
ENV CA_BUNDLE_SOURCE="https://curl.se/ca/cacert.pem"
ENV CA_BUNDLE="${INSTALL_DIR}/bref/ssl/cert.pem"
RUN set -xe; \
mkdir -p ${OPENSSL_BUILD_DIR}; \
curl -Ls https://github.com/openssl/openssl/archive/OpenSSL_${VERSION_OPENSSL//./_}.tar.gz \
curl -Ls https://github.com/openssl/openssl/releases/download/openssl-${VERSION_OPENSSL}/openssl-${VERSION_OPENSSL}.tar.gz \
| tar xzC ${OPENSSL_BUILD_DIR} --strip-components=1
WORKDIR ${OPENSSL_BUILD_DIR}/
RUN CFLAGS="" \
Expand Down Expand Up @@ -384,6 +385,10 @@ ARG VERSION_PHP
RUN curl --location --silent --show-error --fail https://www.php.net/get/php-${VERSION_PHP}.tar.gz/from/this/mirror \
| tar xzC . --strip-components=1

COPY layers/openssl3.patch ${PHP_BUILD_DIR}
RUN patch -N -p1 -s < openssl3.patch
RUN rm openssl3.patch

# Configure the build
# -fstack-protector-strong : Be paranoid about stack overflows
# -fpic : Make PHP's main executable position-independent (improves ASLR security mechanism, and has no performance impact on x86_64)
Expand Down
2 changes: 1 addition & 1 deletion php-81/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ RUN set -xe; \
# - curl
# - php
RUN yum install -y perl-IPC-Cmd
ENV VERSION_OPENSSL=3.0.12
ENV VERSION_OPENSSL=3.2.0
ENV OPENSSL_BUILD_DIR=${BUILD_DIR}/openssl
ENV CA_BUNDLE_SOURCE="https://curl.se/ca/cacert.pem"
ENV CA_BUNDLE="${INSTALL_DIR}/bref/ssl/cert.pem"
Expand Down
2 changes: 1 addition & 1 deletion php-82/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ RUN set -xe; \
# - curl
# - php
RUN yum install -y perl-IPC-Cmd
ENV VERSION_OPENSSL=3.0.12
ENV VERSION_OPENSSL=3.2.0
ENV OPENSSL_BUILD_DIR=${BUILD_DIR}/openssl
ENV CA_BUNDLE_SOURCE="https://curl.se/ca/cacert.pem"
ENV CA_BUNDLE="${INSTALL_DIR}/bref/ssl/cert.pem"
Expand Down
2 changes: 1 addition & 1 deletion php-83/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ RUN set -xe; \
# - curl
# - php
RUN yum install -y perl-IPC-Cmd
ENV VERSION_OPENSSL=3.0.12
ENV VERSION_OPENSSL=3.2.0
ENV OPENSSL_BUILD_DIR=${BUILD_DIR}/openssl
ENV CA_BUNDLE_SOURCE="https://curl.se/ca/cacert.pem"
ENV CA_BUNDLE="${INSTALL_DIR}/bref/ssl/cert.pem"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_2_extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
// https://github.com/brefphp/aws-lambda-layers/issues/42
'curl-http2' => defined('CURL_HTTP_VERSION_2'),
// Make sure we are not using the default AL2 OpenSSL version (7.79)
'curl-openssl' => str_starts_with(curl_version()['ssl_version'], 'OpenSSL/1.1.1') || str_starts_with(curl_version()['ssl_version'], 'OpenSSL/3.0'),
'curl-openssl' => str_starts_with(curl_version()['ssl_version'], 'OpenSSL/3.2'),
// Check that the default certificate file exists
// https://github.com/brefphp/aws-lambda-layers/issues/53
'curl-openssl-certificates' => file_exists(openssl_get_cert_locations()['default_cert_file']),
Expand Down

0 comments on commit 797c936

Please sign in to comment.