From 6d7c6af616c2e9b0a8ce84f50d7c2496b5cb041e Mon Sep 17 00:00:00 2001 From: pktxu <5881103+pktxu@users.noreply.github.com> Date: Thu, 14 Dec 2023 12:29:45 +0100 Subject: [PATCH] fix --- .../kubernetes/client/internal/CertUtils.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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(); }