Documentation
¶
Index ¶
- Constants
- Variables
- func AddCAdESTimestamp(pkcs7DER []byte, tstTokenDER []byte) ([]byte, error)
- func BuildSignedData(eContentType asn1.ObjectIdentifier, eContent []byte, cert *x509.Certificate, ...) ([]byte, error)
- func BuildSignedDataWithDigest(eContentType asn1.ObjectIdentifier, eContent, digest []byte, ...) ([]byte, error)
- func BuildSignedDataWithHash(eContentType asn1.ObjectIdentifier, eContent []byte, cert *x509.Certificate, ...) ([]byte, error)
- func BuildSignedDataWithoutCertificates(eContentType asn1.ObjectIdentifier, eContent []byte, cert *x509.Certificate, ...) ([]byte, error)
- func HasCAdESUnsigned(pkcs7DER []byte) bool
- func SelectHash(cert *x509.Certificate) crypto.Hash
- func SignatureValue(pkcs7DER []byte) ([]byte, error)
- func VerifyDetached(der []byte, content []byte) (*x509.Certificate, error)
- type AlgorithmIdentifier
- type Attribute
- type ContentInfo
- type EncapsulatedContentInfo
- type IssuerAndSerial
- type SignedData
- type SignerInfo
Constants ¶
const Version = "0.1.1"
Version is the current pkcs7 library version.
Variables ¶
var ( OIDSignedData = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 7, 2} OIDData = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 7, 1} 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} 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} OIDRSAWithSHA256 = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 1, 11} OIDRSAWithSHA384 = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 1, 12} OIDRSAWithSHA512 = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 1, 13} OIDEd25519 = asn1.ObjectIdentifier{1, 3, 101, 112} )
Content type and signature algorithm OIDs (RFC 5652 / RFC 5754).
var OIDSignatureTimeStamp = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 16, 2, 14}
OIDSignatureTimeStamp is the attribute type for CAdES signature timestamps (RFC 5126).
Functions ¶
func AddCAdESTimestamp ¶
AddCAdESTimestamp appends a CAdES signature timestamp (RFC 5126) to a PKCS#7 SignedData.
func BuildSignedData ¶
func BuildSignedData(eContentType asn1.ObjectIdentifier, eContent []byte, cert *x509.Certificate, signer crypto.Signer, chain []*x509.Certificate) ([]byte, error)
BuildSignedData builds a PKCS#7 SignedData with signing certificate attributes.
func BuildSignedDataWithDigest ¶
func BuildSignedDataWithDigest(eContentType asn1.ObjectIdentifier, eContent, digest []byte, cert *x509.Certificate, signer crypto.Signer, chain []*x509.Certificate, hash crypto.Hash) ([]byte, error)
BuildSignedDataWithDigest builds a PKCS#7 SignedData using a precomputed digest. Unlike BuildSignedDataWithHash which hashes eContent internally, this function uses the provided digest directly for the messageDigest attribute. If eContent is nil, the EncapContentInfo.Content is omitted (detached signature).
func BuildSignedDataWithHash ¶
func BuildSignedDataWithHash(eContentType asn1.ObjectIdentifier, eContent []byte, cert *x509.Certificate, signer crypto.Signer, chain []*x509.Certificate, hash crypto.Hash) ([]byte, error)
BuildSignedDataWithHash builds a PKCS#7 SignedData using the specified hash algorithm.
func BuildSignedDataWithoutCertificates ¶ added in v0.1.1
func BuildSignedDataWithoutCertificates(eContentType asn1.ObjectIdentifier, eContent []byte, cert *x509.Certificate, signer crypto.Signer, chain []*x509.Certificate) ([]byte, error)
BuildSignedDataWithoutCertificates is like BuildSignedData but omits the signing certificate (and any chain certificates) from SignedData.certificates. RFC 3161 §2.4.1: a TimeStampReq whose certReq flag is FALSE (the default) MUST result in a TimeStampToken whose SignedData.certificates field is empty. The ESSCertID signing attribute still carries the certificate hash so a verifier can identify the signer.
func HasCAdESUnsigned ¶
HasCAdESUnsigned reports whether any SignerInfo has unsigned attributes.
func SelectHash ¶
func SelectHash(cert *x509.Certificate) crypto.Hash
SelectHash selects the signature hash algorithm based on the certificate's public key type.
func SignatureValue ¶
SignatureValue extracts the first signature value from a PKCS#7 SignedData.
func VerifyDetached ¶
func VerifyDetached(der []byte, content []byte) (*x509.Certificate, error)
Types ¶
type AlgorithmIdentifier ¶
type AlgorithmIdentifier struct {
Algorithm asn1.ObjectIdentifier
Parameters asn1.RawValue `asn1:"optional"`
}
AlgorithmIdentifier is the signature/digest algorithm identifier (RFC 5652 §10.1).
type Attribute ¶
type Attribute struct {
Type asn1.ObjectIdentifier
Values []asn1.RawValue `asn1:"set"`
}
Attribute is the CMS attribute structure (RFC 5652 §5.3).
type ContentInfo ¶
type ContentInfo struct {
ContentType asn1.ObjectIdentifier
Content asn1.RawValue `asn1:"explicit,tag:0"`
}
ContentInfo is the CMS SignedData content information wrapper (RFC 5652 §5.2).
type EncapsulatedContentInfo ¶
type EncapsulatedContentInfo struct {
ContentType asn1.ObjectIdentifier
Content asn1.RawValue `asn1:"optional"`
}
EncapsulatedContentInfo is the signed content encapsulated within SignedData (RFC 5652 §5.2).
type IssuerAndSerial ¶
IssuerAndSerial identifies the signer certificate by issuer and serial number (RFC 5652 §5.3).
type SignedData ¶
type SignedData struct {
Version int
DigestAlgorithms []AlgorithmIdentifier `asn1:"set"`
EncapContentInfo EncapsulatedContentInfo
Certificates []asn1.RawValue `asn1:"optional,implicit,tag:0"`
SignerInfos []SignerInfo `asn1:"set"`
}
SignedData is the CMS SignedData structure (RFC 5652 §5.1).
type SignerInfo ¶
type SignerInfo struct {
Version int
IssuerAndSerial IssuerAndSerial
DigestAlgorithm AlgorithmIdentifier
SignedAttributes []Attribute `asn1:"optional,implicit,tag:0"`
SignatureAlgorithm AlgorithmIdentifier
Signature []byte
UnsignedAttributes []Attribute `asn1:"optional,implicit,tag:1"`
}
SignerInfo is the information for a single signer (RFC 5652 §5.3).