2017 © Pedro Peláez
 

library ssl-certificate

A class to easily query the properties of an ssl certificate

image

spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  • Monday, June 25, 2018
  • by Spatie
  • Repository
  • 12 Watchers
  • 258 Stars
  • 41,659 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 44 Forks
  • 1 Open issues
  • 38 Versions
  • 20 % Grown

The README.md

A class to validate SSL certificates

Latest Version on Packagist MIT Licensed run-tests Quality Score Total Downloads, (*1)

The class provided by this package makes it incredibly easy to query the properties on an ssl certificate. We have three options for fetching a certficate. Here's an example:, (*2)

use Spatie\SslCertificate\SslCertificate;

// fetch the certificate using an url
$certificate = SslCertificate::createForHostName('spatie.be');

// or from a certificate file
$certificate = SslCertificate::createFromFile($pathToCertificateFile);

// or from a string
$certificate = SslCertificate::createFromString($certificateData);

$certificate->isValid(); // returns true if the certificate is currently valid

$certificate->expirationDate(); // returns a Carbon instance Carbon
$certificate->validFromDate(); // returns a Carbon instance Carbon

$certificate->daysUntilExpirationDate(); // returns the amount of days between today and expirationDate
$certificate->lifespanInDays(); // return the amount of days between validFromDate and expirationDate

$certificate->getIssuer(); // returns "Let's Encrypt Authority X3"
$certificate->getOrganization(); // returns the organization name when available
$certificate->getPublicKeyAlgorithm(); // returns the public key algorithm
$certificate->getPublicKeySize(); // returns the public key algorithm
$certificate->getSignatureAlgorithm(); // returns the signature algorithm

Downloading invalid certificate

If you want to download certificates even if they are invalid (for example, if they are expired), you can pass a $verifyCertificate boolean to SslCertificate::createFromHostname() as the third argument, for example:, (*3)

$certificate = SslCertificate::createForHostName('expired.badssl.com', $timeoutInSeconds, false);

About us

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website., (*4)

Support us

, (*5)

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products., (*6)

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall., (*7)

Installation

You can install the package via composer:, (*8)

composer require spatie/ssl-certificate

Important notice

Currently, this package does not check if the certificate is signed by a trusted authority. We'll add this check soon in a next point release., (*9)

Usage

You can create an instance of Spatie\SslCertificate\SslCertificate with this named constructor:, (*10)

$certificate = SslCertificate::createForHostName('spatie.be');

You can create an instance of Spatie\SslCertificate\SslCertificate passing the port with this named constructor:, (*11)

$certificate = SslCertificate::createForHostName('spatie.be:443');

You can use this fluent style to specify a specific port to connect to., (*12)

SslCertificate::download()
   ->usingPort($customPort)
   ->forHost($hostName);

You can check the certificate on a different IP address using the same style., (*13)

SslCertificate::download()
   ->fromIpAddress($ipAddress)
   ->forHost($hostName);

This also works with IPv6 addresses, (*14)

SslCertificate::download()
    ->fromIpAddress('2a00:1450:4001:80e::200e')
    ->forHost('google.com');

You can specify socket context options., (*15)

SslCertificate::download()
   ->withSocketContextOptions([
      'option' => 'value',
   ])
   ->forHost($hostName);

If the given ipAddress is invalid Spatie\SslCertificate\Exceptions\InvalidIpAddress will be thrown., (*16)

If the given hostName is invalid Spatie\SslCertificate\Exceptions\InvalidUrl will be thrown., (*17)

If the given hostName is valid but there was a problem downloading the certifcate Spatie\SslCertificate\Exceptions\CouldNotDownloadCertificate will be thrown., (*18)

Getting the issuer name

$certificate->getIssuer(); // returns "Let's Encrypt Authority X3"

Getting the domain name

Returns the primary domain name for the certificate, (*19)

$certificate->getDomain(); // returns "spatie.be"

Getting the certificate's signing algorithm

Returns the algorithm used for signing the certificate, (*20)

$certificate->getSignatureAlgorithm(); // returns "RSA-SHA256"

Getting the certificate's organization

Returns the organization belonging to the certificate, (*21)

$certificate->getOrganization(); // returns "Spatie BVBA"

Getting the additional domain names

