Skip to content
Permalink
Browse files
[FIX JENKINS-41978] - Fix NPE when an invalid PEM is being decoded.
  • Loading branch information
alvarolobato committed Feb 13, 2017
1 parent 0307dba commit 3811e984cf25456f08b4381173832c064db0165f
@@ -152,6 +152,10 @@ public static PEMEncodable decode(@Nonnull String pem, @Nullable final char[] pa

Object object = parser.readObject();

if (object == null) {
throw new IOException("Could not parse PEM, only key pairs, private keys, public keys and certificates are supported");
}

JcaPEMKeyConverter kConv = new JcaPEMKeyConverter().setProvider("BC");

// handle supported PEM formats.
@@ -29,6 +29,7 @@
import static org.junit.Assert.assertNotNull;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.security.PublicKey;
@@ -237,4 +238,9 @@ public void testReadKeyPairFromPCKS8PEM() throws Exception {
assertNotNull(pemEnc.toPublicKey());
}

}
@Test(expected = IOException.class)
@Issue(value = "JENKINS-41978")
public void testInvalidPEM() throws Exception {
PEMEncodable.decode(FileUtils.readFileToString(getResourceFile("invalid.pem")));
}
}
@@ -0,0 +1 @@
---INVALID PEM---

0 comments on commit 3811e98

Please sign in to comment.