mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-27 20:56:18 +08:00
pkcs7: reduce duplicated and useless code
This commit is contained in:
parent
652e6da354
commit
a93f7fd94d
@ -185,14 +185,6 @@ func (sd *SignedData) AddSignerChain(ee *smx509.Certificate, pkey crypto.Private
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
unsignedAttrs := &attributes{}
|
||||
for _, attr := range config.ExtraUnsignedAttributes {
|
||||
unsignedAttrs.Add(attr.Type, attr.Value)
|
||||
}
|
||||
finalUnsignedAttrs, err := unsignedAttrs.ForMarshalling()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// create signature of signed attributes
|
||||
signature, err := signAttributes(finalAttrs, pkey, hasher)
|
||||
if err != nil {
|
||||
@ -200,13 +192,16 @@ func (sd *SignedData) AddSignerChain(ee *smx509.Certificate, pkey crypto.Private
|
||||
}
|
||||
signer := signerInfo{
|
||||
AuthenticatedAttributes: finalAttrs,
|
||||
UnauthenticatedAttributes: finalUnsignedAttrs,
|
||||
DigestAlgorithm: pkix.AlgorithmIdentifier{Algorithm: sd.digestOid},
|
||||
DigestEncryptionAlgorithm: pkix.AlgorithmIdentifier{Algorithm: encryptionOid},
|
||||
IssuerAndSerialNumber: ias,
|
||||
EncryptedDigest: signature,
|
||||
Version: 1,
|
||||
}
|
||||
if err = signer.SetUnauthenticatedAttributes(config.ExtraUnsignedAttributes); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !config.SkipCertificates {
|
||||
sd.certs = append(sd.certs, ee)
|
||||
if len(parents) > 0 {
|
||||
@ -227,6 +222,7 @@ func newHash(hasher crypto.Hash, hashOid asn1.ObjectIdentifier) hash.Hash {
|
||||
return h
|
||||
}
|
||||
|
||||
/*
|
||||
// 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.
|
||||
@ -276,6 +272,7 @@ func (sd *SignedData) SignWithoutAttr(ee *smx509.Certificate, pkey crypto.Privat
|
||||
sd.sd.SignerInfos = append(sd.sd.SignerInfos, signer)
|
||||
return nil
|
||||
}
|
||||
*/
|
||||
|
||||
func (si *signerInfo) SetUnauthenticatedAttributes(extraUnsignedAttrs []Attribute) error {
|
||||
unsignedAttrs := &attributes{}
|
||||
|
@ -254,6 +254,12 @@ func TestVerifyFirefoxAddon(t *testing.T) {
|
||||
t.Errorf("Verify failed with error: %v", err)
|
||||
}
|
||||
|
||||
p7.Content = []byte("bad content")
|
||||
if err = p7.VerifyWithChain(certPool); err == nil {
|
||||
t.Errorf("Verify with incorrect content did not error")
|
||||
}
|
||||
p7.Content = FirefoxAddonContent
|
||||
|
||||
// The chain has validity:
|
||||
//
|
||||
// EE: 2016-08-17 20:04:58 +0000 UTC 2021-08-16 20:04:58 +0000 UTC
|
||||
|
Loading…
x
Reference in New Issue
Block a user