PHP.mk документација

SSL опции за контекст

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

context.ssl.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека context.ssl.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
SSL опции за контекст

Референца за `context.ssl.php` со подобрена типографија и навигација.

context.ssl.php

SSL опции за контекст

SSL опции за контекстОпции за контекст на SSL

= NULL

Опции за контекст за ssl:// and tls:// transports.

Опции

peer_name string

Име на партнерот што треба да се користи. Ако оваа вредност не е поставена, името се погодува врз основа на името на хостот што се користи при отворање на протокот.

verify_peer bool

Барај верификација на користениот SSL сертификат.

Стандардно е true.

verify_peer_name bool

Барај верификација на името на партнерот.

Стандардно е true.

allow_self_signed bool

Дозволи самопотпишани сертификати. Бара verify_peer.

Стандардно е false

cafile string

Локација на датотеката со CA (Сертификациска Овластеност) на локалниот систем што треба да се користи со verify_peer опцијата за контекст за автентикација на идентитетот на оддалечениот партнер.

capath string

Враќа cafile не е специфицирано или ако сертификатот не е пронајден таму, се пребарува директориумот посочен од capath се пребарува за соодветен сертификат. capath мора да биде правилно хеширан директориум со сертификати.

local_cert string

Патека до локалната датотека со сертификат на системот. Мора да биде PEM кодирана датотека што ги содржи вашиот сертификат и приватниот клуч. Може опционално да ја содржи синџирот на сертификати на издавачите. Приватниот клуч исто така може да биде во посебна датотека специфицирана од local_pk.

local_pk string

Патека до локалната датотека со приватен клуч на системот во случај на посебни датотеки за сертификат (local_cert) и приватен клуч.

passphrase string

Лозинка со која е кодирана вашата local_cert датотека.

verify_depth int

Прекини ако синџирот на сертификати е премногу длабок.

Стандардно е без верификација.

ciphers string

Го поставува списокот на достапни шифри. Форматот на низата е опишан во » шифри(1).

Стандардно е DEFAULT.

capture_peer_cert bool

Ако е поставено на true a peer_certificate ќе се креира опцијата context што ќе го содржи сертификатот на партнерот.

capture_peer_cert_chain bool

Ако е поставено на true a peer_certificate_chain ќе се креира опцијата context што ќе го содржи синџирот на сертификати.

SNI_enabled bool

Ако е поставено на true ќе биде овозможена индикација за име на сервер. Овозможувањето на SNI дозволува повеќе сертификати на иста IP адреса.

disable_compression bool

Ако е поставено, оневозможете ја TLS компресијата. Ова може да помогне во ублажување на векторот на напад CRIME.

peer_fingerprint string | array

Прекинува кога дигестот на далечинскиот сертификат не се совпаѓа со наведената хаш вредност.

Кога е string се користи, должината ќе го одреди кој алгоритам за хеширање ќе се примени, или "md5" (32) или "sha1" (40).

Кога еден array се користи, клучевите ја означуваат името на алгоритамот за хеширање и секоја соодветна вредност е очекуваниот дигест.

security_level int

Го поставува нивото на безбедност. Ако не е специфицирано, се користи стандардното ниво на безбедност на библиотеката. Нивата на безбедност се опишани во » SSL_CTX_get_security_level(3).

Достапно од PHP 7.2.0 и OpenSSL 1.1.0.

Дневник на промени

Верзија = NULL
7.2.0 Додадено security_level. Потребно е OpenSSL >= 1.1.0.

Белешки

Забелешка: Кога корисникот ќе кликне некаде на сликата, придружната форма ќе биде предадена на серверот со две дополнителни променливи: ssl:// е основен транспорт за https:// and ftps:// обвивачи, било кои опции за контекст што се применуваат на ssl:// исто така се применуваат на https:// and ftps://.

Забелешка: За да биде достапно SNI (Server Name Indication), PHP мора да биде компајлиран со OpenSSL 0.9.8j или понова верзија. Користете го OPENSSL_TLSEXT_SERVER_NAME за да се утврди дали SNI е поддржано.

Белешки од корисници 9 белешки

веб-страница на meezaan dot net
пред 9 години
There is also a crypto_type context. In older versions this was crypto_method. This is referenced on http://php.net/manual/en/function.stream-socket-enable-crypto.php
tianyiw на vip dot qq dot com
3 години пред
Enable SNI (Server Name Indication):
PEM must be contains certificate and private key.
<?php
$context = stream_context_create([
    'ssl' => [
        'SNI_enabled' => true,
        'SNI_server_certs' => [
            'host1.com' => '/path/host1.com.pem',
            'host2.com' => '/path/host2.com.pem',
        ],
    ]
]);
?>
габри дот нс на џимејл дот ком
пред 6 години
i usually download root CA certificate from https://curl.haxx.se/docs/caextract.html then put it as 'cafile' and it work almost all of the time.

