承接 spatie/ssl-certificate 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

spatie/ssl-certificate

Composer 安装命令:

composer require spatie/ssl-certificate

包简介

A class to easily query the properties of an ssl certificate

README 文档

README

Latest Version on Packagist MIT Licensed run-tests Quality Score Total Downloads

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->getSubjectOrganization(); // returns the subject 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

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

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

Support us

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.

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.

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

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

$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 certificate's organization

Returns the organization belonging to the certificate

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

Getting the subject's organization

Returns the organization of the certificate's subject

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

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

$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

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

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

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.

Credits

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

License

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

spatie/ssl-certificate 适用场景与选型建议

spatie/ssl-certificate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.18M 次下载、GitHub Stars 达 741, 最近一次更新时间为 2016 年 07 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「spatie」 「ssl-certificate」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 spatie/ssl-certificate 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 spatie/ssl-certificate 我们能提供哪些服务?
定制开发 / 二次开发

基于 spatie/ssl-certificate 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.18M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 751
  • 点击次数: 26
  • 依赖项目数: 37
  • 推荐数: 5

GitHub 信息

  • Stars: 741
  • Watchers: 16
  • Forks: 137
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-25