mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-07 12:21:31 +00:00
21aeed4f4e
Phase 0 closure (Path B2, post-rewrite):
addlicense sweep — adds the canonical certctl LLC copyright + BUSL-1.1
SPDX header to every production Go file. Template:
// Copyright 2026 certctl LLC. All rights reserved.
// SPDX-License-Identifier: BUSL-1.1
Coverage: 338 / 338 production Go files (cmd/ + internal/, excluding
*_test.go and **/testdata/**). Pre-sweep coverage was 22 / 338 (6.5%);
post-sweep is 338 / 338 (100%).
Normalized 22 pre-existing legacy headers (`// Copyright (c) certctl`
+ `// SPDX-License-Identifier: BSL-1.1`) and 1 file using a
`Certctl Contributors` attribution. The legacy SPDX ID `BSL-1.1`
is non-standard; the official SPDX identifier for Business Source
License 1.1 is `BUSL-1.1` (capital U). All 338 files now share the
canonical form.
Generated via:
addlicense -c "certctl LLC" -y 2026 \
-f cowork/legal/copyright-header.tpl \
-ignore '**/testdata/**' -ignore '**/*_test.go' \
cmd/ internal/
Verification:
find cmd internal -name '*.go' -not -name '*_test.go' \
-not -path '*/testdata/*' \
-exec grep -L '^// Copyright 2026 certctl LLC' {} \; | wc -l
Returns: 0
gofmt clean. Header additions are comments only, no compile impact.
Closes: cowork/certctl-architecture-diligence-audit.html#fix-RED-4
48 lines
1.7 KiB
Go
48 lines
1.7 KiB
Go
// Copyright 2026 certctl LLC. All rights reserved.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package acme
|
|
|
|
import (
|
|
"context"
|
|
"crypto/rand"
|
|
"encoding/base64"
|
|
"time"
|
|
)
|
|
|
|
// NonceStore is the persistence-layer contract for ACME nonces. The
|
|
// production implementation lives at internal/repository/postgres/acme.go
|
|
// and is DB-backed (NOT in-memory) — replay protection requires the
|
|
// store to outlast the client's nonce caching window.
|
|
//
|
|
// Issue creates a new nonce and stores it with a TTL. The string return
|
|
// is what the handler echoes in the Replay-Nonce response header.
|
|
//
|
|
// Consume marks a nonce used and returns an error if the nonce is
|
|
// missing, already used, or expired. The handler maps that error to
|
|
// urn:ietf:params:acme:error:badNonce per RFC 8555 §6.5.1.
|
|
//
|
|
// Phase 1a: Issue is wired (every directory + new-nonce response carries
|
|
// a Replay-Nonce header). Consume is exposed but not yet invoked —
|
|
// JWS-authenticated POSTs (which consume nonces) arrive in Phase 1b.
|
|
type NonceStore interface {
|
|
Issue(ctx context.Context, ttl time.Duration) (string, error)
|
|
Consume(ctx context.Context, nonce string) error
|
|
}
|
|
|
|
// nonceByteLen is 32 bytes (256 bits) of entropy. RFC 8555 §6.5.1 only
|
|
// requires nonces to be hard-to-guess; 256 bits is overkill on purpose
|
|
// (matches the consumer-side ACME library + every other ACME server).
|
|
const nonceByteLen = 32
|
|
|
|
// GenerateNonce returns 32 cryptographically-random bytes encoded as
|
|
// base64url-no-padding per RFC 7515 §2 (the encoding ACME wire format
|
|
// uses for the protected-header nonce field).
|
|
func GenerateNonce() (string, error) {
|
|
b := make([]byte, nonceByteLen)
|
|
if _, err := rand.Read(b); err != nil {
|
|
return "", err
|
|
}
|
|
return base64.RawURLEncoding.EncodeToString(b), nil
|
|
}
|