Skip to content

fix(tl): emit DER C2SP checkpoint signatures#38

Merged
csnitker-godaddy merged 2 commits into
mainfrom
codex/c2sp-checkpoint-der-signatures
Jun 4, 2026
Merged

fix(tl): emit DER C2SP checkpoint signatures#38
csnitker-godaddy merged 2 commits into
mainfrom
codex/c2sp-checkpoint-der-signatures

Conversation

@csnitker-godaddy

@csnitker-godaddy csnitker-godaddy commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Identified a bug while reviewing PR feat(verify): add provider enumeration mode to ans-verify #32 with deviation from how the checkpoint signatures are emitted
  • Emit ASN.1 DER ECDSA bytes for the primary raw C2SP checkpoint signature line: <keyhash:4> || <DER signature>.
  • Verify DER checkpoint signatures with ecdsa.VerifyASN1, while retaining a legacy P1363 fallback for existing local-dev checkpoints.
  • Add regression coverage for direct signer output, sumdb/note keyhash wrapping, DER verification, and legacy P1363 verification.
  • Remove deprecated chi RealIP middleware calls surfaced by make check; the repo does not currently consume RemoteAddr or chi client-IP context.

Wire Shape

Canonical contract reference: spec/api-spec-tl-v2.yaml documents CheckpointSignature.rawSignature as base64-encoded raw signature bytes with shape <keyhash:4> || <sig>.

This PR changes the local primary C2SP checkpoint signer from:

<4-byte keyhash> || <IEEE P1363 r||s ECDSA signature>

to production parity:

<4-byte keyhash> || <ASN.1 DER ECDSA signature>

JWS checkpoint signatures, COSE receipts, and status tokens remain P1363.

Validation

  • go test ./internal/tl/logstore ./internal/tl/service
  • make check

Return the KeyManager DER signature directly for the primary C2SP checkpoint signer and verify DER with ecdsa.VerifyASN1, while keeping a legacy P1363 verifier fallback for local checkpoints.

Update checkpoint signature comments and add regression coverage for signer output, sumdb-note keyhash wrapping, DER verification, and P1363 compatibility.

Remove deprecated chi RealIP middleware calls surfaced by make check; the repo does not currently consume RemoteAddr/client-IP state.

Signed-off-by: Connor Snitker <csnitker@godaddy.com>
Copilot AI review requested due to automatic review settings June 4, 2026 16:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aligns the TL checkpoint primary (C2SP / sumdb-note) signature wire format with production by emitting ASN.1 DER-encoded ECDSA signatures (wrapped as <keyhash:4> || <sig>), updates verification to prefer ecdsa.VerifyASN1 with a legacy P1363 fallback, and removes deprecated chi RealIP middleware usage.

Changes:

  • Emit DER ECDSA bytes for the primary checkpoint signature and verify with ecdsa.VerifyASN1 (legacy P1363 verification retained).
  • Add/adjust regression tests covering DER signer output, sumdb/note wrapping, DER verification, and legacy P1363 verification.
  • Remove deprecated middleware.RealIP calls from TL/RA HTTP router setup.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/tl/service/checkpoint.go Updates checkpoint signature metadata/comments and C2SP verification description to reflect DER-first ECDSA verification.
internal/tl/service/checkpoint_helpers_test.go Updates parser test fixture to use a DER-shaped signature blob.
internal/tl/logstore/signer_errors_test.go Updates negative-path test commentary for DER/P1363 handling.
internal/tl/logstore/c2spsigner.go Switches primary checkpoint signer output to DER and updates verifier to DER-first with P1363 fallback.
internal/tl/logstore/c2spsigner_test.go Adds tests asserting DER output and DER/P1363 verification behavior.
internal/crypto/p1363.go Updates documentation to reflect DER↔P1363 conversion responsibilities for JWS/COSE callers.
cmd/ans-tl/main.go Removes deprecated chi RealIP middleware.
cmd/ans-ra/main.go Removes deprecated chi RealIP middleware.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 90 to +92
SignerName string
SignatureType string // "C2SP" (sumdb note) or "JWS" (additional signer)
Algorithm string // "ED25519" for C2SP, "ES256" for JWS
Algorithm string // "ES256" for the single ECDSA checkpoint signing key
Comment on lines 95 to +101
func (s *C2SPECDSASigner) Sign(msg []byte) ([]byte, error) {
digest := sha256.Sum256(msg)
rawSig, err := s.km.Sign(context.Background(), s.keyID, digest[:])
if err != nil {
return nil, fmt.Errorf("logstore: c2sp sign: %w", err)
}
// KeyManager returns ASN.1 DER; C2SP wants IEEE P1363 (r||s).
// P-256 coordinates are 32 bytes.
coordBytes := (s.pub.Curve.Params().BitSize + 7) / 8
p1363, err := anscrypto.DERToP1363(rawSig, coordBytes)
if err != nil {
return nil, fmt.Errorf("logstore: c2sp sig format: %w", err)
}
return p1363, nil
return rawSig, nil
@csnitker-godaddy csnitker-godaddy added this pull request to the merge queue Jun 4, 2026
Merged via the queue into main with commit d94d531 Jun 4, 2026
2 checks passed
@csnitker-godaddy csnitker-godaddy deleted the codex/c2sp-checkpoint-der-signatures branch June 4, 2026 21:21
nicknacnic added a commit to nicknacnic/ans that referenced this pull request Jun 7, 2026
Updates signTestCheckpoint in walk_test.go to produce ASN.1 DER
ECDSA signatures, matching the production wire shape restored in
godaddy/ans PR godaddy#38 ("fix(tl): emit DER C2SP checkpoint signatures").

VerifyC2SPECDSA on main still accepts IEEE P1363 r||s as a legacy
fallback for older local-dev checkpoints, so the previous P1363
fixture continued to pass — but the tests should pin the format
verifiers will see in production, not the deprecated one.

Walker production code is unchanged: verifyCheckpointNote delegates
ECDSA verification to logstore.VerifyC2SPECDSA, which after PR godaddy#38
transparently accepts DER (primary) and P1363 (legacy). No other
adjustments needed.

Signed-off-by: Layer8 <NWillAU900@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants