Skip to content

Commit

Permalink
Support for EC key spec algorithm used in Docker EE client bundles (s…
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoffer Soop authored and Christoffer Soop committed May 29, 2018
1 parent dbae73f commit 2310051
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/main/java/com/spotify/docker/client/DockerCertificates.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,26 @@ private PrivateKey readPrivateKey(Path file) throws IOException, InvalidKeySpecE
private static PrivateKey generatePrivateKey(PrivateKeyInfo privateKeyInfo) throws IOException,
InvalidKeySpecException, NoSuchAlgorithmException {
final PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(privateKeyInfo.getEncoded());
final KeyFactory kf = KeyFactory.getInstance("RSA");
return kf.generatePrivate(spec);
return tryGeneratePrivateKey(spec, "RSA", "EC");
}

private static PrivateKey tryGeneratePrivateKey(PKCS8EncodedKeySpec spec, String... algorithms)
throws InvalidKeySpecException {

KeyFactory kf;
PrivateKey key;
for (String algorithm : algorithms) {
try {
kf = KeyFactory.getInstance(algorithm);
key = kf.generatePrivate(spec);
log.debug("Generated private key from spec using the '{}' algorithm", algorithm);
return key;
} catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
log.debug("Tried generating private key from spec using the '{}' algorithm", algorithm, e);
}
}

throw new InvalidKeySpecException("Could not generate private key from spec");
}

private List<Certificate> readCertificates(Path file) throws CertificateException, IOException {
Expand Down

0 comments on commit 2310051

Please sign in to comment.