Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

package org.elasticsearch.entitlement.initialization;

import org.elasticsearch.core.Booleans;
import org.elasticsearch.core.PathUtils;
import org.elasticsearch.core.internal.provider.ProviderLocator;
import org.elasticsearch.entitlement.bootstrap.EntitlementBootstrap;
Expand Down Expand Up @@ -241,16 +242,22 @@ private static PolicyManager createPolicyManager() {
)
);

Path trustStorePath = trustStorePath();
if (trustStorePath != null) {
// conditionally add FIPS entitlements if FIPS only functionality is enforced
if (Booleans.parseBoolean(System.getProperty("org.bouncycastle.fips.approved_only"), false)) {
// if custom trust store is set, grant read access to its location, otherwise use the default JDK trust store
String trustStore = System.getProperty("javax.net.ssl.trustStore");
Path trustStorePath = trustStore != null
? Path.of(trustStore)
: Path.of(System.getProperty("java.home")).resolve("lib/security/jssecacerts");

Collections.addAll(
serverScopes,
new Scope(
"org.bouncycastle.fips.tls",
List.of(
new FilesEntitlement(List.of(FileData.ofPath(trustStorePath, READ))),
new OutboundNetworkEntitlement(),
new ManageThreadsEntitlement()
new ManageThreadsEntitlement(),
new OutboundNetworkEntitlement()
)
),
new Scope(
Expand Down Expand Up @@ -302,11 +309,6 @@ private static Path getUserHome() {
return PathUtils.get(userHome);
}

private static Path trustStorePath() {
String trustStore = System.getProperty("javax.net.ssl.trustStore");
return trustStore != null ? Path.of(trustStore) : null;
}

private static Stream<InstrumentationService.InstrumentationInfo> fileSystemProviderChecks() throws ClassNotFoundException,
NoSuchMethodException {
var fileSystemProviderClass = FileSystems.getDefault().provider().getClass();
Expand Down