|
9 | 9 |
|
10 | 10 | package org.elasticsearch.entitlement.initialization; |
11 | 11 |
|
| 12 | +import org.elasticsearch.core.Booleans; |
12 | 13 | import org.elasticsearch.core.PathUtils; |
13 | 14 | import org.elasticsearch.core.internal.provider.ProviderLocator; |
14 | 15 | import org.elasticsearch.entitlement.bootstrap.EntitlementBootstrap; |
@@ -241,16 +242,22 @@ private static PolicyManager createPolicyManager() { |
241 | 242 | ) |
242 | 243 | ); |
243 | 244 |
|
244 | | - Path trustStorePath = trustStorePath(); |
245 | | - if (trustStorePath != null) { |
| 245 | + // conditionally add FIPS entitlements if FIPS only functionality is enforced |
| 246 | + if (Booleans.parseBoolean(System.getProperty("org.bouncycastle.fips.approved_only"), false)) { |
| 247 | + // if custom trust store is set, grant read access to its location, otherwise use the default JDK trust store |
| 248 | + String trustStore = System.getProperty("javax.net.ssl.trustStore"); |
| 249 | + Path trustStorePath = trustStore != null |
| 250 | + ? Path.of(trustStore) |
| 251 | + : Path.of(System.getProperty("java.home")).resolve("lib/security/jssecacerts"); |
| 252 | + |
246 | 253 | Collections.addAll( |
247 | 254 | serverScopes, |
248 | 255 | new Scope( |
249 | 256 | "org.bouncycastle.fips.tls", |
250 | 257 | List.of( |
251 | 258 | new FilesEntitlement(List.of(FileData.ofPath(trustStorePath, READ))), |
252 | | - new OutboundNetworkEntitlement(), |
253 | | - new ManageThreadsEntitlement() |
| 259 | + new ManageThreadsEntitlement(), |
| 260 | + new OutboundNetworkEntitlement() |
254 | 261 | ) |
255 | 262 | ), |
256 | 263 | new Scope( |
@@ -302,11 +309,6 @@ private static Path getUserHome() { |
302 | 309 | return PathUtils.get(userHome); |
303 | 310 | } |
304 | 311 |
|
305 | | - private static Path trustStorePath() { |
306 | | - String trustStore = System.getProperty("javax.net.ssl.trustStore"); |
307 | | - return trustStore != null ? Path.of(trustStore) : null; |
308 | | - } |
309 | | - |
310 | 312 | private static Stream<InstrumentationService.InstrumentationInfo> fileSystemProviderChecks() throws ClassNotFoundException, |
311 | 313 | NoSuchMethodException { |
312 | 314 | var fileSystemProviderClass = FileSystems.getDefault().provider().getClass(); |
|
0 commit comments