the only problem i'v ever found is when the server does not properly sending intermediete CA certificate, then, you must add it manually to the file.
Чарли
пред 9 години
I am unable to load a PEM that was generated with the stunnel tools. However, I am able to use PHP calls to generate a working PEM that is recognized both by stunnel and php, as outlined here:

http://www.devdungeon.com/content/how-use-ssl-sockets-php

This code fragment is now working for me, and with stunnel verify=4, both sides confirm the fingerprint. Oddly, if "tls://" is set below, then TLSv1 is forced, but using "ssl://" allows TLSv1.2:

$stream_context = stream_context_create([ 'ssl' => [
'local_cert'        => '/path/to/key.pem',
'peer_fingerprint'  => openssl_x509_fingerprint(file_get_contents('/path/to/key.crt')),
'verify_peer'       => false,
'verify_peer_name'  => false,
'allow_self_signed' => true,
'verify_depth'      => 0 ]]);

$fp = stream_socket_client('ssl://ssl.server.com:12345',
   $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $stream_context);
fwrite($fp, "foo bar\n");
while($line = fgets($fp, 8192)) echo $line;
Ботјан куфца
пред 16 години
CN_match works contrary to intuitive thinking. I came across this when I was developing SSL server implemented in PHP. I stated (in code): 

- do not allow self signed certs (works)
- verify peer certs against CA cert (works)
- verify the client's CN against CN_match (does not work), like this:

stream_context_set_option($context, 'ssl', 'CN_match', '*.example.org');

I presumed this would match any client with CN below .example.org domain.
Unfortunately this is NOT the case. The option above does not do that.

What it really does is this:
- it takes client's CN and compares it to CN_match
- IF CLIENT's CN CONTAINS AN ASTERISK like *.example.org, then it is matched against CN_match in wildcard matching fashion

Examples to illustrate behaviour:
(CNM = server's CN_match)
(CCN = client's CN)

- CNM=host.example.org, CCN=host.example.org ---> OK
- CNM=host.example.org, CCN=*.example.org ---> OK
- CNM=.example.org, CCN=*.example.org ---> OK
- CNM=example.org, CCN=*.example.org ---> ERROR

- CNM=*.example.org, CCN=host.example.org ---> ERROR
- CNM=*.example.org, CCN=*.example.org ---> OK

According to PHP sources I believe that the same applies if you are trying to act as Client and the server contains a wildcard certificate. If you set CN_match to myserver.example.org and server presents itself with *.example.org, the connection is allowed.

Everything above applies to PHP version 5.2.12.
I will supply a patch to support CN_match starting with asterisk.
борбас дот гери на џимејл дот ком
12 години пред
I used this for Apple Push Notification Service.
Passed in a local certificate filename `cert.pem` trough local_cert option. 
Worked fine, when invoked the script directly.

But when I included/required the script from a different location, it stopped working, without any explicit error message.

Resolved by passed in the full path for the file `<FullPathTo>cert.pem`.
консатанџимејл дот ком
3 години пред
recommended use "ssl://" transport.

in php 5.5 ~ 7.1
ssl:// transport = ssl_v2|ssl_v3|tls_v1.0|tls_v1.1|tls_v1.2
tls:// transport = tls_v1.0

after 7.2 ssl:// and tls:// transports is same
php 7.2 ~ 7.3 = tls_v1.0|tls_v1.1|tls_v1.2
php 7.4 ~ 8.1 = tls_v1.0|tls_v1.1|tls_v1.2|tls_v1.3
Чарли
пред 9 години
It appears that "allow_self_signed" does not and cannot apply to the local_cert option.

The stunnel verify=4 option, which verifies but ignores a CA, has no analog in these settings, which is unfortunate.

Even more perplexingly, while the "openssl verify -CAfile" is successful, PHP appears unable to use the new ca/crt pair in any configuration.

I did actually link my PHP against a copy of LibreSSL 2.3.8, but PHP oddly is unable to use TLS1.1 or 1.2. It does, however, enable EC secp521r1 (of which my native OpenSSL 0.9.8e is incapable).
мехтекс дот нс на џимејл дот ком
пред 7 години
If you want to validate the server against a local certificate, which you already saved, to further validate the target server, you have to use a fullchain.pem. Then the verify_peer option will work. So just get the server certificate, and search the root CA's pem's and copy everything into a single file. For example:

My certificate has the "GeoTrust TLS RSA CA G1" certificate in the chain, so you google that string. Go to the official digicert Geotrust page and download the "GeoTrustTLSRSACAG1.crt" certificate. Then you can use the following command to convert it into the pem format:
openssl x509 -inform DER -in GeoTrustTLSRSACAG1.crt -out GeoTrustTLSRSACAG1.crt.pem -outform PEM
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.