Skip to content

Commit 1492a04

Browse files
committed
Remove BouncyCastle dependency from runtime (elastic#32193)
* Remove BouncyCastle dependency from runtime This commit introduces a new gradle project that contains the classes that have a dependency on BouncyCastle. For the default distribution, It builds a jar from those and in puts it in a subdirectory of lib (/tools/security-cli) along with the BouncyCastle jars. This directory is then passed in the ES_ADDITIONAL_CLASSPATH_DIRECTORIES of the CLI tools that use these classes. BouncyCastle is removed as a runtime dependency (remains as a compileOnly one) from x-pack core and x-pack security.
1 parent 4c2fbcf commit 1492a04

File tree

25 files changed

+293
-172
lines changed

25 files changed

+293
-172
lines changed

distribution/archives/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, boolean os
5050
return copySpec {
5151
into("elasticsearch-${version}") {
5252
into('lib') {
53-
with libFiles
53+
with libFiles(oss)
5454
}
5555
into('config') {
5656
dirMode 0750

distribution/build.gradle

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,24 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
226226
/*****************************************************************************
227227
* Common files in all distributions *
228228
*****************************************************************************/
229-
libFiles = copySpec {
230-
// delay by using closures, since they have not yet been configured, so no jar task exists yet
231-
from { project(':server').jar }
232-
from { project(':server').configurations.runtime }
233-
from { project(':libs:plugin-classloader').jar }
234-
from { project(':distribution:tools:java-version-checker').jar }
235-
from { project(':distribution:tools:launchers').jar }
236-
into('tools/plugin-cli') {
237-
from { project(':distribution:tools:plugin-cli').jar }
238-
from { project(':distribution:tools:plugin-cli').configurations.runtime }
229+
libFiles = { oss ->
230+
copySpec {
231+
// delay by using closures, since they have not yet been configured, so no jar task exists yet
232+
from { project(':server').jar }
233+
from { project(':server').configurations.runtime }
234+
from { project(':libs:plugin-classloader').jar }
235+
from { project(':distribution:tools:java-version-checker').jar }
236+
from { project(':distribution:tools:launchers').jar }
237+
into('tools/plugin-cli') {
238+
from { project(':distribution:tools:plugin-cli').jar }
239+
from { project(':distribution:tools:plugin-cli').configurations.runtime }
240+
}
241+
if (oss == false) {
242+
into('tools/security-cli') {
243+
from { project(':x-pack:plugin:security:cli').jar }
244+
from { project(':x-pack:plugin:security:cli').configurations.compile }
245+
}
246+
}
239247
}
240248
}
241249

distribution/packages/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Closure commonPackageConfig(String type, boolean oss) {
125125
fileMode 0644
126126
}
127127
into('lib') {
128-
with libFiles
128+
with libFiles(oss)
129129
}
130130
into('modules') {
131131
with modulesFiles(oss)

qa/vagrant/src/main/java/org/elasticsearch/packaging/test/ArchiveTestCase.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import static org.hamcrest.CoreMatchers.notNullValue;
5858
import static org.hamcrest.MatcherAssert.assertThat;
5959
import static org.hamcrest.Matchers.isEmptyString;
60+
import static org.junit.Assert.assertFalse;
6061
import static org.junit.Assert.assertTrue;
6162
import static org.junit.Assume.assumeThat;
6263
import static org.junit.Assume.assumeTrue;
@@ -302,5 +303,26 @@ public void test80RelativePathConf() throws IOException {
302303
}
303304
}
304305

306+
public void test90SecurityCliPackaging() {
307+
assumeThat(installation, is(notNullValue()));
308+
309+
final Installation.Executables bin = installation.executables();
310+
final Shell sh = new Shell();
311+
312+
if (distribution().equals(Distribution.DEFAULT_TAR) || distribution().equals(Distribution.DEFAULT_ZIP)) {
313+
assertTrue(Files.exists(installation.lib.resolve("tools").resolve("security-cli")));
314+
Platforms.onLinux(() -> {
315+
final Result result = sh.run(bin.elasticsearchCertutil + " help");
316+
assertThat(result.stdout, containsString("Simplifies certificate creation for use with the Elastic Stack"));
317+
});
318+
319+
Platforms.onWindows(() -> {
320+
final Result result = sh.run(bin.elasticsearchCertutil + " help");
321+
assertThat(result.stdout, containsString("Simplifies certificate creation for use with the Elastic Stack"));
322+
});
323+
} else if (distribution().equals(Distribution.OSS_TAR) || distribution().equals(Distribution.OSS_ZIP)) {
324+
assertFalse(Files.exists(installation.lib.resolve("tools").resolve("security-cli")));
325+
}
326+
}
305327

306328
}

qa/vagrant/src/main/java/org/elasticsearch/packaging/util/Installation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public class Executables {
101101
public final Path elasticsearchPlugin = platformExecutable("elasticsearch-plugin");
102102
public final Path elasticsearchKeystore = platformExecutable("elasticsearch-keystore");
103103
public final Path elasticsearchTranslog = platformExecutable("elasticsearch-translog");
104+
public final Path elasticsearchCertutil = platformExecutable("elasticsearch-certutil");
104105

105106
private Path platformExecutable(String name) {
106107
final String platformExecutableName = Platforms.WINDOWS

x-pack/plugin/core/build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ esplugin {
2121
}
2222

2323
dependencyLicenses {
24-
mapping from: /bc.*/, to: 'bouncycastle'
2524
mapping from: /http.*/, to: 'httpclient' // pulled in by rest client
2625
mapping from: /commons-.*/, to: 'commons' // pulled in by rest client
2726
}
@@ -39,8 +38,6 @@ dependencies {
3938

4039
// security deps
4140
shadow 'com.unboundid:unboundid-ldapsdk:3.2.0'
42-
shadow 'org.bouncycastle:bcprov-jdk15on:1.59'
43-
shadow 'org.bouncycastle:bcpkix-jdk15on:1.59'
4441
shadow project(path: ':modules:transport-netty4', configuration: 'runtime')
4542

4643
testCompile 'org.elasticsearch:securemock:1.2'

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/CertParsingUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static Path resolvePath(String path, @Nullable Environment environment) {
6363
return PathUtils.get(path).normalize();
6464
}
6565

66-
static KeyStore readKeyStore(Path path, String type, char[] password)
66+
public static KeyStore readKeyStore(Path path, String type, char[] password)
6767
throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
6868
try (InputStream in = Files.newInputStream(path)) {
6969
KeyStore store = KeyStore.getInstance(type);
@@ -108,7 +108,7 @@ public static X509Certificate[] readX509Certificates(List<Path> certPaths) throw
108108
return certificates.toArray(new X509Certificate[0]);
109109
}
110110

111-
static List<Certificate> readCertificates(InputStream input) throws CertificateException, IOException {
111+
public static List<Certificate> readCertificates(InputStream input) throws CertificateException, IOException {
112112
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
113113
Collection<Certificate> certificates = (Collection<Certificate>) certFactory.generateCertificates(input);
114114
return new ArrayList<>(certificates);
@@ -140,7 +140,7 @@ public static Map<Certificate, Key> readPkcs12KeyPairs(Path path, char[] passwor
140140
/**
141141
* Creates a {@link KeyStore} from a PEM encoded certificate and key file
142142
*/
143-
static KeyStore getKeyStoreFromPEM(Path certificatePath, Path keyPath, char[] keyPassword)
143+
public static KeyStore getKeyStoreFromPEM(Path certificatePath, Path keyPath, char[] keyPassword)
144144
throws IOException, CertificateException, KeyStoreException, NoSuchAlgorithmException {
145145
final PrivateKey key = PemUtils.readPrivateKey(keyPath, () -> keyPassword);
146146
final Certificate[] certificates = readCertificates(Collections.singletonList(certificatePath));
@@ -168,7 +168,7 @@ private static KeyStore getKeyStore(Certificate[] certificateChain, PrivateKey p
168168
/**
169169
* Returns a {@link X509ExtendedKeyManager} that is built from the provided keystore
170170
*/
171-
static X509ExtendedKeyManager keyManager(KeyStore keyStore, char[] password, String algorithm)
171+
public static X509ExtendedKeyManager keyManager(KeyStore keyStore, char[] password, String algorithm)
172172
throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException {
173173
KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
174174
kmf.init(keyStore, password);
@@ -271,7 +271,7 @@ public static X509ExtendedTrustManager trustManager(String trustStorePath, Strin
271271
/**
272272
* Creates a {@link X509ExtendedTrustManager} based on the trust material in the provided {@link KeyStore}
273273
*/
274-
static X509ExtendedTrustManager trustManager(KeyStore keyStore, String algorithm)
274+
public static X509ExtendedTrustManager trustManager(KeyStore keyStore, String algorithm)
275275
throws NoSuchAlgorithmException, KeyStoreException {
276276
TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
277277
tmf.init(keyStore);

x-pack/plugin/security/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ dependencies {
2121
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
2222

2323
compile 'com.unboundid:unboundid-ldapsdk:3.2.0'
24-
compile 'org.bouncycastle:bcprov-jdk15on:1.59'
25-
compile 'org.bouncycastle:bcpkix-jdk15on:1.59'
24+
compileOnly 'org.bouncycastle:bcprov-jdk15on:1.59'
25+
compileOnly 'org.bouncycastle:bcpkix-jdk15on:1.59'
2626

2727
// the following are all SAML dependencies - might as well download the whole internet
2828
compile "org.opensaml:opensaml-core:3.3.0"
@@ -139,7 +139,6 @@ sourceSets.test.resources {
139139
srcDir '../core/src/test/resources'
140140
}
141141
dependencyLicenses {
142-
mapping from: /bc.*/, to: 'bouncycastle'
143142
mapping from: /java-support|opensaml-.*/, to: 'shibboleth'
144143
mapping from: /http.*/, to: 'httpclient'
145144
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apply plugin: 'elasticsearch.build'
2+
3+
archivesBaseName = 'elasticsearch-security-cli'
4+
5+
dependencies {
6+
compileOnly "org.elasticsearch:elasticsearch:${version}"
7+
compileOnly xpackProject('plugin:core')
8+
compile 'org.bouncycastle:bcprov-jdk15on:1.59'
9+
compile 'org.bouncycastle:bcpkix-jdk15on:1.59'
10+
testImplementation 'com.google.jimfs:jimfs:1.1'
11+
testCompile "junit:junit:${versions.junit}"
12+
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
13+
testCompile 'org.elasticsearch:securemock:1.2'
14+
testCompile "org.elasticsearch.test:framework:${version}"
15+
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
16+
}
17+
18+
dependencyLicenses {
19+
mapping from: /bc.*/, to: 'bouncycastle'
20+
}
File renamed without changes.

0 commit comments

Comments
 (0)