Skip to content

Add client-side SCT verification and entry matching in hammer - #897

Merged
phbnf merged 2 commits into
transparency-dev:mainfrom
phbnf:hammersct
Jul 15, 2026
Merged

Add client-side SCT verification and entry matching in hammer#897
phbnf merged 2 commits into
transparency-dev:mainfrom
phbnf:hammersct

Conversation

@phbnf

@phbnf phbnf commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

This PR allows the hammer to verify that the SCTs it receives matches with the requests it sent.

While I'm there, move isPrecertificate to x509util.

I tested this with the hammer locally and it worked. I'll send a PR afterwards that adds instructions to run the hammer locally with a POSIX log unless someone can point me at them!

Fixes #884.

Update hammer's httpWriter to parse and cryptographically verify AddChainResponse signatures against the log's public key. Reconstruct the CertificateTimestamp from the submitted certificate and verify that the LogID, timestamp, and certificate fields in the returned SCT match the request.

Refactor base64 public key extraction into parseLogPublicKeyB64 helper function and reuse it inside logSigVerifier. Implement newAddChainResponseVerifier factory constructor, decoupling HTTP transport from verification logic. Precompute expected Log ID outside verification callback closure to eliminate redundant public key marshaling and SHA-256 computation in the hot path. Pre-allocate chainCerts slice with exact len(req.Chain) capacity and decode response extensions from base64 exactly once into extBytes (parsing via staticct.ParseCTExtensionsBytes) to eliminate redundant allocations and decoding. Ensure verification fails explicitly if public key is nil or request payload is empty, and format verifyWriteResponse error in httpWriter to include verification failure details and readable body string (%q). Export IsPrecertificate in x509util, call x509util.IsPrecertificate directly across chain_validation and hammer without wrappers, and use staticct.NewCertificateTimestamp helper to cleanly construct sctInput.

TAG=agy
CONV=fdd8e21c-6548-461f-8ead-5ec8915de98d
@phbnf
phbnf requested review from AlCutter and roger2hk July 10, 2026 16:03
@phbnf
phbnf marked this pull request as ready for review July 10, 2026 16:04
@phbnf
phbnf requested a review from a team as a code owner July 10, 2026 16:04
@phbnf

phbnf commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

Gentle ping on that one, I'd like to get it in to close on #884.

Comment thread internal/hammer/hammer.go
pubBytes, err := x509.MarshalPKIXPublicKey(pubKey)
if err != nil {
return 0, 0, fmt.Errorf("can't parse extensions: %v", err)
return func(reqBytes []byte, respBytes []byte) (uint64, uint64, error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It feels like at this point we know the user intent is to verify (they've provided a "pub key"), but the key is broken so we should bail rather than return a func which will always error out.

Could perhaps return (func..., error), and just check the err from main rather than inlining in a chained call?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Nice, thanks! I've also added the same check when the key is nil, at which point, you might as well not call the function if your intent it actually to have a nil key.

Comment thread internal/hammer/hammer.go Outdated
Comment on lines +658 to +661
case *rsa.PublicKey:
if err := rsa.VerifyPKCS1v15(pk, crypto.SHA256, digest[:], ds.Signature); err != nil {
return 0, 0, fmt.Errorf("SCT RSA signature verification failed: %w", err)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can probably safely ditch this RSA support and rely on the default "computer says no"?

Pretty sure there are no RSA static CT logs and never should there be :)

@phbnf
phbnf merged commit 2790083 into transparency-dev:main Jul 15, 2026
15 checks passed
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.

Improve robustness when constructing SCT for duplicate entry

3 participants