tsa

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

TSA ASN.1 structures for RFC 3161 Time-Stamp Protocol.

⚠️ ASN.1 FREEZE: This package's ASN.1 structures are frozen. Bug fixes only — no new ASN.1 struct types, no new OIDs. See dev-docs/ASN1_DISCIPLINE.md.

Index

Constants

View Source
const (
	PKIStatusGranted     = 0
	PKIStatusGrantedMods = 1
	PKIStatusRejection   = 2
	PKIStatusWaiting     = 3
)

PKIStatus values (RFC 3161 §2.4.5 / RFC 4210 §5.2.3).

Variables

View Source
var (
	OIDTSTInfo         = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 16, 1, 4}
	OIDDigestSHA256    = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 2, 1}
	OIDDigestSHA384    = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 2, 2}
	OIDDigestSHA512    = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 2, 3}
	OIDEcdsaWithSHA256 = asn1.ObjectIdentifier{1, 2, 840, 10045, 4, 3, 2}
	OIDEcdsaWithSHA384 = asn1.ObjectIdentifier{1, 2, 840, 10045, 4, 3, 3}
	OIDEcdsaWithSHA512 = asn1.ObjectIdentifier{1, 2, 840, 10045, 4, 3, 4}
)
View Source
var OIDTSAPolicyDefault = asn1.ObjectIdentifier{0, 0}

Functions

func BuildErrorResponse

func BuildErrorResponse(status int, msg string) ([]byte, error)

func BuildGrantedResponse

func BuildGrantedResponse(tstInfoDER, contentInfoDER []byte) ([]byte, error)

func BuildTSTInfo

func BuildTSTInfo(req *TimeStampReq, serial int64, cfg *TSTInfoConfig) ([]byte, int, error)

func BuildTimeStampReq

func BuildTimeStampReq(hash crypto.Hash, digest []byte, nonce *big.Int) ([]byte, error)

func ForceRenewSignerCert

func ForceRenewSignerCert(rc *RuntimeConfig, renewCfg *RenewalConfig) error

ForceRenewSignerCert triggers an immediate signer certificate renewal regardless of expiry. Used by the management API (POST /tsa/cert/renew).

func NeedsRenewal

func NeedsRenewal(cert *x509.Certificate, window time.Duration) bool

NeedsRenewal returns true if the certificate expires within the window.

func ParseChainPEM

func ParseChainPEM(pemData string) []*x509.Certificate

ParseChainPEM parses a PEM-encoded certificate chain.

func RotateSignerCert

func RotateSignerCert(rc *RuntimeConfig, renewCfg *RenewalConfig) error

RotateSignerCert issues a brand-new signer certificate with a fresh key pair and atomically swaps it in. Used by the management API (POST /tsa/cert/rotate).

func SerialFromBigInt

func SerialFromBigInt(n *big.Int) int

func SignRequest

func SignRequest(reqDER []byte, cfg *TSAConfig) ([]byte, error)

func SignerRenewLoop

func SignerRenewLoop(rc *RuntimeConfig, renewCfg *RenewalConfig, stopCh <-chan struct{})

SignerRenewLoop periodically checks the TSA signer certificate and renews it via the Varwof Core API before expiry. It atomically swaps the new cert/key into the RuntimeConfig without interrupting service.

The loop stops when stopCh is closed.

Types

type Accuracy

type Accuracy struct {
	Seconds int `asn1:"optional"`
	Millis  int `asn1:"optional,tag:0"`
	Micros  int `asn1:"optional,tag:1"`
}

type AlgorithmIdentifier

