Skip to content

Commit 0ffed5e

Browse files
beanuwaveIgonin
and
Igonin
authored
Use BC libraries to parse PEM files, increase key length, allow gener… (opensearch-project#17393)
* Use BC libraries to parse PEM files, increase key length, allow general use of known cryptographic binary extensions, remove unused BC dependencies Signed-off-by: Igonin <iigonin@sap.de> * remove duplicated test permission Signed-off-by: Igonin <iigonin@sap.de> --------- Signed-off-by: Igonin <iigonin@sap.de> Co-authored-by: Igonin <iigonin@sap.de>
1 parent 176a4f0 commit 0ffed5e

File tree

95 files changed

+1214
-1312
lines changed

Some content is hidden

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

95 files changed

+1214
-1312
lines changed

CHANGELOG-3.0.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4444
- Refactor the `:server` module `org.opensearch.client` to `org.opensearch.transport.client` to eliminate top level split packages for JPMS support ([#17272](https://github.com/opensearch-project/OpenSearch/pull/17272))
4545
- Use Lucene `BM25Similarity` as default since the `LegacyBM25Similarity` is marked as deprecated ([#17306](https://github.com/opensearch-project/OpenSearch/pull/17306))
4646
- Wildcard field index only 3gram of the input data [#17349](https://github.com/opensearch-project/OpenSearch/pull/17349)
47+
- Use BC libraries to parse PEM files, increase key length, allow general use of known cryptographic binary extensions, remove unused BC dependencies ([#3420](https://github.com/opensearch-project/OpenSearch/pull/14912))
4748

4849
### Deprecated
4950

buildSrc/build.gradle

-4
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,8 @@ if (project != rootProject) {
229229

230230
forbiddenPatterns {
231231
exclude '**/*.wav'
232-
exclude '**/*.p12'
233-
exclude '**/*.jks'
234-
exclude '**/*.crt'
235232
// the file that actually defines nocommit
236233
exclude '**/ForbiddenPatternsTask.java'
237-
exclude '**/*.bcfks'
238234
}
239235

240236
testingConventions {

buildSrc/src/main/java/org/opensearch/gradle/precommit/ForbiddenPatternsTask.java

+5
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,13 @@ public class ForbiddenPatternsTask extends DefaultTask {
8383
.exclude("**/*.ico")
8484
.exclude("**/*.jar")
8585
.exclude("**/*.zip")
86+
.exclude("**/*.p12")
8687
.exclude("**/*.jks")
8788
.exclude("**/*.crt")
89+
.exclude("**/*.der")
90+
.exclude("**/*.pem")
91+
.exclude("**/*.key")
92+
.exclude("**/*.bcfks")
8893
.exclude("**/*.keystore")
8994
.exclude("**/*.png");
9095

buildSrc/src/main/java/org/opensearch/gradle/testclusters/OpenSearchNode.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -548,15 +548,15 @@ public synchronized void start() {
548548

549549
logToProcessStdout("Creating opensearch keystore with password set to [" + keystorePassword + "]");
550550
if (keystorePassword.length() > 0) {
551-
runOpenSearchBinScriptWithInput(keystorePassword + "\n" + keystorePassword, "opensearch-keystore", "create", "-p");
551+
runOpenSearchBinScriptWithInput(keystorePassword + "\n" + keystorePassword + "\n", "opensearch-keystore", "create", "-p");
552552
} else {
553553
runOpenSearchBinScript("opensearch-keystore", "-v", "create");
554554
}
555555

556556
if (keystoreSettings.isEmpty() == false || keystoreFiles.isEmpty() == false) {
557557
logToProcessStdout("Adding " + keystoreSettings.size() + " keystore settings and " + keystoreFiles.size() + " keystore files");
558558

559-
keystoreSettings.forEach((key, value) -> runKeystoreCommandWithPassword(keystorePassword, value.toString(), "add", "-x", key));
559+
keystoreSettings.forEach((key, value) -> runKeystoreCommandWithPassword(keystorePassword, value.toString(), "add", key));
560560

561561
for (Map.Entry<String, File> entry : keystoreFiles.entrySet()) {
562562
File file = entry.getValue();
@@ -738,7 +738,12 @@ private void runOpenSearchBinScriptWithInput(String input, String tool, CharSequ
738738
}
739739

740740
private void runKeystoreCommandWithPassword(String keystorePassword, String input, CharSequence... args) {
741-
final String actualInput = keystorePassword.length() > 0 ? keystorePassword + "\n" + input : input;
741+
final String actualInput;
742+
if (keystorePassword.length() > 0) {
743+
actualInput = keystorePassword + "\n" + input + "\n" + input;
744+
} else {
745+
actualInput = input + "\n" + input;
746+
}
742747
runOpenSearchBinScriptWithInput(actualInput, "opensearch-keystore", args);
743748
}
744749

client/rest/build.gradle

-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ tasks.withType(CheckForbiddenApis).configureEach {
7575
replaceSignatureFiles('jdk-signatures', 'http-signatures')
7676
}
7777

78-
forbiddenPatterns {
79-
exclude '**/*.der'
80-
}
81-
8278
tasks.named('forbiddenApisTest').configure {
8379
//we are using jdk-internal instead of jdk-non-portable to allow for com.sun.net.httpserver.* usage
8480
bundledSignatures -= 'jdk-non-portable'

distribution/tools/plugin-cli/build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ dependencies {
3939
compileOnly project(":libs:opensearch-cli")
4040
api "org.bouncycastle:bcpg-fips:2.0.9"
4141
api "org.bouncycastle:bc-fips:2.0.0"
42-
testImplementation project(":test:framework")
42+
testImplementation(project(":test:framework")) {
43+
exclude group: 'org.bouncycastle'
44+
}
4345
testImplementation 'com.google.jimfs:jimfs:1.3.0'
4446
testRuntimeOnly("com.google.guava:guava:${versions.guava}") {
4547
transitive = false

libs/ssl-config/build.gradle

+5-6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ apply plugin: "opensearch.publish"
3434

3535
dependencies {
3636
api project(':libs:opensearch-common')
37+
api "org.bouncycastle:bcprov-jdk18on:${versions.bouncycastle}"
38+
api "org.bouncycastle:bcpkix-jdk18on:${versions.bouncycastle}"
39+
runtimeOnly "org.bouncycastle:bcutil-jdk18on:${versions.bouncycastle}"
3740

3841
testImplementation(project(":test:framework")) {
3942
exclude group: 'org.opensearch', module: 'opensearch-ssl-config'
@@ -44,16 +47,12 @@ dependencies {
4447
testImplementation "org.hamcrest:hamcrest:${versions.hamcrest}"
4548
}
4649

47-
4850
tasks.named('forbiddenApisMain').configure {
4951
replaceSignatureFiles 'jdk-signatures'
5052
}
5153

52-
forbiddenPatterns {
53-
exclude '**/*.key'
54-
exclude '**/*.pem'
55-
exclude '**/*.p12'
56-
exclude '**/*.jks'
54+
tasks.named("dependencyLicenses").configure {
55+
mapping from: /bc.*/, to: 'bouncycastle'
5756
}
5857

5958
tasks.test {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
81c1f5e06f206be5dad137d563609dbe66c81d31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Copyright (c) 2000 - 2023 The Legion of the Bouncy Castle Inc. (https://www.bouncycastle.org)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
5+
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
6+
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7+
8+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
9+
Software.
10+
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

libs/ssl-config/src/main/java/org/opensearch/common/ssl/PemKeyConfig.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
package org.opensearch.common.ssl;
3434

35+
import org.bouncycastle.pkcs.PKCSException;
36+
3537
import javax.net.ssl.KeyManagerFactory;
3638
import javax.net.ssl.X509ExtendedKeyManager;
3739

@@ -91,7 +93,7 @@ private PrivateKey getPrivateKey() {
9193
throw new SslConfigException("the configured ssl private key file [" + key.toAbsolutePath() + "] does not exist", e);
9294
} catch (IOException e) {
9395
throw new SslConfigException("the configured ssl private key file [" + key.toAbsolutePath() + "] cannot be read", e);
94-
} catch (GeneralSecurityException e) {
96+
} catch (PKCSException e) {
9597
throw new SslConfigException("cannot load ssl private key file [" + key.toAbsolutePath() + "]", e);
9698
}
9799
}

0 commit comments

Comments
 (0)