Documentation ¶
Index ¶
- Variables
- func AddKeySign(oid asn1.ObjectIdentifier, keySign func() KeySign)
- func AddSignHash(oid asn1.ObjectIdentifier, signHash func() SignHash)
- func DegenerateCertificate(cert []byte) ([]byte, error)
- type Attribute
- type KeySign
- type KeySignWithDSA
- func (this KeySignWithDSA) HashOID() asn1.ObjectIdentifier
- func (this KeySignWithDSA) OID() asn1.ObjectIdentifier
- func (this KeySignWithDSA) Sign(pkey crypto.PrivateKey, data []byte) ([]byte, []byte, error)
- func (this KeySignWithDSA) Verify(pkey crypto.PublicKey, signed []byte, signature []byte) (bool, error)
- type KeySignWithEcdsa
- func (this KeySignWithEcdsa) HashOID() asn1.ObjectIdentifier
- func (this KeySignWithEcdsa) OID() asn1.ObjectIdentifier
- func (this KeySignWithEcdsa) Sign(pkey crypto.PrivateKey, data []byte) ([]byte, []byte, error)
- func (this KeySignWithEcdsa) Verify(pkey crypto.PublicKey, signed []byte, signature []byte) (bool, error)
- type KeySignWithEdDsa
- func (this KeySignWithEdDsa) HashOID() asn1.ObjectIdentifier
- func (this KeySignWithEdDsa) OID() asn1.ObjectIdentifier
- func (this KeySignWithEdDsa) Sign(pkey crypto.PrivateKey, data []byte) ([]byte, []byte, error)
- func (this KeySignWithEdDsa) Verify(pkey crypto.PublicKey, signed []byte, signature []byte) (bool, error)
- type KeySignWithRsa
- func (this KeySignWithRsa) HashOID() asn1.ObjectIdentifier
- func (this KeySignWithRsa) OID() asn1.ObjectIdentifier
- func (this KeySignWithRsa) Sign(pkey crypto.PrivateKey, data []byte) ([]byte, []byte, error)
- func (this KeySignWithRsa) Verify(pkey crypto.PublicKey, data []byte, signature []byte) (bool, error)
- type KeySignWithSM2
- func (this KeySignWithSM2) HashOID() asn1.ObjectIdentifier
- func (this KeySignWithSM2) OID() asn1.ObjectIdentifier
- func (this KeySignWithSM2) Sign(pkey crypto.PrivateKey, data []byte) ([]byte, []byte, error)
- func (this KeySignWithSM2) Verify(pkey crypto.PublicKey, signed []byte, signature []byte) (bool, error)
- type MessageDigestMismatchError
- type PKCS7
- func (this *PKCS7) GetOnlySigner() *x509.Certificate
- func (this *PKCS7) UnmarshalSignedAttribute(attributeType asn1.ObjectIdentifier, out interface{}) error
- func (this *PKCS7) Verify() (err error)
- func (this *PKCS7) VerifyWithChain(truststore *x509.CertPool) (err error)
- func (this *PKCS7) VerifyWithChainAtTime(truststore *x509.CertPool, currentTime time.Time) (err error)
- type SignHash
- type SignHashWithFunc
- type SignedData
- func (this *SignedData) AddCertificate(cert *x509.Certificate)
- func (this *SignedData) AddSigner(ee *x509.Certificate, pkey crypto.PrivateKey, config SignerInfoConfig) error
- func (this *SignedData) AddSignerChain(ee *x509.Certificate, pkey crypto.PrivateKey, parents []*x509.Certificate, ...) error
- func (this *SignedData) Detach()
- func (this *SignedData) Finish() ([]byte, error)
- func (this *SignedData) GetSignedData() *signedData
- func (this *SignedData) RemoveAuthenticatedAttributes()
- func (this *SignedData) RemoveUnauthenticatedAttributes()
- func (this *SignedData) SetContentType(contentType asn1.ObjectIdentifier)
- func (this *SignedData) SetDigestAlgorithm(d asn1.ObjectIdentifier)
- func (this *SignedData) SetEncryptionAlgorithm(d asn1.ObjectIdentifier)
- func (this *SignedData) SignWithoutAttr(ee *x509.Certificate, pkey crypto.PrivateKey, config SignerInfoConfig) error
- type SignerInfoConfig
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupportedContentType = errors.New("pkcs7: cannot parse data: unimplemented content type")
ErrUnsupportedContentType is returned when a PKCS7 content is not supported. Currently only Data (1.2.840.113549.1.7.1), Signed Data (1.2.840.113549.1.7.2), and Enveloped Data are supported (1.2.840.113549.1.7.3)
var KeySignWithDSASHA1 = KeySignWithDSA{ // contains filtered or unexported fields }
var KeySignWithDSASHA224 = KeySignWithDSA{ // contains filtered or unexported fields }
var KeySignWithDSASHA256 = KeySignWithDSA{ // contains filtered or unexported fields }
var KeySignWithEcdsaSHA1 = KeySignWithEcdsa{ // contains filtered or unexported fields }
var KeySignWithEcdsaSHA224 = KeySignWithEcdsa{ // contains filtered or unexported fields }
var KeySignWithEcdsaSHA256 = KeySignWithEcdsa{ // contains filtered or unexported fields }
var KeySignWithEcdsaSHA384 = KeySignWithEcdsa{ // contains filtered or unexported fields }
var KeySignWithEcdsaSHA512 = KeySignWithEcdsa{ // contains filtered or unexported fields }
var KeySignWithEdDsaSHA1 = KeySignWithRsa{ // contains filtered or unexported fields }
var KeySignWithRsaMD5 = KeySignWithRsa{ // contains filtered or unexported fields }
var KeySignWithRsaSHA1 = KeySignWithRsa{ // contains filtered or unexported fields }
var KeySignWithRsaSHA224 = KeySignWithRsa{ // contains filtered or unexported fields }
var KeySignWithRsaSHA256 = KeySignWithRsa{ // contains filtered or unexported fields }
var KeySignWithRsaSHA384 = KeySignWithRsa{ // contains filtered or unexported fields }
var KeySignWithRsaSHA512 = KeySignWithRsa{ // contains filtered or unexported fields }
var KeySignWithSM2SM3 = KeySignWithSM2{ // contains filtered or unexported fields }
var SignHashWithSHA1 = SignHashWithFunc{ // contains filtered or unexported fields }
各种 hash
var SignHashWithSHA224 = SignHashWithFunc{ // contains filtered or unexported fields }
var SignHashWithSHA256 = SignHashWithFunc{ // contains filtered or unexported fields }
var SignHashWithSHA384 = SignHashWithFunc{ // contains filtered or unexported fields }
var SignHashWithSHA512 = SignHashWithFunc{ // contains filtered or unexported fields }
var SignHashWithSM3 = SignHashWithFunc{ // contains filtered or unexported fields }
Functions ¶
func DegenerateCertificate ¶
DegenerateCertificate creates a signed data structure containing only the provided certificate or certificate chain.
Types ¶
type Attribute ¶
type Attribute struct { Type asn1.ObjectIdentifier Value interface{} }
Attribute represents a key value pair attribute. Value must be marshalable byte `encoding/asn1`
type KeySign ¶
type KeySign interface { // oid OID() asn1.ObjectIdentifier // HashOID HashOID() asn1.ObjectIdentifier // 签名 Sign(pkey crypto.PrivateKey, data []byte) (hashData []byte, signData []byte, err error) // 解密 Verify(pkey crypto.PublicKey, signed []byte, signature []byte) (bool, error) }
签名接口
type KeySignWithDSA ¶
type KeySignWithDSA struct {
// contains filtered or unexported fields
}
rsa 签名
func (KeySignWithDSA) Sign ¶
func (this KeySignWithDSA) Sign(pkey crypto.PrivateKey, data []byte) ([]byte, []byte, error)
签名
type KeySignWithEcdsa ¶
type KeySignWithEcdsa struct {
// contains filtered or unexported fields
}
ecdsa 签名
func (KeySignWithEcdsa) Sign ¶
func (this KeySignWithEcdsa) Sign(pkey crypto.PrivateKey, data []byte) ([]byte, []byte, error)
签名
type KeySignWithEdDsa ¶
type KeySignWithEdDsa struct {
// contains filtered or unexported fields
}
EdDsa 签名
func (KeySignWithEdDsa) Sign ¶
func (this KeySignWithEdDsa) Sign(pkey crypto.PrivateKey, data []byte) ([]byte, []byte, error)
签名
type KeySignWithRsa ¶
type KeySignWithRsa struct {
// contains filtered or unexported fields
}
rsa 签名
func (KeySignWithRsa) Sign ¶
func (this KeySignWithRsa) Sign(pkey crypto.PrivateKey, data []byte) ([]byte, []byte, error)
签名
type KeySignWithSM2 ¶
type KeySignWithSM2 struct {
// contains filtered or unexported fields
}
sm2 签名
func (KeySignWithSM2) Sign ¶
func (this KeySignWithSM2) Sign(pkey crypto.PrivateKey, data []byte) ([]byte, []byte, error)
签名
type MessageDigestMismatchError ¶
MessageDigestMismatchError is returned when the signer data digest does not match the computed digest for the contained content
func (*MessageDigestMismatchError) Error ¶
func (err *MessageDigestMismatchError) Error() string
type PKCS7 ¶
type PKCS7 struct { Content []byte Certificates []*x509.Certificate CRLs []pkix.CertificateList Signers []signerInfo // contains filtered or unexported fields }
PKCS7 Represents a PKCS7 structure
func (*PKCS7) GetOnlySigner ¶
func (this *PKCS7) GetOnlySigner() *x509.Certificate
GetOnlySigner returns an x509.Certificate for the first signer of the signed data payload. If there are more or less than one signer, nil is returned
func (*PKCS7) UnmarshalSignedAttribute ¶
func (this *PKCS7) UnmarshalSignedAttribute(attributeType asn1.ObjectIdentifier, out interface{}) error
UnmarshalSignedAttribute decodes a single attribute from the signer info
func (*PKCS7) Verify ¶
Verify is a wrapper around VerifyWithChain() that initializes an empty trust store, effectively disabling certificate verification when validating a signature.
func (*PKCS7) VerifyWithChain ¶
VerifyWithChain checks the signatures of a PKCS7 object.
If truststore is not nil, it also verifies the chain of trust of the end-entity signer cert to one of the roots in the truststore. When the PKCS7 object includes the signing time authenticated attr verifies the chain at that time and UTC now otherwise.
func (*PKCS7) VerifyWithChainAtTime ¶
func (this *PKCS7) VerifyWithChainAtTime(truststore *x509.CertPool, currentTime time.Time) (err error)
VerifyWithChainAtTime checks the signatures of a PKCS7 object.
If truststore is not nil, it also verifies the chain of trust of the end-entity signer cert to a root in the truststore at currentTime. It does not use the signing time authenticated attribute.
type SignHash ¶
type SignHash interface { // oid OID() asn1.ObjectIdentifier // 加密 Sum(data []byte) []byte }
hash 接口
type SignHashWithFunc ¶
type SignHashWithFunc struct {
// contains filtered or unexported fields
}
hash
type SignedData ¶
type SignedData struct {
// contains filtered or unexported fields
}
SignedData is an opaque data structure for creating signed data payloads
func NewSignedData ¶
func NewSignedData(data []byte) (*SignedData, error)
NewSignedData takes data and initializes a PKCS7 SignedData struct that is ready to be signed via AddSigner. The digest algorithm is set to SHA1 by default and can be changed by calling SetDigestAlgorithm.
func (*SignedData) AddCertificate ¶
func (this *SignedData) AddCertificate(cert *x509.Certificate)
AddCertificate adds the certificate to the payload. Useful for parent certificates
func (*SignedData) AddSigner ¶
func (this *SignedData) AddSigner(ee *x509.Certificate, pkey crypto.PrivateKey, config SignerInfoConfig) error
AddSigner is a wrapper around AddSignerChain() that adds a signer without any parent.
func (*SignedData) AddSignerChain ¶
func (this *SignedData) AddSignerChain(ee *x509.Certificate, pkey crypto.PrivateKey, parents []*x509.Certificate, config SignerInfoConfig) error
AddSignerChain signs attributes about the content and adds certificates and signers infos to the Signed Data. The certificate and private key of the end-entity signer are used to issue the signature, and any parent of that end-entity that need to be added to the list of certifications can be specified in the parents slice.
The signature algorithm used to hash the data is the one of the end-entity certificate.
func (*SignedData) Detach ¶
func (this *SignedData) Detach()
Detach removes content from the signed data struct to make it a detached signature. This must be called right before Finish()
func (*SignedData) Finish ¶
func (this *SignedData) Finish() ([]byte, error)
Finish marshals the content and its signers
func (*SignedData) GetSignedData ¶
func (this *SignedData) GetSignedData() *signedData
GetSignedData returns the private Signed Data
func (*SignedData) RemoveAuthenticatedAttributes ¶
func (this *SignedData) RemoveAuthenticatedAttributes()
RemoveAuthenticatedAttributes removes authenticated attributes from signedData similar to OpenSSL's PKCS7_NOATTR or -noattr flags
func (*SignedData) RemoveUnauthenticatedAttributes ¶
func (this *SignedData) RemoveUnauthenticatedAttributes()
RemoveUnauthenticatedAttributes removes unauthenticated attributes from signedData
func (*SignedData) SetContentType ¶
func (this *SignedData) SetContentType(contentType asn1.ObjectIdentifier)
SetContentType sets the content type of the SignedData. For example to specify the content type of a time-stamp token according to RFC 3161 section 2.4.2.
func (*SignedData) SetDigestAlgorithm ¶
func (this *SignedData) SetDigestAlgorithm(d asn1.ObjectIdentifier)
SetDigestAlgorithm sets the digest algorithm to be used in the signing process.
This should be called before adding signers
func (*SignedData) SetEncryptionAlgorithm ¶
func (this *SignedData) SetEncryptionAlgorithm(d asn1.ObjectIdentifier)
SetEncryptionAlgorithm sets the encryption algorithm to be used in the signing process.
This should be called before adding signers
func (*SignedData) SignWithoutAttr ¶
func (this *SignedData) SignWithoutAttr(ee *x509.Certificate, pkey crypto.PrivateKey, config SignerInfoConfig) error
SignWithoutAttr issues a signature on the content of the pkcs7 SignedData. Unlike AddSigner/AddSignerChain, it calculates the digest on the data alone and does not include any signed attributes like timestamp and so on.
This function is needed to sign old Android APKs, something you probably shouldn't do unless you're maintaining backward compatibility for old applications.
type SignerInfoConfig ¶
type SignerInfoConfig struct { ExtraSignedAttributes []Attribute ExtraUnsignedAttributes []Attribute }
SignerInfoConfig are optional values to include when adding a signer