{"id":13548954,"url":"https://github.com/spatie/ssl-certificate","last_synced_at":"2025-05-13T21:06:54.485Z","repository":{"id":10037296,"uuid":"64165510","full_name":"spatie/ssl-certificate","owner":"spatie","description":"A class to validate SSL certificates","archived":false,"fork":false,"pushed_at":"2025-04-25T13:45:39.000Z","size":228,"stargazers_count":722,"open_issues_count":0,"forks_count":138,"subscribers_count":19,"default_branch":"main","last_synced_at":"2025-04-28T13:59:42.631Z","etag":null,"topics":["certificate","letsencrypt","php","ssl"],"latest_commit_sha":null,"homepage":"https://spatie.be/open-source","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"spatie","custom":"https://spatie.be/open-source/support-us"}},"created_at":"2016-07-25T20:24:44.000Z","updated_at":"2025-04-25T20:26:07.000Z","dependencies_parsed_at":"2023-01-13T15:42:20.085Z","dependency_job_id":"c7e7e65f-f3c2-497a-8e90-70bc13394470","html_url":"https://github.com/spatie/ssl-certificate","commit_stats":{"total_commits":235,"total_committers":51,"mean_commits":4.607843137254902,"dds":"0.37446808510638296","last_synced_commit":"aa4e524a3da5ed0e469eb4edbd8f1cc456854300"},"previous_names":[],"tags_count":79,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fssl-certificate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fssl-certificate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fssl-certificate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fssl-certificate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/ssl-certificate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254028798,"owners_count":22002277,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["certificate","letsencrypt","php","ssl"],"created_at":"2024-08-01T12:01:16.460Z","updated_at":"2025-05-13T21:06:49.475Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://github.com/sponsors/spatie","https://spatie.be/open-source/support-us"],"categories":["PHP"],"sub_categories":[],"readme":"# A class to validate SSL certificates\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/ssl-certificate.svg?style=flat-square)](https://packagist.org/packages/spatie/ssl-certificate)\n[![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![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)\n[![Quality Score](https://img.shields.io/scrutinizer/g/spatie/ssl-certificate.svg?style=flat-square)](https://scrutinizer-ci.com/g/spatie/ssl-certificate)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/ssl-certificate.svg?style=flat-square)](https://packagist.org/packages/spatie/ssl-certificate)\n\nThe 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:\n```php\nuse Spatie\\SslCertificate\\SslCertificate;\n\n// fetch the certificate using an url\n$certificate = SslCertificate::createForHostName('spatie.be');\n\n// or from a certificate file\n$certificate = SslCertificate::createFromFile($pathToCertificateFile);\n\n// or from a string\n$certificate = SslCertificate::createFromString($certificateData);\n\n$certificate-\u003eisValid(); // returns true if the certificate is currently valid\n\n$certificate-\u003eexpirationDate(); // returns a Carbon instance Carbon\n$certificate-\u003evalidFromDate(); // returns a Carbon instance Carbon\n\n$certificate-\u003edaysUntilExpirationDate(); // returns the amount of days between today and expirationDate\n$certificate-\u003elifespanInDays(); // return the amount of days between validFromDate and expirationDate\n\n$certificate-\u003egetIssuer(); // returns \"Let's Encrypt Authority X3\"\n$certificate-\u003egetOrganization(); // returns the organization name when available\n$certificate-\u003egetPublicKeyAlgorithm(); // returns the public key algorithm\n$certificate-\u003egetPublicKeySize(); // returns the public key algorithm\n$certificate-\u003egetSignatureAlgorithm(); // returns the signature algorithm\n```\n\n#### Downloading invalid certificate\n\nIf 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:\n\n```\n$certificate = SslCertificate::createForHostName('expired.badssl.com', $timeoutInSeconds, false);\n```\n\n## About us\n\nSpatie 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).\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/ssl-certificate.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/ssl-certificate)\n\nWe 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).\n\nWe 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).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/ssl-certificate\n```\n\n## Important notice\n\nCurrently, 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.\n\n## Usage\n\nYou can create an instance of `Spatie\\SslCertificate\\SslCertificate` with this named constructor:\n\n```php\n$certificate = SslCertificate::createForHostName('spatie.be');\n```\n\nYou can create an instance of `Spatie\\SslCertificate\\SslCertificate` passing the port with this named constructor:\n\n```php\n$certificate = SslCertificate::createForHostName('spatie.be:443');\n```\n\nYou can use this fluent style to specify a specific port to connect to.\n\n```php\nSslCertificate::download()\n   -\u003eusingPort($customPort)\n   -\u003eforHost($hostName);\n```\n\nYou can check the certificate on a different IP address using the same style.\n```php\nSslCertificate::download()\n   -\u003efromIpAddress($ipAddress)\n   -\u003eforHost($hostName);\n```\n\nThis also works with IPv6 addresses\n```php\nSslCertificate::download()\n    -\u003efromIpAddress('2a00:1450:4001:80e::200e')\n    -\u003eforHost('google.com');\n```\n\nYou can specify [socket context options](https://www.php.net/manual/en/context.socket.php).\n```php\nSslCertificate::download()\n   -\u003ewithSocketContextOptions([\n      'option' =\u003e 'value',\n   ])\n   -\u003eforHost($hostName);\n```\n\nIf the given `ipAddress` is invalid `Spatie\\SslCertificate\\Exceptions\\InvalidIpAddress` will be thrown.\n\nIf the given `hostName` is invalid `Spatie\\SslCertificate\\Exceptions\\InvalidUrl` will be thrown.\n\nIf the given `hostName` is valid but there was a problem downloading the certifcate `Spatie\\SslCertificate\\Exceptions\\CouldNotDownloadCertificate` will be thrown.\n\n### Getting the issuer name\n\n```php\n$certificate-\u003egetIssuer(); // returns \"Let's Encrypt Authority X3\"\n```\n\n### Getting the domain name\n\nReturns the primary domain name for the certificate\n\n```php\n$certificate-\u003egetDomain(); // returns \"spatie.be\"\n```\n\n### Getting the certificate's signing algorithm\n\nReturns the algorithm used for signing the certificate\n\n```php\n$certificate-\u003egetSignatureAlgorithm(); // returns \"RSA-SHA256\"\n```\n\n### Getting the certificate's organization\n\nReturns the organization belonging to the certificate\n\n```php\n$certificate-\u003egetOrganization(); // returns \"Spatie BVBA\"\n```\n\n### Getting the additional domain names\n\nA certificate can cover multiple (sub)domains. Here's how to get them.\n\n```php\n$certificate-\u003egetAdditionalDomains(); // returns [\"spatie.be\", \"www.spatie.be]\n```\n\nA domain name return with this method can start with `*` meaning it is valid for all subdomains of that domain.\n\n### Getting the fingerprint\n\n```php\n$certificate-\u003egetFingerprint(); // returns a fingerprint for the certificate\n```\n\n### Getting the SHA256 fingerprint\n\n```php\n$certificate-\u003egetFingerprintSha256(); // returns a SHA256 fingerprint for the certificate\n```\n\n### Getting the date when the certificate becomes valid\n\n```php\n$certificate-\u003evalidFromDate(); // returns an instance of Carbon\n```\n\n### Getting the expiration date\n\n```php\n$certificate-\u003eexpirationDate(); // returns an instance of Carbon\n```\n\n### Determining if the certificate is still valid\n\nReturns true if the current Date and time is between `validFromDate` and `expirationDate`.\n\n```php\n$certificate-\u003eisValid(); // returns a boolean\n```\n\nYou 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`.\n\n```php\n$certificate-\u003eisValid('spatie.be'); // returns true;\n$certificate-\u003eisValid('laravel.com'); // returns false;\n```\n\n### Determining if the certificate is still valid until a given date\n\nReturns true if the certificate is valid and if the `expirationDate` is after the given date.\n\n```php\n$certificate-\u003eisValidUntil(Carbon::now()-\u003eaddDays(7)); // returns a boolean\n```\n\n### Determining if the certificate is expired\n\n```php\n$certificate-\u003eisExpired(); // returns a boolean if expired\n```\n\n### Convert the certificate to an array\n\nYou can convert a certificate to an array using the `toArray` method.\n\n```php\n$certificateProperties = $certificate-\u003etoArray();\n```\n\nThe properties can be used to create a new instance of the certificate.\n\n```php\n\\Spatie\\SslCertificate\\SslCertificate::createFromArray($certificateProperties);\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Postcardware\n\nYou'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.\n\nOur address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.\n\nWe publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\nThe helper functions and tests were copied from the [Laravel Framework](https://github.com/laravel/framework).\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fssl-certificate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Fssl-certificate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fssl-certificate/lists"}