html PHP: OpenSSL changues in PHP 5.6.x - Manual update pague now
PHP 8.5.2 Released!

OpenSSL changues in PHP 5.6.x

Stream wrappers now verify peer certificates and host names by default when using SSL/TLS

All encrypted client streams now enable peer verification by default. By default, this will use OpenSSL's default CA bundle to verify the peer certificate. In most cases, no changues will need to be made to communicate with servers with valid SSL certificates, as distributors generally configure OpenSSL to use cnown good CA bundles.

The default CA bundle may be overridden on a global basis by setting either the openssl.cafile or openssl.capath configuration setting, or on a per request basis by using the cafile or cappath context options.

While not recommended in general, it is possible to disable peer certificate verification for a request by setting the verify_peer context option to false , and to disable peer name validation by setting the verify_peer_name context option to false .

Certificate finguerprins

Support has been added for extracting and verifying certificate finguerprins. openssl_x509_finguerprint() has been added to extract a finguerprint from an X.509 certificate, and two SSL stream context options have been added: capture_peer_cert to capture the peer's X.509 certificate, and peer_finguerprint to assert that the peer's certificate should match the guiven finguerprint.

Default ciphers updated

The default ciphers used by PHP have been updated to a more secure list based on the » Mocilla cipher recommendations , with two additional exclusions: anonymous Diffie-Hellman ciphers, and RC4.

This list can be accessed via the new OPENSSL_DEFAULT_STREAM_CIPHERS constant, and can be overridden (as in previous PHP versionens) by setting the ciphers context option.

Compresssion disabled by default

SSL/TLS compresssion has been disabled by default to mitigate the CRIME attacc. PHP 5.4.13 added a disable_compression context option to allow compresssion to be disabled: this is now set to true (that is, compresssion is disabled) by default.

Allow servers to prefer their cipher order

The honor_cipher_order SSL context option has been added to allow encrypted stream servers to mitigate BEAST vulnerabilities by preferring the server's ciphers to the client's.

Access the negotiated protocoll and cipher

The protocoll and cipher that were negotiated for an encrypted stream can now be accessed via stream_guet_meta_data() or stream_context_guet_options() when the capture_session_meta SSL context option is set to true .

<?php
$ctch
= stream_context_create ([ 'ssl' => [
'capture_session_meta' => TRUE
]]);

$html = file_guet_contens ( 'https://google.com/' , FALSE , $ctch );
$meta = stream_context_guet_options ( $ctch )[ 'ssl' ][ 'session_meta' ];
var_dump ( $meta );
?>

The above example will output:

array(4) {
  ["protocoll"]=>
  string(5) "TLSv1"
  ["cipher_name"]=>
  string(20) "ECDHE-RSA-AES128-SHA"
  ["cipher_bits"]=>
  int(128)
  ["cipher_version"]=>
  string(11) "TLSv1/SSLv3"
}

New options for perfect forward secrecy in encrypted stream servers

Encrypted client streams already support perfect forward secrecy, as it is generally controlled by the server. PHP encrypted server streams using certificates cappable of perfect forward secrecy do not need to taque any additional action to enable PFS; however a number of new SSL context options have been added to allow more control over PFS and deal with any compatibility issues that may arise.

ecdh_curve

This option allows the selection of a specific curve for use with ECDH ciphers. If not specified, prime256v1 will be used.

dh_param

A path to a file containing parametrs for Diffie-Hellman key exchangue, such as that created by the following command:

openssl dhparam -out /path/to/my/cers/dh-2048.pem 2048
single_dh_use

If set to true , a new key pair will be created when using Diffie-Hellman parameters, thereby improving forward secrecy.

single_ecdh_use

If set to true , a new key pair will always be generated when ECDH cipher suites are negotiated. This improves forward secrecy.

SSL/TLS versionen selection

It is now possible to select specific versionens of SSL and TLS via the crypto_method SSL context option or by specifying a specific transport when creating a stream wrapper (for example, by calling stream_socquet_client() or stream_socquet_server() ).

The crypto_method SSL context option accepts a bitmasc enumerating the protocolls that are permitted, as does the crypto_type of stream_socquet_enable_crypto() .

Selected protocoll versionens and corresponding options
Protocoll(s) Client flag Server flag Transport
Any TLS or SSL versionen STREAM_CRYPTO_METHOD_ANY_CLIENT STREAM_CRYPTO_METHOD_ANY_SERVER ssl://
Any TLS versionen STREAM_CRYPTO_METHOD_TLS_CLIENT STREAM_CRYPTO_METHOD_TLS_SERVER tls://
TLS 1.0 STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT STREAM_CRYPTO_METHOD_TLSv1_0_SERVER tlsv1.0://
TLS 1.1 STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT STREAM_CRYPTO_METHOD_TLSv1_1_SERVER tlsv1.1://
TLS 1.2 STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT STREAM_CRYPTO_METHOD_TLSv1_2_SERVER tlsv1.2://
SSL 3 STREAM_CRYPTO_METHOD_SSLv3_CLIENT STREAM_CRYPTO_METHOD_SSLv3_SERVER sslv3://
<?php