A certificate can cover multiple (sub)domains. Here's how to get them., (*22)

$certificate->getAdditionalDomains(); // returns ["spatie.be", "www.spatie.be]

A domain name return with this method can start with * meaning it is valid for all subdomains of that domain., (*23)

Getting the fingerprint

$certificate->getFingerprint(); // returns a fingerprint for the certificate

Getting the SHA256 fingerprint

$certificate->getFingerprintSha256(); // returns a SHA256 fingerprint for the certificate

Getting the date when the certificate becomes valid

$certificate->validFromDate(); // returns an instance of Carbon

Getting the expiration date

$certificate->expirationDate(); // returns an instance of Carbon

Determining if the certificate is still valid

Returns true if the current Date and time is between validFromDate and expirationDate., (*24)

$certificate->isValid(); // returns a boolean

You also use this method to determine if a given domain is covered by the certificate. Of course it'll keep checking if the current Date and time is between validFromDate and expirationDate., (*25)

$certificate->isValid('spatie.be'); // returns true;
$certificate->isValid('laravel.com'); // returns false;

Determining if the certificate is still valid until a given date

Returns true if the certificate is valid and if the expirationDate is after the given date., (*26)

$certificate->isValidUntil(Carbon::now()->addDays(7)); // returns a boolean

Determining if the certificate is expired

$certificate->isExpired(); // returns a boolean if expired

Convert the certificate to an array

You can convert a certificate to an array using the toArray method., (*27)

$certificateProperties = $certificate->toArray();

The properties can be used to create a new instance of the certificate., (*28)

\Spatie\SslCertificate\SslCertificate::createFromArray($certificateProperties);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently., (*29)

Contributing

Please see CONTRIBUTING for details., (*30)

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities., (*31)

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using., (*32)

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium., (*33)

We publish all received postcards on our company website., (*34)

Credits

The helper functions and tests were copied from the Laravel Framework., (*35)

License

The MIT License (MIT). Please see License File for more information., (*36)

The Versions

25/06 2018

dev-master

9999999-dev https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

25/06 2018

1.12.8

1.12.8.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

11/05 2018

1.12.7

1.12.7.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

30/04 2018

1.12.6

1.12.6.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

24/04 2018

1.12.5

1.12.5.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

02/03 2018

1.12.4

1.12.4.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

26/02 2018

1.12.3

1.12.3.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

05/02 2018

1.12.2

1.12.2.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

02/02 2018

1.12.1

1.12.1.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

28/12 2017

1.12.0

1.12.0.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

08/11 2017

1.11.7

1.11.7.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

01/11 2017

1.11.6

1.11.6.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

30/10 2017

1.11.5

1.11.5.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

30/10 2017

1.11.4

1.11.4.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

26/10 2017

1.11.3

1.11.3.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

25/10 2017

1.11.2

1.11.2.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

23/10 2017

1.11.1

1.11.1.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

18/09 2017

1.11.0

1.11.0.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

15/09 2017

1.10.0

1.10.0.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

04/09 2017

1.9.1

1.9.1.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

25/08 2017

1.9.0

1.9.0.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

25/08 2017

1.8.0

1.8.0.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

25/08 2017

1.7.0

1.7.0.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

23/08 2017

dev-analysis-qgWV61

dev-analysis-qgWV61 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

23/08 2017

1.6.0

1.6.0.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

11/08 2017

1.5.0

1.5.0.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

10/08 2017

1.4.0

1.4.0.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

10/08 2017

1.4.1

1.4.1.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

18/07 2017

1.3.2

1.3.2.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

08/03 2017

1.3.1

1.3.1.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

19/12 2016

1.3.0

1.3.0.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

16/11 2016

1.2.1

1.2.1.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

20/08 2016

1.2.0

1.2.0.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

20/08 2016

dev-analysis-zDDl65

dev-analysis-zDDl65 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

29/07 2016

1.1.0

1.1.0.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

28/07 2016

1.0.0

1.0.0.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

28/07 2016

dev-review

dev-review https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate

26/07 2016

0.0.1

0.0.1.0 https://github.com/spatie/ssl-certificate

A class to easily query the properties of an ssl certificate

  Sources   Download

MIT

The Requires

 

The Development Requires

spatie ssl-certificate