rfc3161

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package rfc3161 implements the bounded Forecast Ledger RFC 3161 profile. Dependency-specific types do not cross this package boundary.

Index

Constants

View Source
const (
	HashAlgorithm    = "sha256"
	MaxTargetBytes   = 1 << 20
	MaxRequestBytes  = 64 << 10
	MaxResponseBytes = 1 << 20
	MaxCABundleBytes = 1 << 20
	MaxCertificates  = 64
	MaxSignerInfos   = 8
	MaxExtensions    = 32
)
View Source
const DefaultHTTPTimeout = 15 * time.Second

Variables

This section is empty.

Functions

func MetadataMatches

func MetadataMatches(metadata Metadata, genTime, policyOID, serialNumber, hashAlgorithm string) error

MetadataMatches compares parsed verified metadata with one ledger entry.

func NormalizeEndpoint

func NormalizeEndpoint(raw string) (string, error)

NormalizeEndpoint performs the no-network part of TSA endpoint validation and returns a stable credential-free URL for path derivation and storage.

func ParseResponse

func ParseResponse(data []byte, limits Limits) error

ParseResponse performs bounded structural and successful-status parsing without claiming signature, trust-chain, request, or target verification.

func ValidateCABundle

func ValidateCABundle(data []byte, limits Limits) error

ValidateCABundle performs bounded PEM and certificate parsing without using system roots or making a network request.

Types

type Error

type Error struct {
	Reason  Reason
	Message string
}

Error deliberately contains no request, response, certificate, target, or credential bytes. The underlying parser error is not exposed to callers.

func (*Error) Error

func (e *Error) Error() string

type HTTPClient

type HTTPClient struct {
	Client   *http.Client
	Resolver Resolver
	Limits   Limits
	Timeout  time.Duration
}

HTTPClient is a constrained one-request TSA client. A custom Client is only an internal test seam; production uses a pinned-address transport built here.

func (HTTPClient) Submit

func (c HTTPClient) Submit(ctx context.Context, endpoint string, request []byte) (SubmitResult, error)

type Limits

type Limits struct {
	TargetBytes   int
	RequestBytes  int
	ResponseBytes int
	CABundleBytes int
	Certificates  int
	SignerInfos   int
	Extensions    int
}

Limits defines application-owned byte and collection limits.

func DefaultLimits

func DefaultLimits() Limits

type Metadata

type Metadata struct {
	HashAlgorithm     string    `json:"hash_algorithm"`
	GenTime           time.Time `json:"gen_time"`
	PolicyOID         string    `json:"policy_oid"`
	SerialNumber      string    `json:"serial_number"`
	SignerSubject     string    `json:"signer_subject"`
	SignerFingerprint string    `json:"signer_fingerprint_sha256"`
	CABundleSHA256    string    `json:"ca_bundle_sha256"`
}

Metadata is the safe verified projection retained in a Forecast Ledger.

func Verify

func Verify(ctx context.Context, target, request, response, caBundle []byte, limits Limits) (Metadata, error)

Verify checks the complete local target/request/response/trust chain.

func (Metadata) String

func (m Metadata) String() string

type Reason

type Reason string

Reason is a stable safe RFC 3161 failure category.

const (
	ReasonLimit             Reason = "rfc3161.limit"
	ReasonRequestMalformed  Reason = "rfc3161.request_malformed"
	ReasonRequestProfile    Reason = "rfc3161.request_profile"
	ReasonTargetMismatch    Reason = "rfc3161.target_mismatch"
	ReasonResponseMalformed Reason = "rfc3161.response_malformed"
	ReasonResponseRejected  Reason = "rfc3161.response_rejected"
	ReasonBindingMismatch   Reason = "rfc3161.binding_mismatch"
	ReasonTokenMalformed    Reason = "rfc3161.token_malformed"
	ReasonAlgorithm         Reason = "rfc3161.algorithm_unsupported"
	ReasonTrustBundle       Reason = "rfc3161.trust_bundle"
	ReasonSignature         Reason = "rfc3161.signature"
	ReasonCertificate       Reason = "rfc3161.certificate"
	ReasonMetadata          Reason = "rfc3161.metadata"
	ReasonEntropy           Reason = "rfc3161.entropy"
)

func SafeReason

func SafeReason(err error) Reason

SafeReason returns the stable reason without exposing parser details.

type RequestInfo

type RequestInfo struct {
	HashAlgorithm string `json:"hash_algorithm"`
	HasNonce      bool   `json:"has_nonce"`
	RequestsCert  bool   `json:"requests_certificate"`
}

RequestInfo is a safe parsed request projection.

func CreateRequest

func CreateRequest(target []byte, entropy io.Reader, limits Limits) ([]byte, RequestInfo, error)

CreateRequest builds the exact supported request profile. Entropy must be a CSPRNG in production and is injectable only below adapters for tests.

func ParseRequest

func ParseRequest(data, target []byte, limits Limits) (RequestInfo, error)

ParseRequest parses and enforces the supported request profile and target binding. It rejects trailing bytes that the dependency API otherwise ignores.

type Resolver

type Resolver interface {
	LookupIPAddr(context.Context, string) ([]net.IPAddr, error)
}

type SubmitResult

type SubmitResult struct {
	Response     []byte `json:"-"`
	RequestCount int    `json:"request_count"`
	TSAOrigin    string `json:"tsa_origin"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL