classifyCertificate reports whether a signature that failed to validate against roots was made with an untrusted certificate, or with a trusted one outside its validity period at now. It mirrors how goxmldsig picks the signing certificate: the first X509Certificate in the Signature's KeyInfo, or the
(el *etree.Element, roots []*x509.Certificate, now time.Time)
| 190 | // or the only root when there is no KeyInfo. It returns nil when neither |
| 191 | // applies or the certificate cannot be determined. |
| 192 | func classifyCertificate(el *etree.Element, roots []*x509.Certificate, now time.Time) error { |
| 193 | var signingCert *x509.Certificate |
| 194 | if certEl := el.FindElement("./Signature/KeyInfo/X509Data/X509Certificate"); certEl != nil { |
| 195 | cert, err := parseCert(certEl.Text()) |
| 196 | if err != nil { |
| 197 | return nil |
| 198 | } |
| 199 | signingCert = cert |
| 200 | } else if el.FindElement("./Signature/KeyInfo") == nil && len(roots) == 1 { |
| 201 | signingCert = roots[0] |
| 202 | } else { |
| 203 | return nil |
| 204 | } |
| 205 | |
| 206 | for _, root := range roots { |
| 207 | if root.Equal(signingCert) { |
| 208 | if now.Before(root.NotBefore) || now.After(root.NotAfter) { |
| 209 | return ErrCertificateNotValidNow |
| 210 | } |
| 211 | return nil |
| 212 | } |
| 213 | } |
| 214 | return ErrUntrustedCertificate |
| 215 | } |