Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8146592

X509Factory throws IllegalArgumentException if parsing error occured

XMLWordPrintable

    • 8
    • x86_64
    • generic

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      public boolean isX509Certificate(byte[] data)
        {
          try {
            CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(data));
            return true;
          }
          catch (CertificateException e) {
            return false;
          }
       }

      java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Input byte array has wrong 4-byte ending unit
      java.lang.IllegalArgumentException: Input byte array has wrong 4-byte ending unit
      at java.util.Base64$Decoder.decode0(Base64.java:704)
      at java.util.Base64$Decoder.decode(Base64.java:526)
      at java.util.Base64$Decoder.decode(Base64.java:549)
      at sun.security.provider.X509Factory.readOneBlock(X509Factory.java:636)
      at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:94)
      at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:339)
      at com.kyriba.technical.shared.internal.services.crypto.CryptoTypeDetector.isX509Certificate(CryptoTypeDetector.java:78)

      REGRESSION. Last worked in version 7u79

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Use the following method
      public boolean isX509Certificate(byte[] data)
        {
          try {
            CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(data));
            return true;
          }
          catch (CertificateException e) {
            return false;
          }
       }

      2. Pass non-X509 certificate to this method.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      generateCertificate throws CertificateException according to javadoc (@exception CertificateException on parsing errors)
      ACTUAL -
      generateCertificate throws IllegalArgumentException



      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Input byte array has wrong 4-byte ending unit
      java.lang.IllegalArgumentException: Input byte array has wrong 4-byte ending unit
      at java.util.Base64$Decoder.decode0(Base64.java:704)
      at java.util.Base64$Decoder.decode(Base64.java:526)
      at java.util.Base64$Decoder.decode(Base64.java:549)
      at sun.security.provider.X509Factory.readOneBlock(X509Factory.java:636)
      at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:94)
      at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:339)
      at com.kyriba.technical.shared.internal.services.crypto.CryptoTypeDetector.isX509Certificate(CryptoTypeDetector.java:78)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      public boolean isX509Certificate(byte[] data)
        {
          try {
            CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(data));
            return true;
          }
          catch (CertificateException | IllegalArgumentException e) {
            return false;
          }
       }

            igerasim Ivan Gerasimov
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: