SSL Context Options for OpenSSL
This section describes how 'SSL context options' defined for ssl:// and tls:// transports can be used to control behaviors of the OpenSSL module.
In previous tutorials, I learned how to turn on the OpenSSL module and retrieve HTTPS page
with a single function call: file_get_contents($url).
Now I want to know to how to control the behavior of the OpenSSL module. Particularly,
I want to know if the OpenSSL module is performing server certificate verification or not.
After reading many PHP manual pages, I found that controlling OpenSSL's behavior is done by "SSL context options",
which is defined for ssl:// and tls:// transports.
Major SSL context options are:
- verify_peer boolean - Require verification of SSL certificate used. Defaults to FALSE.
- allow_self_signed boolean - Allow self-signed certificates. Defaults to FALSE
- cafile string - Location of Certificate Authority file on local filesystem which should be used with the verify_peer context option to authenticate the identity of the remote peer.
- capath string - If cafile is not specified or if the certificate is not found there, the directory pointed to by capath is searched for a suitable certificate. capath must be a correctly hashed certificate directory.
- local_cert string - Path to local certificate file on filesystem. It must be a PEM encoded file which contains your certificate and private key. It can optionally contain the certificate chain of issuers.
- passphrase string - Passphrase with which your local_cert file was encoded.
- CN_match string - Common Name we are expecting. PHP will perform limited wildcard matching. If the Common Name does not match this, the connection attempt will fail.
- verify_depth integer - Abort if the certificate chain is too deep. Defaults to no verification.
- ciphers string - Sets the list of available ciphers. The format of the string is described in ciphers(1). Defaults to DEFAULT.
- capture_peer_cert boolean - If set to TRUE a peer_certificate context option will be created containing the peer certificate.
- capture_peer_cert_chain boolean - If set to TRUE a peer_certificate_chain context option will be created containing the certificate chain.
- SNI_enabled boolean - If set to TRUE server name indication will be enabled. Enabling SNI allows multiple certificates on the same IP address.
- SNI_server_name string - If set, then this value will be used as server name for server name indication. If this value is not set, then the server name is guessed based on the hostname used when opening the stream.
Since the default setting for "verify_peer" is FALSE, now I know that the OpenSSL module does not verify HTTPS server
certificates by default.
Table of Contents
About This Book
Introduction of PKI (Public Key Infrastructure)
Introduction of HTTPS (Hypertext Transfer Protocol Secure)
Using HTTPS with Google Chrome
Using HTTPS with Mozilla Firefox
HTTPS with Microsoft Edge
Using HTTPS with Apple Safari
HTTPS with IE (Internet Explorer)
Android and Server Certificate
iPhone and Server Certificate
Windows Certificate Stores and Console
RDP (Remote Desktop Protocol) and Server Certificate
macOS Certificate Stores and Keychain Access
Perl Scripts Communicating with HTTPS Servers
►PHP Scripts Communicating with HTTPS Servers
Configuring PHP OpenSSL on Windows
Testing OpenSSL with file_get_contents()
OpenSSL Configuration Errors
►SSL Context Options for OpenSSL
Asking OpenSSL to Verify Server's Certificate
OpenSSL Failing to Verify Server's Certificate
Multiple CA Certificates in a Single File
Testing OpenSSL with fopen()
Java Programs Communicating with HTTPS Servers
.NET Programs Communicating with HTTPS Servers
CAcert.org - Root CA Offering Free Certificates
PKI CA Administration - Issuing Certificates
Comodo Free Personal Certificate
Digital Signature - Microsoft Word
Digital Signature - OpenOffice.org 3
S/MIME and Email Security
PKI (Public Key Infrastructure) Terminology
Full Version in PDF/EPUB