Skip to content

Commit 8fad3d6

Browse files
committed
Throw an exception when unable to read Certificate (#40092)
With SUN security provider, a CertificateException is thrown when attempting to parse a Certificate from a PEM file on disk with `sun.security.provider.X509Provider#parseX509orPKCS7Cert` When using the BouncyCastle Security provider (as we do in fips tests) the parsing happens in CertificateFactory#engineGenerateCertificates which doesn't throw an exception but returns an empty list. In order to have a consistent behavior, this change makes it so that we throw a CertificateException when attempting to read a PEM file from disk and failing to do so in either Security Provider Resolves: #39580
1 parent 1a98568 commit 8fad3d6

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/CertParsingUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ public static Certificate[] readCertificates(List<Path> certPaths) throws Certif
9292
for (Path path : certPaths) {
9393
try (InputStream input = Files.newInputStream(path)) {
9494
certificates.addAll((Collection<Certificate>) certFactory.generateCertificates(input));
95+
if (certificates.isEmpty()) {
96+
throw new CertificateException("failed to parse any certificates from [" + path.toAbsolutePath() + "]");
97+
}
9598
}
9699
}
97100
return certificates.toArray(new Certificate[0]);

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ssl/SSLConfigurationReloaderTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@ void reloadSSLContext(SSLConfiguration configuration) {
448448
* truncating the certificate file that is being monitored
449449
*/
450450
public void testPEMTrustReloadException() throws Exception {
451-
assumeFalse("Broken on BC-FIPS -- https://github.com/elastic/elasticsearch/issues/39580", inFipsJvm());
452451
Path tempDir = createTempDir();
453452
Path clientCertPath = tempDir.resolve("testclient.crt");
454453
Files.copy(getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testclient.crt"), clientCertPath);

0 commit comments

Comments
 (0)