spomky-labs/pki-framework
PHP 8.1+ framework for Public Key Infrastructure: X.509 certificates (incl. attribute certs), ASN.1 DER encoding/decoding, X.501/X.520 DN parsing, PEM (RFC 7468) handling, and PKCS-oriented cryptography utilities.
php artisan pki:rotate).Certificate, CertificateAuthority, Validation) allows selective adoption (e.g., use only ASN.1 parsing or full CA management).brick/math (for cryptographic operations) is already used in Laravel’s spatie/laravel-encryption and vlucas/phpdotenv.ext-openssl is a soft dependency (used for fallback operations), ensuring compatibility with Laravel’s existing TLS stack.CertificateAuthority, Validator) as singletons.// app/Providers/PKIServiceProvider.php
public function register()
{
$this->app->singleton(CertificateAuthority::class, function ($app) {
return new CertificateAuthority(
new FilePrivateKey('/path/to/ca.key'),
new FileCertificate('/path/to/ca.crt')
);
});
}
certificates table with DER/PEM blobs) for auditing/revocation.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Cryptographic Complexity | ASN.1/DER parsing and PKCS operations are error-prone if misconfigured (e.g., invalid OIDs, weak key generation). | - Unit test validation logic (e.g., mock CertificateAuthority with known-good inputs). |
- Use ext-openssl as a sanity check for critical operations (e.g., verify generated certificates with openssl x509 -in cert.pem -text -noout). |
||
| Key Management | Private keys must be securely stored (e.g., encrypted at rest, HSM-backed). | - Integrate with Laravel Forge/Vault for secrets management (e.g., Hashicorp/Vault or AWS KMS). |
- Avoid hardcoding keys in Git; use environment variables or Laravel’s config/services.php. |
||
| Performance Overhead | ASN.1 parsing is CPU-intensive for high-volume validation (e.g., 10,000+ requests/sec). | - Cache parsed certificates (e.g., Illuminate\Support\Facades\Cache::remember). |
| - Offload validation to edge proxies (e.g., Traefik, Envoy) where possible. | ||
| Revocation Latency | CRL/OCSP checks add network latency if not cached. | - Pre-fetch CRLs/OCSP responses during low-traffic periods (e.g., cron job). |
- Use spomky-labs/ocsp (if available) for async OCSP validation. |
||
| Laravel Ecosystem Gaps | No native integration with Laravel’s auth systems (e.g., Sanctum, Passport). | - Build a custom CertificateGuard extending Laravel’s Authenticatable. |
- Extend Passport’s TokenRepository to validate client certificates. |
||
| Long-Term Maintenance | The package is MIT-licensed but unsponsored; future updates depend on community contributions. | - Fork and maintain if critical features are missing (e.g., OCSP stapling). |
| - Monitor GitHub issues for regressions (e.g., ASN.1 parsing bugs). |
Security Ownership:
Operational Workflow:
Performance Requirements:
Compliance and Auditing:
Integration Depth:
openssl CLI usage in the codebase, or coexist with existing tools?Team Expertise:
| Laravel Component | Integration Strategy | Example Use Case |
|---|---|---|
| Authentication | Replace or extend Sanctum/Passport with certificate-based auth (e.g., validate client certs in AuthenticatesRequests). |
mTLS for internal APIs or machine-to-machine auth. |
| API Gateways | Use Laravel Echo/Horizon to validate certificates in WebSocket connections or HTTP requests (e.g., middleware). | Secure real-time dashboards or IoT device APIs. |
| Task Scheduling | Automate certificate rotation via Laravel’s scheduler (e.g., php artisan pki:rotate --days=30). |
Renew expired certificates in CI/CD pipelines or microservices. |
| Queue Workers | Offload OCSP/CRL checks to queues (e.g., spomky-labs/ocsp + Laravel Queues). |
Async validation for high-traffic APIs. |
| Database | Store certificates in Laravel Eloquent models (e.g., Certificate with DER/PEM fields) for auditing. |
Track issuance/revocation history for compliance. |
| Caching | Cache parsed certificates and CRLs using Laravel Cache (Redis/Memcached). | Reduce ASN.1 parsing overhead in high-QPS environments. |
| Service Providers | Register PKI components as Laravel bindings (e.g |
How can I help you explore Laravel packages today?