Skip to content

Commit

Permalink
address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
pktxu committed Dec 30, 2023
1 parent 5694948 commit 3956a44
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,30 +182,28 @@ private static PrivateKey handleECKey(InputStream keyInputStream) {
try {
return new Callable<PrivateKey>() {
@Override
public PrivateKey call() {
try {
if (Security.getProvider("BC") == null && Security.getProvider("BCFIPS") == null) {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
}
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 KubernetesClientException("Don't know what to do with a " + pemObject.getClass().getName());
}
} catch (IOException exception) {
exception.printStackTrace();
public PrivateKey call() throws IOException {
if (Security.getProvider("BC") == null && Security.getProvider("BCFIPS") == null) {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
}
Object pemObject = new PEMParser(new InputStreamReader(keyInputStream)).readObject();
if (pemObject == null) {
throw new KubernetesClientException("Got null PEM object from EC key's input stream.");
} else if (pemObject instanceof PEMKeyPair) {
return new JcaPEMKeyConverter().getKeyPair((PEMKeyPair) pemObject).getPrivate();
} else if (pemObject instanceof PrivateKeyInfo) {
return BouncyCastleProvider.getPrivateKey((PrivateKeyInfo) pemObject);
} else {
throw new KubernetesClientException("Don't know what to do with a " + pemObject.getClass().getName());
}
return null;
}
}.call();
} catch (NoClassDefFoundError e) {
throw new KubernetesClientException(
"JcaPEMKeyConverter is provided by BouncyCastle, an optional dependency. To use support for EC Keys you must explicitly add this dependency to classpath.");
} catch (NullPointerException npe) {
throw new KubernetesClientException("Could not load EC key.");
} catch (IOException e) {
e.printStackTrace();
throw new KubernetesClientException(e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void loadNothingError()

Exception exception = assertThrows(KubernetesClientException.class,
() -> CertUtils.createKeyStore(null, certPath, null, privateKeyPath, "EC", "foo", null, null));
assertTrue(exception.getMessage().contains("Could not load EC key."));
assertTrue(exception.getMessage().equals("Got null PEM object from EC key's input stream."));
}

@Test
Expand Down

0 comments on commit 3956a44

Please sign in to comment.