@@ -544,10 +544,27 @@ void SignatureXAdES_B::validate(const string &policy) const
544544 if (!signatureref.empty ())
545545 EXCEPTION_ADD (exception, " Manifest references and signature references do not match" );
546546
547- try { checkKeyInfo (); }
547+ X509Cert signingCertificate;
548+ vector<X509Cert> untrusted;
549+ for (auto x509Data = signature/" KeyInfo" /" X509Data" ; x509Data; x509Data++)
550+ {
551+ for (auto x509Cert = x509Data/" X509Certificate" ; x509Cert; x509Cert++)
552+ {
553+ vector<unsigned char > cert = x509Cert;
554+ if (cert.empty ())
555+ continue ;
556+ if (!signingCertificate)
557+ signingCertificate = X509Cert (cert);
558+ else
559+ untrusted.emplace_back (cert);
560+ }
561+ }
562+ if (!signingCertificate)
563+ THROW (" Signature does not contain signer certificate" );
564+ try { checkKeyInfo (signingCertificate); }
548565 catch (const Exception& e) { exception.addCause (e); }
549566
550- try { checkSigningCertificate (policy == POLv1); }
567+ try { checkSigningCertificate (signingCertificate, policy == POLv1, untrusted ); }
551568 catch (const Exception& e) { exception.addCause (e); }
552569 } catch (const Exception &e) {
553570 exception.addCause (e);
@@ -595,9 +612,8 @@ void SignatureXAdES_B::checkDigest(XMLNode digest, const vector<unsigned char> &
595612 * Verify if SigningCertificate matches with
596613 * XAdES::SigningCertificate/SigningCertificateV2 Digest and IssuerSerial info
597614 */
598- void SignatureXAdES_B::checkKeyInfo () const
615+ void SignatureXAdES_B::checkKeyInfo (const X509Cert &x509 ) const
599616{
600- X509Cert x509 = signingCertificate ();
601617 if (auto sigCert = signedSignatureProperties ()/" SigningCertificate" )
602618 {
603619 if (auto certs = sigCert/" Cert" ; certs || !(certs + 1 ))
@@ -626,15 +642,13 @@ void SignatureXAdES_B::checkKeyInfo() const
626642 * Check if signing certificate was issued by trusted party.
627643 * @throws Exception on a problem with signing certificate
628644 */
629- void SignatureXAdES_B::checkSigningCertificate (bool noqscd) const
645+ void SignatureXAdES_B::checkSigningCertificate (const X509Cert &x509, bool noqscd, const vector<X509Cert> &untrusted ) const
630646{
631647 try
632648 {
633- X509Cert signingCert = signingCertificate ();
634- vector<X509Cert::KeyUsage> usage = signingCert.keyUsage ();
635- if (!contains (usage, X509Cert::NonRepudiation))
649+ if (!contains (x509.keyUsage (), X509Cert::NonRepudiation))
636650 THROW (" Signing certificate does not contain NonRepudiation key usage flag" );
637- if (!signingCertificate () .verify (noqscd))
651+ if (!x509 .verify (noqscd, {}, untrusted ))
638652 THROW (" Unable to verify signing certificate" );
639653 }
640654 catch (const Exception &e)
0 commit comments