Log when encountered cert but expecting key and vice-versa (elastic/x-pack-elasticsearch#2670)
relates elastic/x-pack-elasticsearch#2657
Original commit: elastic/x-pack-elasticsearch@0e826b63b7c87bc07d587298bd245faf1359c65a
@@ -226,8 +226,11 @@ public class CertUtils {
X509TrustedCertificateBlock certificateBlock = (X509TrustedCertificateBlock) parsed;
holder = certificateBlock.getCertificateHolder();
} else {
- throw new IllegalArgumentException("parsed an unsupported object [" +
- parsed.getClass().getSimpleName() + "]");
+ String msg = "parsed an unsupported object [" + parsed.getClass().getSimpleName() + "]";
+ if (parsed instanceof PEMEncryptedKeyPair || parsed instanceof PEMKeyPair || parsed instanceof PrivateKeyInfo) {
+ msg = msg + ". Encountered a PEM Key while expecting a PEM certificate.";
+ }
+ throw new IllegalArgumentException(msg);
}
certificates.add(certFactory.generateCertificate(new ByteArrayInputStream(holder.getEncoded())));
parsed = pemParser.readObject();
@@ -275,7 +278,11 @@ public class CertUtils {
// skip this object and recurse into this method again to read the next object
return innerReadPrivateKey(parser, passwordSupplier);
} else {
- throw new IllegalArgumentException("parsed an unsupported object [" + parsed.getClass().getSimpleName() + "]");
+ String msg = "parsed an unsupported object [" + parsed.getClass().getSimpleName() + "]";
+ if (parsed instanceof X509CertificateHolder || parsed instanceof X509TrustedCertificateBlock) {
+ msg = msg + ". Encountered a PEM Certificate while expecting a PEM Key.";
+ }
+ throw new IllegalArgumentException(msg);
}
return privateKeyInfo;
