timestamp

package
v0.0.0-...-4516b99 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MIT, MIT Imports: 15 Imported by: 1

Documentation

Overview

Package timestamp implements the timestamp protocol rfc 3161

Index

Constants

This section is empty.

Variables

View Source
var (
	//Opts are options for timestamp certificate verficiation.
	Opts = x509.VerifyOptions{
		Intermediates: x509.NewCertPool(),
		CurrentTime:   time.Now(),
		KeyUsages:     []x509.ExtKeyUsage{x509.ExtKeyUsageTimeStamping},
	}
)

Functions

func FetchTSToken

func FetchTSToken(url string, msg []byte, hash crypto.Hash) (tsToken cms.ContentInfo, err error)

FetchTSToken tries to fetch a TSTokem of the given msg with hash using the given URL.

func GenerateNonce

func GenerateNonce() *big.Int

GenerateNonce generates a new nonce for this TSR.

Types

type Accuracy

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

Accuracy of the timestamp

func (Accuracy) Duration

func (a Accuracy) Duration() time.Duration

Duration returns this Accuracy as a time.Duration.

type MessageImprint

type MessageImprint struct {
	HashAlgorithm pkix.AlgorithmIdentifier
	HashedMessage []byte
}
MessageImprint ::= SEQUENCE  {
	hashAlgorithm                AlgorithmIdentifier,
	hashedMessage                OCTET STRING  }

func NewMessageImprint

func NewMessageImprint(hash crypto.Hash, msg []byte) (MessageImprint, error)

NewMessageImprint creates a new MessageImprint, digesting msg using the specified hash.

type PKIFreeText

type PKIFreeText []asn1.RawValue

PKIFreeText ::= SEQUENCE SIZE (1..MAX) OF UTF8String

func (PKIFreeText) Append

func (ft PKIFreeText) Append(t string) PKIFreeText

Append returns a new copy of the PKIFreeText with the provided string appended.

func (PKIFreeText) Strings

func (ft PKIFreeText) Strings() ([]string, error)

Strings decodes the PKIFreeText into a []string.

type PKIStatusInfo

type PKIStatusInfo struct {
	Status       int
	StatusString PKIFreeText    `asn1:"optional"`
	FailInfo     asn1.BitString `asn1:"optional"`
}
PKIStatusInfo ::= SEQUENCE {
   status        PKIStatus,
   statusString  PKIFreeText     OPTIONAL,
   failInfo      PKIFailureInfo  OPTIONAL  }

func (PKIStatusInfo) Error

func (si PKIStatusInfo) Error() string

Error implements the error interface.

func (PKIStatusInfo) GetError

func (si PKIStatusInfo) GetError() error

GetError represents an unsuccessful PKIStatusInfo as an error.

type TSTInfo

type TSTInfo struct {
	Version        int
	Policy         asn1.ObjectIdentifier
	MessageImprint MessageImprint
	SerialNumber   *big.Int
	GenTime        time.Time        `asn1:"generalized"`
	Accuracy       Accuracy         `asn1:"optional"`
	Ordering       bool             `asn1:"optional,default:false"`
	Nonce          *big.Int         `asn1:"optional"`
	TSA            asn1.RawValue    `asn1:"tag:0,optional"`
	Extensions     []pkix.Extension `asn1:"tag:1,optional"`
}
TSTInfo ::= SEQUENCE  {
   version                      INTEGER  { v1(1) },
   policy                       TSAPolicyId,
   messageImprint               MessageImprint,
     -- MUST have the same value as the similar field in
     -- TimeStampReq
   serialNumber                 INTEGER,
    -- Time-Stamping users MUST be ready to accommodate integers
    -- up to 160 bits.
   genTime                      GeneralizedTime,
   accuracy                     Accuracy                 OPTIONAL,
   ordering                     BOOLEAN             DEFAULT FALSE,
   nonce                        INTEGER                  OPTIONAL,
     -- MUST be present if the similar field was present
     -- in TimeStampReq.  In that case it MUST have the same value.
   tsa                          [0] GeneralName          OPTIONAL,
   extensions                   [1] IMPLICIT Extensions  OPTIONAL   }

func ParseInfo

func ParseInfo(enci cms.EncapsulatedContentInfo) (TSTInfo, error)

ParseInfo parses an Info out of a CMS EncapsulatedContentInfo.

func VerfiyTS

func VerfiyTS(ci cms.ContentInfo) (info TSTInfo, err error)

VerfiyTS verfies the given TSToken and returns the TSTInfo.

func (*TSTInfo) After

func (i *TSTInfo) After(t time.Time) bool

After checks if the earlier time the signature could have been generated at is before the specified time. For example, you might check that a signature was made *after* a certificate's not-before date.

func (*TSTInfo) Before

func (i *TSTInfo) Before(t time.Time) bool

Before checks if the latest time the signature could have been generated at is before the specified time. For example, you might check that a signature was made *before* a certificate's not-after date.

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     []pkix.Extension      `asn1:"tag:1,optional"`
}
TimeStampReq ::= SEQUENCE  {
	version                  INTEGER  { v1(1) },
	messageImprint           MessageImprint,
	  --a hash algorithm OID and the hash value of the data to be
	  --time-stamped
	reqPolicy                TSAPolicyId                OPTIONAL,
	nonce                    INTEGER                    OPTIONAL,
	certReq                  BOOLEAN                    DEFAULT FALSE,
	extensions               [0] IMPLICIT Extensions    OPTIONAL  }

func (TimeStampReq) Do

func (req TimeStampReq) Do(url string) (TimeStampResp, error)

Do sends this timestamp request to the specified timestamp service, returning the parsed response.

type TimeStampResp

type TimeStampResp struct {
	Status         PKIStatusInfo
	TimeStampToken cms.ContentInfo `asn1:"optional"`
}
TimeStampResp ::= SEQUENCE  {
	status                  PKIStatusInfo,
	timeStampToken          TimeStampToken     OPTIONAL  }

func ParseResponse

func ParseResponse(der []byte) (TimeStampResp, error)

ParseResponse parses a ASN.1 encoded TimeStampResp.

func (TimeStampResp) Info

func (r TimeStampResp) Info() (TSTInfo, error)

Info returns the timestampinfo from a response.

Jump to

Keyboard shortcuts

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