cms

package
v1.118.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package cms builds and reads the CMS SignedData (RFC 5652) that PAdES signatures and RFC 3161 timestamp tokens are made of.

Index

Constants

This section is empty.

Variables

View Source
var (
	OidData                          = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 7, 1}
	OidSignedData                    = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 7, 2}
	OidTstInfo                       = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 16, 1, 4}
	OidAttributeContentType          = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 3}
	OidAttributeMessageDigest        = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 4}
	OidAttributeSigningCertificateV2 = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 16, 2, 47}
	OidAttributeTimeStampToken       = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 16, 2, 14}

	OidSha256 = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 2, 1}
	OidSha384 = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 2, 2}
	OidSha512 = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 2, 3}
)

Functions

func HashFor

func HashFor(algorithm asn1.ObjectIdentifier) (crypto.Hash, error)

HashFor maps a digest algorithm identifier to its hash.

func MarshalSignedData

func MarshalSignedData(contentType asn1.ObjectIdentifier, content []byte, certificates []*x509.Certificate, signerInfos ...*SignerInfo) ([]byte, error)

MarshalSignedData encodes a ContentInfo holding a SignedData; a nil content makes it detached.

Types

type Attribute

type Attribute struct {
	Type   asn1.ObjectIdentifier
	Values []asn1.RawValue `asn1:"set"`
}

Attribute is a CMS attribute: a type and its set of values.

type ParsedSignedData

type ParsedSignedData struct {
	ContentType  asn1.ObjectIdentifier
	Content      []byte
	Certificates []*x509.Certificate
	SignerInfos  []*ParsedSignerInfo
}

ParsedSignedData is a SignedData as read from its ContentInfo.

func ParseSignedData

func ParseSignedData(der []byte) (*ParsedSignedData, error)

ParseSignedData reads a ContentInfo holding a SignedData.

func (*ParsedSignedData) Verify

func (p *ParsedSignedData) Verify(detachedContent []byte) (*x509.Certificate, error)

Verify checks the single signer's signature over its signed attributes and their binding to the content, the encapsulated one or detachedContent, and returns the signer's certificate.

type ParsedSignerInfo

type ParsedSignerInfo struct {
	// IssuerRaw and SerialNumber identify the signer, or SubjectKeyId does.
	IssuerRaw          []byte
	SerialNumber       *big.Int
	SubjectKeyId       []byte
	DigestAlgorithm    asn1.ObjectIdentifier
	SignedAttributes   []*Attribute
	SignatureAlgorithm asn1.ObjectIdentifier
	Signature          []byte
	UnsignedAttributes []*Attribute
	// contains filtered or unexported fields
}

ParsedSignerInfo is a signer info as read from a SignedData.

func (*ParsedSignerInfo) Attribute

func (p *ParsedSignerInfo) Attribute(attributeType asn1.ObjectIdentifier) (asn1.RawValue, bool)

Attribute returns the first value of the signed attribute of the given type.

type SignerInfo

type SignerInfo struct {
	UnsignedAttributes []*Attribute
	// contains filtered or unexported fields
}

SignerInfo is one signer's signed part of a SignedData being built; unsigned attributes may be added until it is marshalled.

func NewSignerInfo

func NewSignerInfo(key crypto.Signer, certificate *x509.Certificate, contentType asn1.ObjectIdentifier, contentDigest []byte) (*SignerInfo, error)

NewSignerInfo signs the content-type, message-digest and signing-certificate-v2 attributes for content of the given type whose SHA-256 digest is contentDigest.

func (*SignerInfo) Signature

func (s *SignerInfo) Signature() []byte

Signature returns the signature value, which is what a signature timestamp covers.

Jump to

Keyboard shortcuts

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