Skip to content

Package audit/rfc3161 ​

Go module github.com/bide-ai/bide; all packages.

github.com/bide-ai/bide/audit/rfc3161 · pkg.go.dev · Stability: building block, not yet used by approval gates

Package rfc3161 verifies RFC 3161 time-stamp tokens with the standard library alone.

Constants

  • const DefaultMaxTokenBytes = 128 << 10, const DefaultMaxCerts = 10: Default limits, applied when the Policy field is zero.
  • const DefaultMaxAccuracy = time.Second: DefaultMaxAccuracy is the largest TSA-stated accuracy accepted when Policy.MaxAccuracy is zero.

Variables

  • var ErrConfig: ErrConfig is wrapped by the error for a Policy or Expected that cannot be used.
  • var ErrRefused = errors.New("rfc3161: token refused"): ErrRefused is wrapped by every *Refusal, so errors.Is(err, ErrRefused) tells a refused token from a misconfigured call.

Functions

  • func Normalize(token []byte, res *Result) ([]byte, error): Normalize returns token with its certificates field reduced to the certificates of the accepted path that the token carries (res.Chain, in the token's order); every other certificate is stripped.
  • func StatusUnknown(*x509.Certificate, []*x509.Certificate, time.Time) error: StatusUnknown is a Policy.CertStatus that refuses every certificate: the fail-closed choice for a caller that has no status data yet.

type Distrust ​

go
type Distrust struct {
	Cert  *x509.Certificate
	After time.Time
}

Distrust ends belief in a TSA key (or anchor) from a time on.

type Expected ​

go
type Expected struct {
	Hash   crypto.Hash
	Digest []byte

	HeadTime time.Time

	Now time.Time

	Nonce *big.Int
}

Expected is what the caller knows the token must say.

type Policy ​

go
type Policy struct {
	Roots *x509.CertPool

	Intermediates []*x509.Certificate

	CertStatus func(signer *x509.Certificate, chain []*x509.Certificate, at time.Time) error

	RSA2048Until time.Time

	ClockTolerance time.Duration

	MaxAccuracy time.Duration

	AllowESSV1 []*x509.Certificate

	AcceptedPolicies []asn1.ObjectIdentifier

	DistrustAfter []Distrust

	MaxTokenBytes int
	MaxCerts      int
}

Policy is what the auditor decides: which TSAs are trusted and how strictly.

type Reason ​

go
type Reason string

Reason names why a token was refused.

Constants

  • const ReasonTooLarge Reason = "too-large", const ReasonTooDeep Reason = "too-deep", const ReasonTooManyCerts Reason = "too-many-certificates", const ReasonNotDER Reason = "not-der", const ReasonTrailingBytes Reason = "trailing-bytes", const ReasonMalformed Reason = "malformed", const ReasonNotSignedData Reason = "not-signed-data", const ReasonSignedDataVersion Reason = "signed-data-version", const ReasonSignerCount Reason = "signer-count", const ReasonDigestAlgs Reason = "digest-algorithms", const ReasonContentType Reason = "content-type", const ReasonDetached Reason = "detached-content", const ReasonCRLs Reason = "crls-present", const ReasonAttrCerts Reason = "attribute-certificates", const ReasonSignerVersion Reason = "signer-info-version", const ReasonSignerID Reason = "signer-identifier", const ReasonNoSignedAttrs Reason = "no-signed-attributes", const ReasonSignedAttrsOrder Reason = "signed-attributes-not-der-order", const ReasonMissingAttr Reason = "missing-signed-attribute", const ReasonDuplicateAttr Reason = "duplicate-signed-attribute", const ReasonESSV1Only Reason = "signing-certificate-v1-only", const ReasonWeakHash Reason = "weak-hash", const ReasonUnsupportedAlgorithm Reason = "unsupported-algorithm", const ReasonWeakKey Reason = "weak-key", const ReasonTSTVersion Reason = "tstinfo-version", const ReasonCriticalExtension Reason = "tstinfo-critical-extension", const ReasonAccuracy Reason = "accuracy-out-of-range", const ReasonGenTimeFormat Reason = "gentime-format", const ReasonAttrContentType Reason = "content-type-attribute-mismatch", const ReasonMessageDigest Reason = "message-digest-mismatch", const ReasonESSMismatch Reason = "signing-certificate-mismatch", const ReasonSignerCertNotFound Reason = "signer-certificate-not-found", const ReasonBadSignature Reason = "bad-signature", const ReasonImprintMismatch Reason = "imprint-mismatch", const ReasonGenTimeBeforeHead Reason = "gentime-before-head", const ReasonNonceMismatch Reason = "nonce-mismatch", const ReasonNoTrustAnchors Reason = "no-trust-anchors", const ReasonUntrustedTSA Reason = "untrusted-tsa", const ReasonTSACertExpired Reason = "tsa-certificate-expired", const ReasonTSAEKU Reason = "tsa-extended-key-usage", const ReasonTSAStatus Reason = "tsa-certificate-status", const ReasonTSAName Reason = "tsa-name-mismatch", const ReasonTSAKeyUsage Reason = "tsa-key-usage", const ReasonTSADistrusted Reason = "tsa-distrusted", const ReasonPolicy Reason = "policy-not-accepted", const ReasonGenTimeFuture Reason = "gentime-in-future": The refusal reasons.

Methods

  • func (r Reason) OutsideProfile() bool: OutsideProfile reports whether r names a construct the verifier does not interpret, as opposed to a check the token failed.

type Refusal ​

go
type Refusal struct {
	Reason Reason
	Detail string
	// contains filtered or unexported fields
}

Refusal is the error for a token the verifier refused.

Methods

  • func (r *Refusal) Error() string: Error implements error.
  • func (r *Refusal) Is(target error) bool: Is reports a match with ErrRefused.
  • func (r *Refusal) Unwrap() error: Unwrap returns the underlying error, when there is one (a status-hook error, for example).

type Result ​

go
type Result struct {
	GenTime  time.Time
	Accuracy time.Duration

	Hash      crypto.Hash
	Imprint   []byte
	PolicyOID string
	Serial    *big.Int

	Signer *x509.Certificate
	Chain  []*x509.Certificate

	ESSV1 bool
}

Result is what a verified token attests.

Constructors and functions

  • func Verify(token []byte, exp Expected, pol Policy) (*Result, error): Verify checks token against exp and pol and returns what it attests.

Methods

  • func (r *Result) Latest() time.Time: Latest is the latest the token allows for the moment it was issued: GenTime plus Accuracy.

Apache-2.0 licensed.