Skip to content

Commit

Permalink
Enforce JKS trustore
Browse files Browse the repository at this point in the history
  • Loading branch information
albertzaharovits committed Aug 3, 2024
1 parent 27c80d5 commit 90d0621
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ public static KeyStore filter(KeyStore store, Predicate<KeyStoreEntry> filter) {
* @param certificates The root certificates to trust
*/
public static KeyStore buildTrustStore(Iterable<Certificate> certificates) throws GeneralSecurityException {
return buildTrustStore(certificates, KeyStore.getDefaultType());
}

public static KeyStore buildTrustStore(Iterable<Certificate> certificates, String type) throws GeneralSecurityException {
assert certificates != null : "Cannot create keystore with null certificates";
KeyStore store = buildNewKeyStore();
KeyStore store = buildNewKeyStore(type);
int counter = 0;
for (Certificate certificate : certificates) {
store.setCertificateEntry("cert-" + counter, certificate);
Expand All @@ -117,7 +121,11 @@ public static KeyStore buildTrustStore(Iterable<Certificate> certificates) throw
}

private static KeyStore buildNewKeyStore() throws GeneralSecurityException {
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
return buildNewKeyStore(KeyStore.getDefaultType());
}

private static KeyStore buildNewKeyStore(String type) throws GeneralSecurityException {
KeyStore keyStore = KeyStore.getInstance(type);
try {
keyStore.load(null, null);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public class RepositoryAzureClientYamlTestSuiteIT extends ESClientYamlSuiteTestC
() -> trustStore.getTrustStorePath().toString(),
s -> USE_FIXTURE && ESTestCase.inFipsJvm() == false
)
.systemProperty(
"javax.net.ssl.trustStoreType",
() -> "jks",
s -> USE_FIXTURE && ESTestCase.inFipsJvm() == false
)
.build();

@ClassRule(order = 1)
Expand Down
2 changes: 0 additions & 2 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ tests:
issue: https://github.com/elastic/elasticsearch/issues/111396
- class: org.elasticsearch.xpack.searchablesnapshots.AzureSearchableSnapshotsIT
issue: https://github.com/elastic/elasticsearch/issues/111279
- class: org.elasticsearch.repositories.azure.RepositoryAzureClientYamlTestSuiteIT
issue: https://github.com/elastic/elasticsearch/issues/111345
- class: org.elasticsearch.repositories.blobstore.testkit.AzureSnapshotRepoTestKitIT
method: testRepositoryAnalysis
issue: https://github.com/elastic/elasticsearch/issues/111280
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ protected void before() {
.stream()
.map(i -> (Certificate) i)
.toList();
final var trustStore = KeyStoreUtil.buildTrustStore(certificates);
trustStore.store(jksStream, null);
final var trustStore = KeyStoreUtil.buildTrustStore(certificates, "jks");
trustStore.store(jksStream, new char[0]);
trustStorePath = tmpTrustStorePath;
} catch (Exception e) {
throw new AssertionError("unexpected", e);
Expand Down

0 comments on commit 90d0621

Please sign in to comment.