MCPcopy Create free account
hub / github.com/egonelbre/exp / CheckSignature

Method CheckSignature

smime/signeddata.go:39–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37}
38
39func (s *SignedData) CheckSignature() (err error) {
40 if len(s.Signers) == 0 {
41 return fmt.Errorf("no signature found")
42 }
43
44 for _, signer := range s.Signers {
45 var cert *x509.Certificate
46 if cert, err = s.findCertFor(signer); err != nil {
47 return
48 }
49
50 // check the revocation lists
51 revoked := false
52 for _, crl := range s.CRLs {
53 if revokeerr := cert.CheckCRLSignature(crl); revokeerr != nil {
54 revoked = true
55 }
56 }
57
58 if revoked {
59 if panictodo {
60 panic("TODO: check counter signature")
61 }
62 // return fmt.Errorf("smime: certificate has been revoked")
63 }
64
65 data := s.Content
66 if signer.RawSignedAttributes != nil {
67 var attrvalue []byte
68 if attrvalue, err = findSingleAttribute(signer.SignedAttributes, oidMessageDigest); err != nil {
69 return errors.New("smime: message digest not found")
70 }
71
72 var digest []byte
73
74 // the single message digest attribute should be OCTET STRING
75 if _, err = asn1.Unmarshal(attrvalue, &digest); err != nil {
76 return
77 }
78
79 calculated := data
80 if hash := getDigestHashType(signer.DigestAlgorithm.Algorithm); hash.Available() {
81 h := hash.New()
82 h.Write(data)
83 calculated = h.Sum(nil)
84 }
85
86 if !bytes.Equal(digest, calculated) {
87 return errors.New("smime: message digest does not match content")
88 }
89
90 data = signer.RawSignedAttributes
91 }
92
93 algo := getSignatureAlgorithmFromOID(signer.SignatureAlgorithm.Algorithm)
94 err = cert.CheckSignature(algo, data, signer.Signature)
95 if err != nil {
96 return

Calls 6

findCertForMethod · 0.95
findSingleAttributeFunction · 0.85
getDigestHashTypeFunction · 0.85
UnmarshalMethod · 0.65
WriteMethod · 0.45

Tested by 9

TestFancierSignedContentFunction · 0.64
TestAllRSASignedMessageFunction · 0.64
TestMultipleSignersFunction · 0.64
TestSigningUsingSKIFunction · 0.64