Skip to content

Commit 747e065

Browse files
committed
HSM: local_cert URI
Let's support cases when `local_cert` is a HSM URI too. TODO: fixup indent, this version is only designed to ease code review. Suggested-by: Jakub Zelenka <bukka@php.net> The current PHP usage of this has got just the path without file:// so the fast path should be to first try to get it from real path and if that fails, then try to get it from php_openssl_x509_from_str(). If the cert is found in any of those, then try local_pk.
1 parent f445677 commit 747e065

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ext/openssl/xp_ssl.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,8 @@ static int php_openssl_set_local_cert(SSL_CTX *ctx, php_stream *stream) /* {{{ *
938938
if (certfile) {
939939
char resolved_path_buff[MAXPATHLEN];
940940
const char *private_key = NULL;
941+
X509 *cert = NULL;
942+
int ctx_set = 0;
941943

942944
if (VCWD_REALPATH(certfile, resolved_path_buff)) {
943945
/* a certificate to use for authentication */
@@ -948,6 +950,19 @@ static int php_openssl_set_local_cert(SSL_CTX *ctx, php_stream *stream) /* {{{ *
948950
certfile);
949951
return FAILURE;
950952
}
953+
ctx_set = 1;
954+
/* val is still local_cert/certfile since GET_VER_OPT_STRING("local_cert", certfile) */
955+
} else if ((cert = php_openssl_x509_from_str(Z_STR_P(val))) != NULL) {
956+
if (SSL_CTX_use_certificate(ctx, cert) != 1) {
957+
X509_free(cert);
958+
php_error_docref(NULL, E_WARNING,
959+
"Invalid local cert `%s'; Check your device",
960+
certfile);
961+
return FAILURE;
962+
}
963+
ctx_set = 1;
964+
}
965+
if (ctx_set) {
951966
GET_VER_OPT_STRING("local_pk", private_key);
952967
if (private_key) {
953968
char resolved_path_buff_pk[MAXPATHLEN];

0 commit comments

Comments
 (0)