]
Jan Kalina reassigned ELY-1300:
-------------------------------
Assignee: Jan Kalina
Pem.parsePemX509Certificate() cannot parse files with non-PEM
content
---------------------------------------------------------------------
Key: ELY-1300
URL:
https://issues.jboss.org/browse/ELY-1300
Project: WildFly Elytron
Issue Type: Bug
Reporter: Peter Palaga
Assignee: Jan Kalina
Add a test like this to `PemTest`:
{code}
@Test
public void testParsePemX509Certificate01() throws Exception {
URL url = PemTest.class.getResource("/ca/certs/01.pem");
byte[] bytes = Files.readAllBytes(Paths.get(url.toURI()));
assertNotNull(Pem.parsePemX509Certificate(CodePointIterator.ofUtf8Bytes(bytes)));
}
{code}
Note that {{ca/certs/01.pem}} should start with non-PEM content
{code}
Certificate:
Data:
...
{code}
followed by the PEM content:
{code}
-----BEGIN CERTIFICATE-----
{code}
Run the test
{code}
mvn clean test -Dtest=PemTest#testParsePemX509Certificate01
{code}
Expected: Not quite sure if the parser should accept this. In any case, the following
code works on Oracle/OpenJDK (while it does not on IBM JDK):
{code}
CertificateFactory certificateFactory =
CertificateFactory.getInstance("X.509");
InputStream is =
X509EvidenceVerificationSuiteChild.class.getResourceAsStream("/ca/certs/01.pem");
Assert.assertNotNull((X509Certificate)
certificateFactory.generateCertificate(is));
{code}
Actual:
{code}
testParsePemX509Certificate01(org.wildfly.security.util.PemTest) Time elapsed: 0.116 sec
<<< ERROR!
java.lang.IllegalArgumentException: ELY03010: Malformed PEM content at offset 1
at org.wildfly.security.pem.Pem.parsePemContent(Pem.java:79)
at org.wildfly.security.pem.Pem.parsePemX509Certificate(Pem.java:272)
at org.wildfly.security.util.PemTest.testParsePemX509Certificate01(PemTest.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:367)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:274)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:161)
at
org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
at
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
{code}