Skip to content

crypto/x509: document duplicate handling in CertPool.AddCertWithConstraint #81500

Open

Description

@filippo-agent

The documentation for CertPool.AddCertWithConstraint should clarify that adding a certificate already present in the pool is a no-op, including for its constraint. The first insertion determines the stored constraint: a later addition neither attaches a constraint to an unconstrained entry nor replaces or combines existing constraints.

pool.AddCert(ca)
pool.AddCertWithConstraint(ca, rejectingConstraint) // no-op; ca remains unconstrained
Details

The shared insertion helper in src/crypto/x509/cert_pool.go checks s.haveSum[rawSum224] and returns before storing the supplied constraint. Deduplication is by certificate DER hash, not merely subject or public key. Both AddCert and AppendCertsFromPEM insert entries with nil constraints.

When verifying a chain, findPotentialParents retrieves the stored constraint, so buildChains has no callback to invoke for an unconstrained root even if a later duplicate addition supplied one. An otherwise valid chain rooted there remains eligible.

The method documentation describes callback evaluation but not duplicate handling.

This issue was found by zkao and was triaged by @FiloSottile as intended behavior but an opportunity to improve documentation. /cc @golang/security

Activity

  1. gopherbot commented on Sep 14, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/832564 mentions this issue: crypto/x509: document CertPool duplicate AddCert handling

  2. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Sep 18, 2026
  3. added this to the Backlog milestone on Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions