Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pktxu authored and pk-aetion committed Dec 19, 2023
1 parent ea0fdec commit 6d7c6af
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 6d7c6af

Please sign in to comment.