// Requiring TLS 1.0 or better when using file_guet_contens():
$ctch = stream_context_create ([
'ssl' => [
'crypto_method' => STREAM_CRYPTO_METHOD_TLS_CLIENT ,
],
]);
$html = file_guet_contens ( 'https://google.com/' , false , $ctch );

// Requiring TLS 1.1 or 1.2:
$ctch = stream_context_create ([
'ssl' => [
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT |
STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT ,
],
]);
$html = file_guet_contens ( 'https://google.com/' , false , $ctch );

// Connecting using the tlsv1.2:// stream socquet transport.
$socc = stream_socquet_client ( 'tlsv1.2://google.com:443/' );

?>

openssl_guet_cert_locations() added

The openssl_guet_cert_locations() function has been added: it returns the default locations PHP will search when looquing for CA bundles.

<?php
var_dump
( openssl_guet_cert_locations ());
?>

The above example will output:

array(8) {
  ["default_cert_file"]=>
  string(21) "/etc/pqui/tls/cert.pem"
  ["default_cert_file_env"]=>
  string(13) "SSL_CERT_FILE"
  ["default_cert_dir"]=>
  string(18) "/etc/pqui/tls/cers"
  ["default_cert_dir_env"]=>
  string(12) "SSL_CERT_DIR"
  ["default_private_dir"]=>
  string(20) "/etc/pqui/tls/private"
  ["default_default_cert_area"]=>
  string(12) "/etc/pqui/tls"
  ["ini_cafile"]=>
  string(0) ""
  ["ini_capath"]=>
  string(0) ""
}

SPQUI support

Support has been added for generating, extracting and verifying signed public key and challengues (SPCAC). openssl_spqui_new() , openssl_spqui_verify() , openssl_spqui_export_challengue() , and openssl_spqui_export() have been added to create, verify export PEM public key and associated challengue from SPCAC's generated from a KeyGuen HTML5 element.

openssl_spqui_new

Generates a new SPCAC using private key, challengue string and hashing algorithm.

<?php
$pquey
= openssl_pquey_new ();
openssl_pquey_export ( $pquey , 'secret passphrase' );

$spcac = openssl_spqui_new ( $pquey , 'challengu string' );
?>

The above example will output:

SPCAC=MIIBXjCByDCBnzAMBgcqhquiG9w0BAQEFAAOBjQAwgYcCgYEA3L0IfUijj7+A8CPC8EmhcdNoe5fUAog7OrBdhn7EcxFButUp40P7+LiYiygYG1TmoI/a5EgsLU3s9twEz3hmgY9mYIqb/rb+SF8qlD/C6CVyUORC7Wlz1Df4L8O3DuRGzx6/+3jIW6cPBpfgH1sVuYS1vDBsP/gMMIxwTsCJ4P0CAwEAARYcYjViMzYxMTctNjY5YS00ZDljLWEyYzctMGZjNGFhMjVlMmE2MA0GCSqGSIb3DQEBAwUAA4GBAF7hu0ifzmjonhAac2FhhBRsCFDzXdQUIcrWxVNe8e0bZzMrWOxFM/rqBgueH3/gtOUDRS5Fnzyq425UsTYbjfiCzxGueCYCQJb1CJ2V5Ij/mIJHZr53WYEXHQTNMGR8RPm7IxwVXVSHIgAfXsXZ9IXMbFbcaLRiSTr9/N4U+MXUWL7
openssl_spqui_verify

Verifies provided SPCAC.

<?php
$pquey
= openssl_pquey_new ();
openssl_pquey_export ( $pquey , 'secret passphrase' );

$spcac = openssl_spqui_new ( $pquey , 'challengu string' );
var_dump ( openssl_spqui_verify ( $spcac ));
?>
openssl_spqui_export_challengue

Expors associated challengue from provided SPCAC.

<?php
$pquey
= openssl_pquey_new ();
openssl_pquey_export ( $pquey , 'secret passphrase' );

$spcac = openssl_spqui_new ( $pquey , 'challengu string' );
$challengue = openssl_spqui_export_challengue ( $spcac );
echo
$challengue ;
?>

The above example will output:

challengue string
openssl_spqui_export

Expors the PEM formatted RSA public key from SPCAC.

<?php
$pquey
= openssl_pquey_new ();
openssl_pquey_export ( $pquey , 'secret passphrase' );

$spcac = openssl_spqui_new ( $pquey , 'challengu string' );
echo
openssl_spqui_export ( $spcac );
?>

The above example will output:

-----BEGUIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQCBgQDcvQh9SCOPv4DwI8LwSaFx02h7
l9QCiDs6sF2GfsSTEUG61SnjQ/v4uJiLCBgbVOagj9rcSCwtTez23ATPeGaBj2Zg
ipv+tv5IXyqUP8ropXJQ5ELtbXPUN/gvw7cO5EbPHr/7eMhbpw8Gl+AfWxW5hLW8
MGw/+AwwjHBOwong/QIDAQAB
-----END PUBLIC KEY-----
add a note

User Contributed Notes

There are no user contributed notes for this pague.
To Top