type AlgorithmIdentifier struct {
	Algorithm  asn1.ObjectIdentifier
	Parameters asn1.RawValue `asn1:"optional"`
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler serves TSA requests using a RuntimeConfig that supports hot-swapping.

func NewHandler

func NewHandler(cfg *TSAConfig) *Handler

NewHandler creates a Handler backed by the given RuntimeConfig.

func NewHandlerWithRuntime

func NewHandlerWithRuntime(rc *RuntimeConfig) *Handler

NewHandlerWithRuntime creates a Handler backed by an existing RuntimeConfig.

func (*Handler) RuntimeConfig

func (h *Handler) RuntimeConfig() *RuntimeConfig

RuntimeConfig returns the underlying RuntimeConfig for hot-swap operations.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type MessageImprint

type MessageImprint struct {
	HashAlgorithm AlgorithmIdentifier
	HashedMessage []byte
}

type PKIStatusInfo

type PKIStatusInfo struct {
	Status       int
	StatusString []string `asn1:"optional"`
	FailInfo     int      `asn1:"optional"`
}

type RenewalConfig

type RenewalConfig struct {
	// CoreURL is the Varwof Core API base URL (e.g., "https://pki.example.com").
	CoreURL string
	// CertFile is the path to the current signer certificate PEM.
	CertFile string
	// KeyFile is the path to the current signer private key PEM.
	KeyFile string
	// CACertFile is the CA certificate for mTLS to Varwof Core.
	CACertFile string
	// CAName is the CA name to issue from (e.g., "tsa").
	CAName string
	// ValidityDays is the validity period for new certificates.
	ValidityDays int
	// RenewalWindow is how far before expiry to trigger renewal.
	RenewalWindow time.Duration
	// CheckInterval is how often to check for renewal need.
	CheckInterval time.Duration
	// TLSClientCert is the mTLS client certificate for API calls.
	TLSClientCert string
	// TLSClientKey is the mTLS client key for API calls.
	TLSClientKey string
}

RenewalConfig controls the automatic signer certificate renewal loop.

type RuntimeConfig

type RuntimeConfig struct {
	// contains filtered or unexported fields
}

RuntimeConfig holds the TSA signing configuration in a hot-swappable container. The handler reads from the atomic pointer on every request; the renewal loop writes a new config when the signer certificate is renewed.

func NewRuntimeConfig

func NewRuntimeConfig(cfg *TSAConfig) *RuntimeConfig

NewRuntimeConfig creates a RuntimeConfig from an initial TSAConfig.

func (*RuntimeConfig) CertInfo

func (rc *RuntimeConfig) CertInfo() *SignerCertInfo

CertInfo returns metadata about the current signer certificate.

func (*RuntimeConfig) Load

func (rc *RuntimeConfig) Load() *TSAConfig

Load returns the current TSAConfig. Never returns nil after construction.

func (*RuntimeConfig) Store

func (rc *RuntimeConfig) Store(cfg *TSAConfig)

Store atomically replaces the current TSAConfig.

type SignerCertInfo

type SignerCertInfo struct {
	SerialNumber string `json:"serial_number"`
	Subject      string `json:"subject"`
	Issuer       string `json:"issuer"`
	NotBefore    string `json:"not_before"`
	NotAfter     string `json:"not_after"`
	HasChain     bool   `json:"has_chain"`
}

SignerCertInfo returns metadata about the current signer certificate.

type TSAConfig

type TSAConfig struct {
	SignerCert *x509.Certificate
	SignerKey  crypto.Signer
	Chain      []*x509.Certificate
	TSTInfo    *TSTInfoConfig
}

type TSTInfo

type TSTInfo struct {
	Version        int
	Policy         asn1.ObjectIdentifier
	MessageImprint MessageImprint
	SerialNumber   int64
	GenTime        asn1.RawValue
	Accuracy       Accuracy        `asn1:"optional"`
	Ordering       bool            `asn1:"optional,default:false"`
	Nonce          *big.Int        `asn1:"optional"`
	TSA            asn1.RawValue   `asn1:"optional,tag:0"`
	TSTInfoExt     []asn1.RawValue `asn1:"optional,tag:1"`
}

type TSTInfoConfig

type TSTInfoConfig struct {
	Policy          asn1.ObjectIdentifier
	Ordering        bool
	AccuracySeconds int
	AccuracyMillis  int
	AccuracyMicros  int
	TSAGenName      asn1.RawValue
}

type TimeStampReq

type TimeStampReq struct {
	Version        int
	MessageImprint MessageImprint
	ReqPolicy      asn1.ObjectIdentifier `asn1:"optional"`
	Nonce          *big.Int              `asn1:"optional"`
	CertReq        bool                  `asn1:"optional,default:false"`
	Extensions     []asn1.RawValue       `asn1:"optional,tag:0"`
}

func ParseTimeStampReq

func ParseTimeStampReq(reqDER []byte) (*TimeStampReq, error)

type TimeStampResp

type TimeStampResp struct {
	Status         PKIStatusInfo
	TimeStampToken asn1.RawValue `asn1:"optional"`
}

Jump to

Keyboard shortcuts

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