k2gl/dsse
Composer 安装命令:
composer require k2gl/dsse
包简介
Sign and verify DSSE (Dead Simple Signing Envelope) payloads in PHP, with pluggable keys.
关键字:
README 文档
README
Sign and verify DSSE (Dead Simple Signing Envelope) payloads in PHP with pluggable keys. It's the envelope Sigstore, in-toto, SLSA and npm provenance use to wrap a signed payload.
It gives you the three pieces of the spec and nothing else:
- PAE — the exact, binary-safe byte string that gets signed.
- Envelope — the JSON envelope (
payload/payloadType/signatures) with lossless (de)serialization. - Signer / Verifier — tiny interfaces so you can plug in any key (or a remote KMS/HSM). ECDSA (P-256/384/521), Ed25519, and RSA (PKCS#1 v1.5) implementations are included.
Install
composer require k2gl/dsse
Requires PHP 8.1+. The bundled signers use ext-openssl (ECDSA P-256/384/521, RSA) and
ext-sodium (Ed25519); both ship with PHP by default. The core (Pae, Envelope)
needs neither.
Usage
PAE — what actually gets signed
use K2gl\Dsse\Pae; Pae::encode('http://example.com/HelloWorld', 'hello world'); // "DSSEv1 29 http://example.com/HelloWorld 11 hello world"
Lengths are byte counts, so the encoding is unambiguous for any payload, including binary data.
Sign
use K2gl\Dsse\Envelope; use K2gl\Dsse\EcdsaP256Signer; $signer = EcdsaP256Signer::fromPem($privateKeyPem, keyId: 'k1'); $envelope = Envelope::sign('hello world', 'http://example.com/HelloWorld', $signer); echo $envelope->toJson(); // {"payload":"aGVsbG8gd29ybGQ=","payloadType":"http://example.com/HelloWorld","signatures":[{"keyid":"k1","sig":"..."}]}
Envelope::sign() accepts several signers to produce a multi-signature envelope.
Verify
use K2gl\Dsse\Envelope; use K2gl\Dsse\EcdsaP256Verifier; use K2gl\Dsse\Exception\SignatureVerificationFailed; $envelope = Envelope::fromJson($json); try { $payload = $envelope->verify(EcdsaP256Verifier::fromPem($publicKeyPem)); // $payload === 'hello world' } catch (SignatureVerificationFailed) { // no signature matched any supplied verifier }
The envelope is accepted if any signature verifies against any verifier you pass, mirroring the spec's verification model. Pass several verifiers to accept a set of trusted keys.
Ed25519
use K2gl\Dsse\Ed25519Signer; use K2gl\Dsse\Ed25519Verifier; $keypair = sodium_crypto_sign_keypair(); $signer = new Ed25519Signer(sodium_crypto_sign_secretkey($keypair), 'ed-1'); $verifier = new Ed25519Verifier(sodium_crypto_sign_publickey($keypair));
ECDSA P-384 / P-521 and RSA
The other bundled algorithms follow the same fromPem() pattern:
use K2gl\Dsse\EcdsaP384Signer; use K2gl\Dsse\EcdsaP384Verifier; use K2gl\Dsse\RsaSigner; use K2gl\Dsse\RsaVerifier; $signer = EcdsaP384Signer::fromPem($p384PrivateKeyPem); $verifier = EcdsaP384Verifier::fromPem($p384PublicKeyPem); // RSASSA-PKCS1-v1_5; hash algorithm defaults to sha256 (sha384/sha512 also supported) $rsaSigner = RsaSigner::fromPem($rsaPrivateKeyPem, hashAlgorithm: 'sha512'); $rsaVerifier = RsaVerifier::fromPem($rsaPublicKeyPem, hashAlgorithm: 'sha512');
EcdsaP521Signer / EcdsaP521Verifier work identically.
Loading a key without knowing its algorithm
When a key arrives as a PEM file or a JWK from a JWKS endpoint, PublicKey picks the
right verifier for you — RSA, ECDSA (P-256/384/521) or Ed25519 — so you don't have to
branch on the algorithm yourself:
use K2gl\Dsse\PublicKey; $verifier = PublicKey::fromPem($publicKeyPem); // detects the algorithm and curve $verifier = PublicKey::fromJwk($jwk); // EC / RSA / OKP (Ed25519) $payload = $envelope->verify($verifier);
RSA keys carry no hash, so these verify with SHA-256; for another hash use
RsaVerifier::fromPem($pem, hashAlgorithm: 'sha512') directly.
KeyId computes the two identifiers commonly used for a signature's keyId:
use K2gl\Dsse\KeyId; KeyId::sha256Spki($publicKeyPem); // hex SHA-256 of the DER key (cosign / Sigstore style) KeyId::jwkThumbprint($jwk); // RFC 7638 base64url thumbprint
Plugging in your own key backend
Implement two methods to sign with a KMS/HSM or any other scheme:
use K2gl\Dsse\Signer; final class KmsSigner implements Signer { public function sign(string $message): string { /* sign PAE bytes, return raw signature */ } public function keyId(): ?string { return 'arn:aws:kms:...'; } }
Design
- Crypto-agnostic core.
PaeandEnvelopecarry no cryptography; signing is delegated toSigner/Verifier, so you control the algorithm and key storage. - Raw signatures. The bundled ECDSA signers emit raw
r||ssignatures (64/96/132 bytes for P-256/384/521) (the form DSSE/JOSE/WebCrypto/Sigstore use), converting to and from OpenSSL's DER internally. The verifier accepts both rawr||sand ASN.1 DER signatures, detecting the encoding automatically — so DER signatures (OpenSSL native, Sigstore bundles) verify without any extra wiring. - Strict and typed.
declare(strict_types=1)throughout, analysed at PHPStan level 9; every exception implementsDsseException.
License
MIT — see LICENSE.
Based on the DSSE specification (Apache-2.0) by the Secure Systems Lab; this is an independent, clean-room PHP implementation.
k2gl/dsse 适用场景与选型建议
k2gl/dsse 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.5k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「signature」 「signing」 「ECDSA」 「envelope」 「supply-chain」 「Ed25519」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 k2gl/dsse 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 k2gl/dsse 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 k2gl/dsse 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
BitWeb extension for Estonian ID-Card and Mobile ID authentication and signing.
接口签名验证
PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.
PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.
Digital signature Nova field.
PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.
统计信息
- 总下载量: 1.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 40
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-30