You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2018/11/24 15:02:48 UTC

svn commit: r1847366 - /pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/cert/OcspHelper.java

Author: tilman
Date: Sat Nov 24 15:02:48 2018
New Revision: 1847366

URL: http://svn.apache.org/viewvc?rev=1847366&view=rev
Log:
PDFBOX-3017: search additionalCerts for issuer of OCSP response if not found

Modified:
    pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/cert/OcspHelper.java

Modified: pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/cert/OcspHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/cert/OcspHelper.java?rev=1847366&r1=1847365&r2=1847366&view=diff
==============================================================================
--- pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/cert/OcspHelper.java (original)
+++ pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/cert/OcspHelper.java Sat Nov 24 15:02:48 2018
@@ -135,24 +135,46 @@ public class OcspHelper
             // (...)
             // either the name of the responder or a hash of the responder's
             // public key as the ResponderID
+            // (...)
+            // The responder MAY include certificates in the certs field of
+            // BasicOCSPResponse that help the OCSP client verify the responder's
+            // signature.
             X500Name name = responderID.getName();
             if (name != null)
             {
-                // The responder MAY include certificates in the certs field of
-                // BasicOCSPResponse that help the OCSP client verify the responder's
-                // signature.
                 X509CertificateHolder[] certHolders = basicResponse.getCerts();
                 for (X509CertificateHolder certHolder : certHolders)
                 {
                     if (name.equals(certHolder.getSubject()))
                     {
                         ocspResponderCertificateHolder = certHolder;
+                        break;
                     }
                 }
                 if (ocspResponderCertificateHolder == null)
                 {
-                    //TODO search existing chain
-                    throw new OCSPException("OCSP: certificate for responder " + name + " not found in response");
+                    // DO NOT use the certificate found in additionalCerts first. One file had a 
+                    // responder certificate in the PDF itself with SHA1withRSA algorithm, but
+                    // the responder delivered a different (newer, more secure) certificate
+                    // with SHA256withRSA (tried with QV_RCA1_RCA3_CPCPS_V4_11.pdf)
+                    // https://www.quovadisglobal.com/~/media/Files/Repository/QV_RCA1_RCA3_CPCPS_V4_11.ashx
+                    for (X509Certificate cert : additionalCerts)
+                    {
+                        X500Name certSubjectName = new X500Name(cert.getSubjectX500Principal().getName());
+                        if (certSubjectName.equals(name))
+                        {
+                            try
+                            {
+                                ocspResponderCertificateHolder = new X509CertificateHolder(cert.getEncoded());
+                                break;
+                            }
+                            catch (CertificateEncodingException ex)
+                            {
+                                // unlikely to happen because the certificate existed as an object
+                                LOG.error(ex, ex);
+                            }
+                        }
+                    }
                 }
             }
             else
@@ -175,6 +197,14 @@ public class OcspHelper
                 //            dgOut.close();
                 //            ASN1OctetString issuerKeyHash = new DEROctetString(digCalc.getDigest());
             }
+
+            if (ocspResponderCertificateHolder == null)
+            {
+                throw new OCSPException("OCSP: certificate for responder " + name + " not found");
+            }
+
+            //TODO verify that ExtendedKeyUsage usage contains OCSPSigning
+
             checkOcspSignature(ocspResponderCertificateHolder, basicResponse);
 
             boolean nonceChecked = checkNonce(basicResponse);