diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/internal/CertUtils.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/internal/CertUtils.java index 25d23196206..39a0473ba1e 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/internal/CertUtils.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/internal/CertUtils.java @@ -17,6 +17,8 @@ import io.fabric8.kubernetes.client.KubernetesClientException; import io.fabric8.kubernetes.client.utils.Utils; +import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; +import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.openssl.PEMKeyPair; import org.bouncycastle.openssl.PEMParser; import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; @@ -185,8 +187,14 @@ public PrivateKey call() { if (Security.getProvider("BC") == null && Security.getProvider("BCFIPS") == null) { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); } - PEMKeyPair keys = (PEMKeyPair) new PEMParser(new InputStreamReader(keyInputStream)).readObject(); - return new JcaPEMKeyConverter().getKeyPair(keys).getPrivate(); + Object pemObject = new PEMParser(new InputStreamReader(keyInputStream)).readObject(); + if (pemObject instanceof PEMKeyPair) { + return new JcaPEMKeyConverter().getKeyPair((PEMKeyPair) pemObject).getPrivate(); + } else if (pemObject instanceof PrivateKeyInfo) { + return BouncyCastleProvider.getPrivateKey((PrivateKeyInfo) pemObject); + } else { + throw new RuntimeException("Don't know what to do with a " + pemObject.getClass().getName()); + } } catch (IOException exception) { exception.printStackTrace(); }