PHPackages                             spatie/ssl-certificate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. spatie/ssl-certificate

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

spatie/ssl-certificate
======================

A class to easily query the properties of an ssl certificate

2.6.10(1y ago)7414.8M—4.1%13720MITPHPPHP ^8.1CI passing

Since Jul 26Pushed 8mo ago17 watchersCompare

[ Source](https://github.com/spatie/ssl-certificate)[ Packagist](https://packagist.org/packages/spatie/ssl-certificate)[ Docs](https://github.com/spatie/ssl-certificate)[ GitHub Sponsors](https://github.com/sponsors/spatie)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/spatie-ssl-certificate/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (80)Used By (20)

A class to validate SSL certificates
====================================

[](#a-class-to-validate-ssl-certificates)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f9842eb53f191a9f37ad8f9589873e3d5adb76c72c89c3b544b3c3aaeaffb1b2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f73736c2d63657274696669636174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/ssl-certificate)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![run-tests](https://github.com/spatie/ssl-certificate/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/ssl-certificate/actions/workflows/run-tests.yml)[![Quality Score](https://camo.githubusercontent.com/73cc354aa5421f69a0031b22e55eb55562f626b1fe257fda995d3d6bef46de5a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f73736c2d63657274696669636174652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/ssl-certificate)[![Total Downloads](https://camo.githubusercontent.com/a73792553b6e9ab32a19fc874f9fcd9a03f424c9e506fde9a2d4dee8f3cafcda/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f73736c2d63657274696669636174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/ssl-certificate)

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:

```
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 size
$certificate->getSignatureAlgorithm(); // returns the signature algorithm
```

#### Downloading invalid certificate

[](#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:

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

```

About us
--------

[](#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](https://spatie.be/opensource).

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/92516b42182beb1678cf0f37c45793da6149e090f17afbf8a1fc5cccdb0fd315/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f73736c2d63657274696669636174652e6a70673f743d31)](https://spatie.be/github-ad-click/ssl-certificate)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

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](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/ssl-certificate
```

Important notice
----------------

[](#important-notice)

Currently, this package [does not check](https://github.com/spatie/ssl-certificate/blob/master/src/SslCertificate.php#L63-L74) if the certificate is signed by a trusted authority. We'll add this check soon in a next point release.

Usage
-----

[](#usage)

You can create an instance of `Spatie\SslCertificate\SslCertificate` with this named constructor:

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

You can create an instance of `Spatie\SslCertificate\SslCertificate` passing the port with this named constructor:

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

You can use this fluent style to specify a specific port to connect to.

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

You can check the certificate on a different IP address using the same style.

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

This also works with IPv6 addresses

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

You can specify [socket context options](https://www.php.net/manual/en/context.socket.php).

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

If the given `ipAddress` is invalid `Spatie\SslCertificate\Exceptions\InvalidIpAddress` will be thrown.

If the given `hostName` is invalid `Spatie\SslCertificate\Exceptions\InvalidUrl` will be thrown.

If the given `hostName` is valid but there was a problem downloading the certifcate `Spatie\SslCertificate\Exceptions\CouldNotDownloadCertificate` will be thrown.

### Getting the issuer name

[](#getting-the-issuer-name)

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

### Getting the domain name

[](#getting-the-domain-name)

Returns the primary domain name for the certificate

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

### Getting the certificate's signing algorithm

[](#getting-the-certificates-signing-algorithm)

Returns the algorithm used for signing the certificate

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

### Getting the certificate's organization

[](#getting-the-certificates-organization)

Returns the organization belonging to the certificate

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

### Getting the additional domain names

[](#getting-the-additional-domain-names)

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

```
$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.

### Getting the fingerprint

[](#getting-the-fingerprint)

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

### Getting the SHA256 fingerprint

[](#getting-the-sha256-fingerprint)

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

### Getting the date when the certificate becomes valid

[](#getting-the-date-when-the-certificate-becomes-valid)

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

### Getting the expiration date

[](#getting-the-expiration-date)

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

### Determining if the certificate is still valid

[](#determining-if-the-certificate-is-still-valid)

Returns true if the current Date and time is between `validFromDate` and `expirationDate`.

```
$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`.

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

### Determining if the certificate is still valid until a given date

[](#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.

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

### Determining if the certificate is expired

[](#determining-if-the-certificate-is-expired)

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

### Convert the certificate to an array

[](#convert-the-certificate-to-an-array)

You can convert a certificate to an array using the `toArray` method.

```
$certificateProperties = $certificate->toArray();
```

The properties can be used to create a new instance of the certificate.

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

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Postcardware
------------

[](#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.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

The helper functions and tests were copied from the [Laravel Framework](https://github.com/laravel/framework).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

67

—

FairBetter than 100% of packages

Maintenance55

Moderate activity, may be stable

Popularity67

Solid adoption and visibility

Community44

Growing community involvement

Maturity87

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 72% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~41 days

Recently: every ~80 days

Total

79

Last Release

388d ago

Major Versions

0.0.1 → 1.0.02016-07-28

1.22.1 → 2.0.02021-03-30

PHP version history (5 changes)0.0.1PHP ^7.0

1.15.0PHP ^7.2

1.21.1PHP ^7.4|^8.0

2.0.0PHP ^8.0

2.4.1PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (188 commits)")[![mattiasgeniar](https://avatars.githubusercontent.com/u/407270?v=4)](https://github.com/mattiasgeniar "mattiasgeniar (15 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (9 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (7 commits)")[![JoeHorn](https://avatars.githubusercontent.com/u/85422?v=4)](https://github.com/JoeHorn "JoeHorn (4 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (4 commits)")[![colinodell](https://avatars.githubusercontent.com/u/202034?v=4)](https://github.com/colinodell "colinodell (3 commits)")[![lloricode](https://avatars.githubusercontent.com/u/8251344?v=4)](https://github.com/lloricode "lloricode (3 commits)")[![vojtech-dobes](https://avatars.githubusercontent.com/u/415925?v=4)](https://github.com/vojtech-dobes "vojtech-dobes (2 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![laszlojau](https://avatars.githubusercontent.com/u/49835454?v=4)](https://github.com/laszlojau "laszlojau (2 commits)")[![markvaneijk](https://avatars.githubusercontent.com/u/1925388?v=4)](https://github.com/markvaneijk "markvaneijk (2 commits)")[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (2 commits)")[![rudiedirkx](https://avatars.githubusercontent.com/u/168024?v=4)](https://github.com/rudiedirkx "rudiedirkx (2 commits)")[![mbardelmeijer](https://avatars.githubusercontent.com/u/1583095?v=4)](https://github.com/mbardelmeijer "mbardelmeijer (1 commits)")[![mm-pagely](https://avatars.githubusercontent.com/u/20521636?v=4)](https://github.com/mm-pagely "mm-pagely (1 commits)")[![khromov](https://avatars.githubusercontent.com/u/1207507?v=4)](https://github.com/khromov "khromov (1 commits)")[![pascalbaljet](https://avatars.githubusercontent.com/u/8403149?v=4)](https://github.com/pascalbaljet "pascalbaljet (1 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (1 commits)")[![ramonfincken](https://avatars.githubusercontent.com/u/1746097?v=4)](https://github.com/ramonfincken "ramonfincken (1 commits)")

---

Tags

certificateletsencryptphpsslspatiessl-certificate

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/spatie-ssl-certificate/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-ssl-certificate/health.svg)](https://phpackages.com/packages/spatie-ssl-certificate)
```

###  Alternatives

[spatie/laravel-analytics

A Laravel package to retrieve Google Analytics data.

3.2k5.7M57](/packages/spatie-laravel-analytics)[spatie/laravel-schedule-monitor

Monitor scheduled tasks in a Laravel app

9815.7M9](/packages/spatie-laravel-schedule-monitor)[spatie/url

Parse, build and manipulate URL's

73914.3M97](/packages/spatie-url)[spatie/laravel-google-calendar

Manage events on a Google Calendar

1.4k1.5M21](/packages/spatie-laravel-google-calendar)[spatie/dns

Retrieve DNS records

6082.3M17](/packages/spatie-dns)[spatie/laravel-personal-data-export

Create personal data downloads in a Laravel app

550543.8k8](/packages/spatie-laravel-personal-data-export)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
