定制 k2gl/dsse 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

k2gl/dsse

最新稳定版本:1.1.1

Composer 安装命令:

composer require k2gl/dsse

包简介

Faithful, zero-dependency PHP implementation of DSSE (Dead Simple Signing Envelope): PAE encoding, envelope (de)serialization, and pluggable signers/verifiers.

README 文档

README

CI Latest Stable Version Total Downloads PHPStan Level License

A faithful, zero-dependency PHP implementation of DSSE — the Dead Simple Signing Envelope used by Sigstore, in-toto, SLSA and npm provenance to sign and verify arbitrary payloads.

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 and Ed25519 implementations are included.

Install

composer require k2gl/dsse

Requires PHP 8.1+. The bundled signers use ext-openssl (ECDSA P-256) 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));

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. Pae and Envelope carry no cryptography; signing is delegated to Signer / Verifier, so you control the algorithm and key storage.
  • Raw signatures. The bundled ECDSA P-256 signer emits 64-byte r||s signatures (the form DSSE/JOSE/WebCrypto/Sigstore use), converting to and from OpenSSL's DER internally. The verifier accepts both raw r||s and 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 implements DsseException.

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.

统计信息

  • 总下载量: 418
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固