-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
8u72
-
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;
}
}
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;
}
}
- duplicates
-
JDK-8074935 jdk8 keytool doesn't validate pem files for RFC 1421 correctness, as jdk7 did
-
- Closed
-
- relates to
-
JDK-8032573 CertificateFactory.getInstance("X.509").generateCertificates(InputStream) does not throw CertificateException for invalid input
-
- Closed
-