Skip to content

Commit 0680de8

Browse files
iigoninbennygoerzigKarstenSchnitterKai Sternad
committed
Make test-suite runnable under FIPS JVM
Signed-off-by: Igonin <[email protected]> Co-authored-by: Benny Goerzig <[email protected]> Co-authored-by: Karsten Schnitter <[email protected]> Co-authored-by: Kai Sternad <[email protected]>
1 parent a9b6d7a commit 0680de8

File tree

134 files changed

+2077
-343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+2077
-343
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4545
- Added approximation support for range queries with now in date field ([#18511](https://github.com/opensearch-project/OpenSearch/pull/18511))
4646
- Upgrade to protobufs 0.6.0 and clean up deprecated TermQueryProtoUtils code ([#18880](https://github.com/opensearch-project/OpenSearch/pull/18880))
4747
- Prevent shard initialization failure due to streaming consumer errors ([#18877](https://github.com/opensearch-project/OpenSearch/pull/18877))
48+
- Make test-suite runnable under FIPS compliance support ([#18491](https://github.com/opensearch-project/OpenSearch/pull/18491))
4849

4950
### Changed
5051
- Update Subject interface to use CheckedRunnable ([#18570](https://github.com/opensearch-project/OpenSearch/issues/18570))

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,11 @@ gradle.projectsEvaluated {
437437
jvmArgs += ["-javaagent:" + project(':libs:agent-sm:agent').jar.archiveFile.get()]
438438
}
439439
if (BuildParams.inFipsJvm) {
440-
task.jvmArgs += ["-Dorg.bouncycastle.fips.approved_only=true"]
440+
def fipsSecurityFile = project.rootProject.file('distribution/src/config/fips_java.security')
441+
task.jvmArgs += [
442+
"-Dorg.bouncycastle.fips.approved_only=true",
443+
"-Djava.security.properties=${fipsSecurityFile}"
444+
]
441445
}
442446
}
443447
}

buildSrc/src/main/groovy/org/opensearch/gradle/test/StandaloneRestTestPlugin.groovy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
package org.opensearch.gradle.test
3232

3333
import groovy.transform.CompileStatic
34+
import org.gradle.api.artifacts.VersionCatalog
35+
import org.gradle.api.artifacts.VersionCatalogsExtension
3436
import org.opensearch.gradle.OpenSearchJavaPlugin
3537
import org.opensearch.gradle.ExportOpenSearchBuildResourcesTask
3638
import org.opensearch.gradle.RepositoriesSetupPlugin
@@ -92,6 +94,10 @@ class StandaloneRestTestPlugin implements Plugin<Project> {
9294
// create a compileOnly configuration as others might expect it
9395
project.configurations.create("compileOnly")
9496
project.dependencies.add('testImplementation', project.project(':test:framework'))
97+
if (BuildParams.inFipsJvm) {
98+
VersionCatalog libs = project.extensions.getByType(VersionCatalogsExtension).named("libs")
99+
project.dependencies.add('testImplementation', libs.findBundle("bouncycastle").get())
100+
}
95101

96102
EclipseModel eclipse = project.extensions.getByType(EclipseModel)
97103
eclipse.classpath.sourceSets = [testSourceSet]

buildSrc/src/main/java/org/opensearch/gradle/test/rest/RestTestUtil.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ static void setupDependencies(Project project, SourceSet sourceSet) {
102102
);
103103
}
104104

105+
if (BuildParams.isInFipsJvm()) {
106+
project.getDependencies()
107+
.add(
108+
sourceSet.getImplementationConfigurationName(),
109+
"org.bouncycastle:bc-fips:" + VersionProperties.getVersions().get("bouncycastle_jce")
110+
);
111+
project.getDependencies()
112+
.add(
113+
sourceSet.getImplementationConfigurationName(),
114+
"org.bouncycastle:bctls-fips:" + VersionProperties.getVersions().get("bouncycastle_tls")
115+
);
116+
}
105117
}
106118

107119
}
3.69 KB
Binary file not shown.

client/rest-high-level/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ apply plugin: 'opensearch.build'
3636
apply plugin: 'opensearch.rest-test'
3737
apply plugin: 'opensearch.publish'
3838
apply plugin: 'opensearch.rest-resources'
39+
apply from: "$rootDir/gradle/fips.gradle"
3940

4041
base {
4142
group = 'org.opensearch.client'
@@ -66,6 +67,7 @@ dependencies {
6667
testImplementation "junit:junit:${versions.junit}"
6768
//this is needed to make RestHighLevelClientTests#testApiNamingConventions work from IDEs
6869
testImplementation project(":rest-api-spec")
70+
testFipsRuntimeOnly libs.bundles.bouncycastle
6971
}
7072

7173
tasks.named('forbiddenApisMain').configure {

client/rest/src/test/java/org/opensearch/client/RestClientBuilderIntegTests.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,22 @@
5656
import java.security.PrivilegedAction;
5757
import java.security.SecureRandom;
5858

59+
import static org.hamcrest.MatcherAssert.assertThat;
5960
import static org.hamcrest.Matchers.instanceOf;
6061
import static org.junit.Assert.assertEquals;
61-
import static org.junit.Assert.assertThat;
6262
import static org.junit.Assert.fail;
6363

6464
/**
6565
* Integration test to validate the builder builds a client with the correct configuration
6666
*/
67-
public class RestClientBuilderIntegTests extends RestClientTestCase {
67+
public class RestClientBuilderIntegTests extends RestClientTestCase implements RestClientFipsAwareTestCase {
6868

6969
private static HttpsServer httpsServer;
7070

7171
@BeforeClass
7272
public static void startHttpServer() throws Exception {
7373
httpsServer = HttpsServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);
74-
httpsServer.setHttpsConfigurator(new HttpsConfigurator(getSslContext(true)));
74+
httpsServer.setHttpsConfigurator(new HttpsConfigurator(new RestClientBuilderIntegTests().getSslContext(true)));
7575
httpsServer.createContext("/", new ResponseHandler());
7676
httpsServer.start();
7777
}
@@ -91,7 +91,6 @@ public static void stopHttpServers() throws IOException {
9191
}
9292

9393
public void testBuilderUsesDefaultSSLContext() throws Exception {
94-
assumeFalse("https://github.com/elastic/elasticsearch/issues/49094", inFipsJvm());
9594
final SSLContext defaultSSLContext = SSLContext.getDefault();
9695
try {
9796
try (RestClient client = buildRestClient()) {
@@ -118,24 +117,23 @@ private RestClient buildRestClient() {
118117
return RestClient.builder(new HttpHost("https", address.getHostString(), address.getPort())).build();
119118
}
120119

121-
private static SSLContext getSslContext(boolean server) throws Exception {
120+
@Override
121+
public SSLContext getSslContext(boolean server, String keyStoreType, SecureRandom secureRandom, String fileExtension) throws Exception {
122122
SSLContext sslContext;
123123
char[] password = "password".toCharArray();
124-
SecureRandom secureRandom = SecureRandom.getInstanceStrong();
125-
String fileExtension = ".jks";
126124

127125
try (
128126
InputStream trustStoreFile = RestClientBuilderIntegTests.class.getResourceAsStream("/test_truststore" + fileExtension);
129127
InputStream keyStoreFile = RestClientBuilderIntegTests.class.getResourceAsStream("/testks" + fileExtension)
130128
) {
131-
KeyStore keyStore = KeyStore.getInstance("JKS");
129+
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
132130
keyStore.load(keyStoreFile, password);
133-
KeyManagerFactory kmf = KeyManagerFactory.getInstance("PKIX");
131+
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
134132
kmf.init(keyStore, password);
135133

136-
KeyStore trustStore = KeyStore.getInstance("JKS");
134+
KeyStore trustStore = KeyStore.getInstance(keyStoreType);
137135
trustStore.load(trustStoreFile, password);
138-
TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
136+
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
139137
tmf.init(trustStore);
140138

141139
SSLContextBuilder sslContextBuilder = SSLContextBuilder.create().setProtocol(getProtocol()).setSecureRandom(secureRandom);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.client;
10+
11+
import javax.net.ssl.SSLContext;
12+
13+
import java.security.SecureRandom;
14+
15+
import static org.opensearch.client.RestClientTestCase.inFipsJvm;
16+
17+
public interface RestClientFipsAwareTestCase {
18+
19+
default SSLContext getSslContext(boolean server) throws Exception {
20+
String keyStoreType = inFipsJvm() ? "BCFKS" : "JKS";
21+
String fileExtension = inFipsJvm() ? ".bcfks" : ".jks";
22+
SecureRandom secureRandom = inFipsJvm() ? SecureRandom.getInstance("DEFAULT", "BCFIPS") : new SecureRandom();
23+
24+
return getSslContext(server, keyStoreType, secureRandom, fileExtension);
25+
}
26+
27+
SSLContext getSslContext(boolean server, String keyStoreType, SecureRandom secureRandom, String fileExtension) throws Exception;
28+
}
1.47 KB
Binary file not shown.
2.82 KB
Binary file not shown.

0 commit comments

Comments
 (0)