Git Product home page Git Product logo

ssl-certificate's Introduction

A class to validate SSL certificates

Latest Version on Packagist Software License Build Status SensioLabsInsight Quality Score StyleCI Total Downloads

The class provided by this package makes it incredibly easy to query the properties on an ssl certificate. Here's an example:

use Spatie\SslCertificate\SslCertificate;

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

$certificate->getIssuer(); // returns "Let's Encrypt Authority X3"
$certificate->isValid(); // returns true if the certificate is currently valid
$certificate->expirationDate(); // returns an instance of Carbon
$certificate->expirationDate()->diffInDays(); // returns an int
$certificate->getSignatureAlgorithm(); // returns a string

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

Installation

You can install the package via composer:

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.

Usage

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

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

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

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

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

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

Getting the domain name

Returns the primary domain name for the certificate

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

Getting the certificate's signing algorithm

Returns the algorithm used for signing the certificate

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

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

$certificate->getFingerprint(); // returns a 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.

$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

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

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

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

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, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

The helper functions and tests were copied from the Laravel Framework.

Support us

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

Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

License

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

ssl-certificate's People

Contributors

freekmurze avatar mattiasgeniar avatar sebastiandedeyne avatar vojtech-dobes avatar akoepcke avatar stayallive avatar mallardduck avatar demiand avatar eugenmayer avatar carusogabriel avatar mm-pagely avatar sunscreem avatar thomasbs avatar tjoosten avatar vmitchell85 avatar ato10 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.