spomky-labs/pki-framework
PHP 8.1+ framework for PKI: X.509 certificates, ASN.1 (X.690 DER) encoding/decoding, X.501/X.520 DN parsing, PEM (RFC 7468) support, and cryptographic/PKCS-related ASN.1 types. mbstring required; gmp/bcmath recommended.
Certificate, CertificateAuthority, CRL, OCSP) maps cleanly to Laravel’s service providers and facades, enabling seamless integration into existing auth, API, or microservice architectures.Illuminate\Http\Middleware).AuthenticatesRequests).ext-openssl lacks granularity. Useful for:
CertificateAuthority) in AppServiceProvider::boot().PKI facade to abstract certificate operations (e.g., PKI::validate($certificate)).php artisan pki:issue, php artisan pki:revoke).CertificateIssued, CertificateExpired) via Laravel’s event bus for auditing or notifications.certificates table) for tracking.Illuminate\Support\Facades\Cache) to reduce ASN.1 parsing overhead.| Risk Area | Mitigation Strategy |
|---|---|
| Cryptographic Complexity | - Peer Review: Engage a security expert to audit key management (e.g., private key storage, rotation). |
- Fallback: Use PHP’s ext-openssl for validation where performance is critical (e.g., openssl_x509_parse). |
|
| Key Management | - HSM Integration: For production, integrate with AWS KMS, HashiCorp Vault, or Thales HSMs via spomky-labs/ca-bundle or custom drivers. |
- Environment Variables: Store private keys in Laravel’s .env (encrypted) or use laravel/vault. |
|
| Revocation Latency | - Hybrid Approach: Combine CRL (periodic) and OCSP (on-demand) for revocation checks. Cache OCSP responses with short TTLs. |
| ASN.1 Parsing Errors | - Input Validation: Sanitize certificate inputs (e.g., reject malformed DER/PEM via Certificate::fromString()). |
| - Logging: Log parsing failures to a monitoring system (e.g., Sentry) for debugging. | |
| Performance | - Benchmark: Compare against ext-openssl for validation-heavy workloads (e.g., API gateways). |
| - Async Processing: Offload certificate generation to Laravel Queues for non-critical paths. | |
| Laravel Version Compatibility | - Test Matrix: Validate compatibility with Laravel LTS versions (e.g., 10.x, 11.x) via phpunit tests. |
| Dependency Bloat | - Tree Shaking: Use Composer’s --optimize-autoloader to reduce runtime overhead. |
- Modular Loading: Load only required classes (e.g., Certificate vs. CRL) to minimize memory usage. |
ext-openssl might be preferable?| Laravel Component | Integration Strategy |
|---|---|
| Service Container | Register the PKI framework as a singleton in AppServiceProvider::register(): |
| ```php | |
| $this->app->singleton(CertificateAuthority::class, function ($app) { | |
| return new CertificateAuthority( | |
| new FilePrivateKeyStorage(storage_path('app/ca/private')), | |
| new FileCertificateStorage(storage_path('app/ca/certs')) | |
| ); | |
| }); | |
| Facades | Create a PKI facade to simplify usage: |
| ```php | |
| php artisan make:facade PKI | |
| ``` | |
| // Usage: | |
| $certificate = PKI::issue('example.com', ['CN' => 'example.com']); | |
| Middleware | Validate client certificates in mTLS scenarios: |
| ```php | |
| namespace App\Http\Middleware; | |
| class ValidateClientCertificate | |
| { | |
| public function handle(Request $request, Closure $next) | |
| { | |
| $cert = $request->getClientCert(); | |
| if (!$cert | |
| abort(403, 'Invalid client certificate'); | |
| } | |
| return $next($request); | |
| } | |
| } | |
| Artisan Commands | Build CLI tools for certificate management: |
| ```php | |
| php artisan make:command IssueCertificate | |
| ``` | |
| // Command: | |
| $certificate = PKI::issue($this->argument('subject'), $this->option('san')); | |
| $this |
How can I help you explore Laravel packages today?