diff --git a/ext/openssl/openssl_backend_common.c b/ext/openssl/openssl_backend_common.c index a5bd7238d9ed..a3c8f8dfdba9 100644 --- a/ext/openssl/openssl_backend_common.c +++ b/ext/openssl/openssl_backend_common.c @@ -745,7 +745,7 @@ int php_openssl_check_cert(X509_STORE *ctx, X509 *x, STACK_OF(X509) *untrustedch int ret=0; X509_STORE_CTX *csc; - csc = X509_STORE_CTX_new(); + csc = php_openssl_x509_store_ctx_new(); if (csc == NULL) { php_openssl_store_errors(); php_error_docref(NULL, E_ERROR, "Memory allocation failure"); @@ -811,7 +811,7 @@ X509_STORE *php_openssl_setup_verify(zval *calist, uint32_t arg_num) if ((sb.st_mode & S_IFREG) == S_IFREG) { file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); - if (file_lookup == NULL || !X509_LOOKUP_load_file(file_lookup, file_path, X509_FILETYPE_PEM)) { + if (file_lookup == NULL || !php_openssl_x509_lookup_load_file(file_lookup, file_path, X509_FILETYPE_PEM)) { php_openssl_store_errors(); php_error_docref(NULL, E_WARNING, "Error loading file %s", file_path); } else { @@ -832,7 +832,7 @@ X509_STORE *php_openssl_setup_verify(zval *calist, uint32_t arg_num) } if (nfiles == 0) { file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); - if (file_lookup == NULL || !X509_LOOKUP_load_file(file_lookup, NULL, X509_FILETYPE_DEFAULT)) { + if (file_lookup == NULL || !php_openssl_x509_lookup_load_file(file_lookup, NULL, X509_FILETYPE_DEFAULT)) { php_openssl_store_errors(); } } diff --git a/ext/openssl/openssl_backend_v1.c b/ext/openssl/openssl_backend_v1.c index 13aab24c3ff0..532321d8d4b7 100644 --- a/ext/openssl/openssl_backend_v1.c +++ b/ext/openssl/openssl_backend_v1.c @@ -747,6 +747,16 @@ STACK_OF(X509_INFO) *php_openssl_pem_read_bio_x509_info(BIO *in) return PEM_X509_INFO_read_bio(in, NULL, NULL, NULL); } +X509_STORE_CTX *php_openssl_x509_store_ctx_new(void) +{ + return X509_STORE_CTX_new(); +} + +int php_openssl_x509_lookup_load_file(X509_LOOKUP *lookup, const char *file, int type) +{ + return X509_LOOKUP_load_file(lookup, file, type); +} + EVP_PKEY *php_openssl_pem_read_bio_public_key(BIO *in) { return PEM_read_bio_PUBKEY(in, NULL, NULL, NULL); diff --git a/ext/openssl/openssl_backend_v3.c b/ext/openssl/openssl_backend_v3.c index 791aae196bfe..f2ffa10cfc70 100644 --- a/ext/openssl/openssl_backend_v3.c +++ b/ext/openssl/openssl_backend_v3.c @@ -911,6 +911,16 @@ STACK_OF(X509_INFO) *php_openssl_pem_read_bio_x509_info(BIO *in) return PEM_X509_INFO_read_bio_ex(in, NULL, NULL, NULL, PHP_OPENSSL_LIBCTX, PHP_OPENSSL_PROPQ); } +X509_STORE_CTX *php_openssl_x509_store_ctx_new(void) +{ + return X509_STORE_CTX_new_ex(PHP_OPENSSL_LIBCTX, PHP_OPENSSL_PROPQ); +} + +int php_openssl_x509_lookup_load_file(X509_LOOKUP *lookup, const char *file, int type) +{ + return X509_LOOKUP_load_file_ex(lookup, file, type, PHP_OPENSSL_LIBCTX, PHP_OPENSSL_PROPQ); +} + EVP_PKEY *php_openssl_pem_read_bio_public_key(BIO *in) { return PEM_read_bio_PUBKEY_ex(in, NULL, NULL, NULL, PHP_OPENSSL_LIBCTX, PHP_OPENSSL_PROPQ); diff --git a/ext/openssl/php_openssl_backend.h b/ext/openssl/php_openssl_backend.h index 0090f4f52fe2..84303db34f4f 100644 --- a/ext/openssl/php_openssl_backend.h +++ b/ext/openssl/php_openssl_backend.h @@ -207,6 +207,8 @@ X509 *php_openssl_pem_read_asn1_bio_x509(BIO *in); X509 *php_openssl_pem_read_bio_x509(BIO *in); X509_REQ *php_openssl_pem_read_bio_x509_req(BIO *in); STACK_OF(X509_INFO) *php_openssl_pem_read_bio_x509_info(BIO *in); +X509_STORE_CTX *php_openssl_x509_store_ctx_new(void); +int php_openssl_x509_lookup_load_file(X509_LOOKUP *lookup, const char *file, int type); EVP_PKEY *php_openssl_pem_read_bio_public_key(BIO *in); EVP_PKEY *php_openssl_pem_read_bio_private_key(BIO *in, pem_password_cb *cb, void *u); PKCS7 *php_openssl_pem_read_bio_pkcs7(BIO *in);