проверка сертификата ssl php 5.6

Я пытаюсь отладить проблему с проверкой сертификата ssl и определил, что openssl получает местоположения сертификатов с возвращением неправильных путей. (См. ниже)

Как мне выяснить, как это установить? Я посмотрел в PHP.ini-файл и не смог найти эту ссылку нигде.

cmuench-air:bin cmuench$ ./php -r "print_r(openssl_get_cert_locations());"
Array
(
    [default_cert_file] => /bitnami/mampstack56Dev-osx-x64/output/common/openssl/cert.pem
    [default_cert_file_env] => SSL_CERT_FILE
    [default_cert_dir] => /bitnami/mampstack56Dev-osx-x64/output/common/openssl/certs
    [default_cert_dir_env] => SSL_CERT_DIR
    [default_private_dir] => /bitnami/mampstack56Dev-osx-x64/output/common/openssl/private
    [default_default_cert_area] => /bitnami/mampstack56Dev-osx-x64/output/common/openssl
    [ini_cafile] => 
    [ini_capath] => 
)

php.Ини (соответствующие части)...Я нигде не вижу bitnami/mampstack56Dev...

[openssl]
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the identity of SSL/TLS peers. Most users should
; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
;openssl.cafile=

; If openssl.cafile is not specified or if the CA file is not found, the
; directory pointed to by openssl.capath is searched for a suitable
; certificate. This value must be a correctly hashed certificate directory.
; Most users should not specify a value for this directive as PHP will
; attempt to use the OS-managed cert stores in its absence. If specified,
; this value may still be overridden on a per-stream basis via the "capath"
; SSL stream context option.
;openssl.capath=

;Curl ca bundle certificate
curl.cainfo="/Applications/phppos/common/openssl/certs/curl-ca-bundle.crt"

EDIT:

Я знаю, что это глупо, но есть времена, когда сертификат ssl будет подписан самостоятельно. Есть директива, я могу изменить, чтобы отключить проверку сертификатов? или мне придется сделать это в коде для сокетов и curl?

1 ответов


если вы проверяете источник PHP для openssl_get_cert_locations() функция, она получает эти местоположения, вызывая различные функции OpenSSL, такие как X509_get_default_cert_file и в php.ini значения openssl.cafile и openssl.capath описал здесь.

какие сертификаты / пути вы ищете именно? Если вы пытаетесь получить файл пакета CA, вы можете установить вышеупомянутыйphp.ini значения, поэтому они возвращаются openssl_get_cert_locations.

в по умолчанию php.ini файл для PHP 5.6 не имеет настроек по умолчанию для этих настроек OpenSSL ini, поскольку они должны быть определены вручную. Эта конфигурация находится в конце php.ini

[openssl]
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the identity of SSL/TLS peers. Most users should
; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
;openssl.cafile=

; If openssl.cafile is not specified or if the CA file is not found, the
; directory pointed to by openssl.capath is searched for a suitable
; certificate. This value must be a correctly hashed certificate directory.
; Most users should not specify a value for this directive as PHP will
; attempt to use the OS-managed cert stores in its absence. If specified,
; this value may still be overridden on a per-stream basis via the "capath"
; SSL stream context option.
;openssl.capath=

при использовании cURL, если вы хотите отключить проверку сертификата, вы можете передать эти параметры в curl_setopt():

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);  // shouldn't need this

CURLOPT_SSL_VERIFYPEER описано так:

FALSE, чтобы остановить cURL от проверки сертификата однорангового узла. Чередовать сертификаты для проверки можно указать с помощью Параметр CURLOPT_CAINFO или каталог сертификатов можно указать с помощью параметр CURLOPT_CAPATH.

CURLOPT_SSL_VERIFYHOST это описывается как:

1 для проверки существования имени в сертификате SSL. 2 для проверки существования имени, а также убедиться в том, что он соответствия имени хоста. В производственных средах значение эта опция должна быть 2 (по умолчанию значение.)

если у вас есть файлы CA, вы можете использовать опцию CURLOPT_CAINFO чтобы предоставить полный путь к файлу, содержащему один или несколько сертификатов для проверки однорангового узла.

чтобы отключить проверку потока, Открытого с помощью fsockopen попробуй:

<?php
$context = stream_context_create();
$result = stream_context_set_option($context, 'ssl', 'verify_peer', false);

$socket = stream_socket_client('ssl://'.$host . ':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context); 

посмотреть параметры контекста SSL для получения дополнительной информации и stream_socket_client().