forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update "ssl-config" to support X-Pack features (elastic#74887)
This commit upgrades the existing SSPL licensed "ssl-config" library to include additional features that are supported by the X-Pack SSL library. This commit does not make any changes to X-Pack to use these new features - it introduces them in preparation for their future use by X-Pack. The reindex module is updated to reflect API changes in ssl-config
- Loading branch information
Showing
26 changed files
with
1,342 additions
and
303 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/CompositeTrustConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.common.ssl; | ||
|
||
import javax.net.ssl.TrustManagerFactory; | ||
import javax.net.ssl.X509ExtendedTrustManager; | ||
import java.nio.file.Path; | ||
import java.security.GeneralSecurityException; | ||
import java.security.KeyStore; | ||
import java.security.cert.Certificate; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* A TrustConfiguration that merges trust anchors from a number of other trust configs to produce a single {@link X509ExtendedTrustManager}. | ||
*/ | ||
public class CompositeTrustConfig implements SslTrustConfig { | ||
private final List<SslTrustConfig> configs; | ||
|
||
CompositeTrustConfig(List<SslTrustConfig> configs) { | ||
this.configs = List.copyOf(configs); | ||
} | ||
|
||
@Override | ||
public Collection<Path> getDependentFiles() { | ||
return configs.stream().map(SslTrustConfig::getDependentFiles).flatMap(Collection::stream).collect(Collectors.toUnmodifiableSet()); | ||
} | ||
|
||
@Override | ||
public boolean isSystemDefault() { | ||
return configs.stream().allMatch(SslTrustConfig::isSystemDefault); | ||
} | ||
|
||
@Override | ||
public X509ExtendedTrustManager createTrustManager() { | ||
try { | ||
Collection<Certificate> trustedIssuers = configs.stream() | ||
.map(c -> c.createTrustManager()) | ||
.map(tm -> tm.getAcceptedIssuers()) | ||
.flatMap(Arrays::stream) | ||
.collect(Collectors.toSet()); | ||
final KeyStore store = KeyStoreUtil.buildTrustStore(trustedIssuers); | ||
return KeyStoreUtil.createTrustManager(store, TrustManagerFactory.getDefaultAlgorithm()); | ||
} catch (GeneralSecurityException e) { | ||
throw new SslConfigException("Cannot combine trust configurations [" | ||
+ configs.stream().map(SslTrustConfig::toString).collect(Collectors.joining(",")) | ||
+ "]", | ||
e); | ||
} | ||
} | ||
|
||
@Override | ||
public Collection<? extends StoredCertificate> getConfiguredCertificates() { | ||
return configs.stream().map(SslTrustConfig::getConfiguredCertificates) | ||
.flatMap(Collection::stream) | ||
.collect(Collectors.toUnmodifiableList()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
CompositeTrustConfig that = (CompositeTrustConfig) o; | ||
return configs.equals(that.configs); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(configs); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Composite-Trust{" + configs.stream().map(SslTrustConfig::toString).collect(Collectors.joining(",")) + '}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.