Download the PHP package mlocati/ocsp without Composer
On this page you can find all versions of the php package mlocati/ocsp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package ocsp
Short Description Library to query HTTPS Certificates revocation status using the Online Certificate Status Protocol (OCSP)
License MIT
Homepage https://github.com/mlocati/ocsp/
Informations about the package ocsp
Online Certificate Status Protocol PHP Library
This repository contains a PHP library that helps you checking if HTTPS certificates are revoked, by using the Online Certificate Status Protocol (OCSP).
This library doesn't require exec
calls to system utilities like OpenSSL: it's a pure PHP library.
This library doesn't include any network-related helpers: you have to use your own transport libraries (cURL, Zend HTTP, Guzzle or whatever).
Checking HTTPS certificates requires:
- the certificate to be checked, in PEM format (that is, the text files that starts with `-----BEGIN CERTIFICATE-----), or in DER format (that is, binary files)
- the issuer certificate, that is the certificate of the Certification Authority that provided you the HTTPS certificate
- the URL, provided by the Certification Authority, to be used for OCSP calls (the so-called
OCSR Responder URL
)
Obtaining the certificate and the issuer certificate from an HTTPS URL
You can get the HTTPS certificate and the issuer certificate from an HTTPS URL by using some code like this:
Obtaining the issuer certificate from a certificate
HTTPS certificates usually contain an URL where you can find the certificate of the certificate issuer.
You can use this code to extract this URL, provided that '/path/to/certificate'
is the path to a local file that contains your HTTPS certificate:
At this point, $urlOfIssuerCertificate
will contain the URL where the issuer certificate can be downloaded from (if it's an empty string, that means that the issuer certificate URL is not included in your certificate).
Obtaining the OCSP Responder URL
To check if a certificate is valid, we need to know an URL, provided by the authority that issued the certificate, that can be called to check if the certificate has been revoked.
This URL may be included in the HTTPS certificate itself.
To get it, you can use the following code (provided that '/path/to/certificate'
is the path to a local file that contains your HTTPS certificate):
Checking if a certificate has been revoked
Once you have the HTTPS certificate, the issuer certificate, and the OCSP Responder URL, you can check if the HTTPS certificate has been revoked, or if it's still valid.
In order to do so, you have to write some code like this (here we use cURL, but you can use any other transport library):
At this point, $response
contains an instance of the Ocsp\Response
class:
- the certificate is not revoked if
$response->isRevoked() === false
- the certificate is revoked if
$response->isRevoked() === true
(you can get the devocation date/time by calling$response->getRevokedOn()
) - in case of unknown state,
$response->isRevoked()
will returnnull
Exceptions
Problems may arise while loading the certificates, creating the request body for the OCSP Responder, analyzing the response from the OCSP Responder. To catch these errors, you can enclose your code within try/catch statements: