web-auth/cose-lib
PHP 8.1+ COSE (RFC 9052/9053) library: sign, encrypt, and MAC with full tag support (Sign1/Sign, Encrypt0/Encrypt, Mac0/Mac). Supports ECDSA, EdDSA, RSA, and HMAC. Compatible with WebAuthn/FIDO2.
spomky-labs/cbor-php, brick/math, spomky-labs/pki-framework).| Risk Area | Mitigation Strategy |
|---|---|
| CBOR/COSE complexity | Library provides high-level abstractions (e.g., CoseSign1Tag::create()), reducing manual CBOR handling. |
| Cryptographic bugs | Comprehensive test suite (including COVID-19 certificate verification) and PHPStan compliance minimize edge-case failures. |
| Algorithm misconfiguration | Explicit algorithm identifiers (e.g., -7 for ES256) enforce correct usage. |
| Dependency bloat | Core functionality is lightweight; spomky-labs/cbor-php is the only mandatory external dependency. |
| Performance overhead | Optimized for PHP 8.1+ with strict types; benchmarking recommended for high-throughput systems. |
kid) and public/private keys be stored/retrieved? (e.g., database, AWS KMS, hardware tokens).| Component | Compatibility Notes |
|---|---|
| PHP 8.1+ | Required; leverages strict types and modern PHP features. |
| Laravel | Seamless integration via Composer; can be used in controllers, commands, or queues. |
| Symfony | Works with Symfony’s security component for authentication flows (e.g., WebAuthn). |
| API Platform | Can replace JWT with COSE_Sign1 for compact, CBOR-based signatures. |
| Queues (Redis/DB) | Cryptographic operations can be offloaded to workers to avoid request latency. |
| Databases | CBOR-encoded COSE messages can be stored in binary fields (e.g., PostgreSQL bytea). |
| Frontend (JS) | Use @peculiar/webcrypto or cose-js for client-side interoperability. |
| Cloud (AWS/GCP) | Integrates with KMS for key management and IAM roles for cryptographic ops. |
spomky-labs/cbor-php and brick/math are pinned to stable versions in composer.json.spomky-labs/pki-framework).composer require web-auth/cose-lib spomky-labs/cbor-php
composer.json:
"autoload": {
"psr-4": {
"App\\": "src/",
"Cose\\": "vendor/web-auth/cose-lib/src"
}
}
kid ↔ key pairs).// Pseudocode for key retrieval
$publicKey = KeyRepository::getByKid($coseSign1->getUnprotectedHeader()->get('kid'));
$coseSign1 = CoseSign1Tag::create(
$protectedHeader,
$unprotectedHeader,
ByteStringObject::create($payload),
ByteStringObject::create($signature)
);
$isValid = openssl_verify(
(string) Signature1::create($protectedHeader, $payload),
$derSignature,
$publicKey,
'sha256'
);
try {
$coseSign1 = $decoder->decode($stream);
} catch (CborException $e) {
logError("Invalid COSE message");
return false;
}
How can I help you explore Laravel packages today?