Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e01a383

Browse files
authored
[DE-1010] SSL configuration properties (#611)
1 parent 8994c00 commit e01a383

File tree

33 files changed

+211
-38
lines changed

33 files changed

+211
-38
lines changed

‎core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<relativePath>../release-parent</relativePath>
99
<groupId>com.arangodb</groupId>
1010
<artifactId>release-parent</artifactId>
11-
<version>7.20.0</version>
11+
<version>7.21.0-SNAPSHOT</version>
1212
</parent>
1313

1414
<name>core</name>

‎core/src/main/java/com/arangodb/ArangoDB.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ public interface ArangoDB extends ArangoSerdeAccessor {
356356
/**
357357
* Reset the server log levels
358358
* Revert the server's log level settings to the values they had at startup, as determined by the startup options specified on the command-line, a configuration file, and the factory defaults.
359+
*
359360
* @since ArangoDB 3.12
360361
*/
361362
LogLevelEntity resetLogLevels(LogLevelOptions options);
@@ -484,6 +485,39 @@ public Builder useSsl(final Boolean useSsl) {
484485
return this;
485486
}
486487

488+
/**
489+
* Sets the SSL certificate value as Base64 encoded String
490+
*
491+
* @param sslCertValue the SSL certificate value as Base64 encoded String
492+
* @return {@link ArangoDB.Builder}
493+
*/
494+
public Builder sslCertValue(final String sslCertValue) {
495+
config.setSslCertValue(sslCertValue);
496+
return this;
497+
}
498+
499+
/**
500+
* Sets the SSL Trust manager algorithm
501+
*
502+
* @param sslAlgorithm the name of the SSL Trust manager algorithm
503+
* @return {@link ArangoDB.Builder}
504+
*/
505+
public Builder sslAlgorithm(final String sslAlgorithm) {
506+
config.setSslAlgorithm(sslAlgorithm);
507+
return this;
508+
}
509+
510+
/**
511+
* Sets the SSLContext protocol, default: {@code TLS}
512+
*
513+
* @param sslProtocol the name of the SSLContext protocol
514+
* @return {@link ArangoDB.Builder}
515+
*/
516+
public Builder sslProtocol(final String sslProtocol) {
517+
config.setSslProtocol(sslProtocol);
518+
return this;
519+
}
520+
487521
/**
488522
* Sets the SSL context to be used when {@code true} is passed through {@link #useSsl(Boolean)}.
489523
*
@@ -716,6 +750,7 @@ public Builder compressionLevel(Integer level) {
716750

717751
/**
718752
* Configuration specific for {@link com.arangodb.internal.net.ProtocolProvider}.
753+
*
719754
* @return {@link ArangoDB.Builder}
720755
*/
721756
public Builder protocolConfig(ProtocolConfig protocolConfig) {

‎core/src/main/java/com/arangodb/config/ArangoConfigProperties.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public interface ArangoConfigProperties {
1919
String KEY_JWT = "jwt";
2020
String KEY_TIMEOUT = "timeout";
2121
String KEY_USE_SSL = "useSsl";
22+
String KEY_SSL_CERT_VALUE = "sslCertValue";
23+
String KEY_SSL_ALGORITHM = "sslAlgorithm";
24+
String KEY_SSL_PROTOCOL = "sslProtocol";
2225
String KEY_VERIFY_HOST = "verifyHost";
2326
String KEY_CHUNK_SIZE = "chunkSize";
2427
String KEY_PIPELINING = "pipelining";
@@ -103,6 +106,18 @@ default Optional<Boolean> getUseSsl() {
103106
return Optional.empty();
104107
}
105108

109+
default Optional<String> getSslCertValue() {
110+
return Optional.empty();
111+
}
112+
113+
default Optional<String> getSslAlgorithm() {
114+
return Optional.empty();
115+
}
116+
117+
default Optional<String> getSslProtocol() {
118+
return Optional.empty();
119+
}
120+
106121
default Optional<Boolean> getVerifyHost() {
107122
return Optional.empty();
108123
}

‎core/src/main/java/com/arangodb/internal/ArangoDefaults.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public final class ArangoDefaults {
4848
public static final Integer DEFAULT_TIMEOUT = 0;
4949
public static final Long DEFAULT_CONNECTION_TTL_HTTP = 30_000L;
5050
public static final Boolean DEFAULT_USE_SSL = false;
51+
public static final String DEFAULT_SSL_PROTOCOL = "TLS";
5152
public static final Boolean DEFAULT_VERIFY_HOST = true;
5253
public static final Integer DEFAULT_CHUNK_SIZE = 30_000;
5354
public static final Boolean DEFAULT_PIPELINING = false;

‎core/src/main/java/com/arangodb/internal/config/ArangoConfig.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
import com.fasterxml.jackson.databind.Module;
1717

1818
import javax.net.ssl.SSLContext;
19+
import javax.net.ssl.TrustManagerFactory;
20+
import java.io.ByteArrayInputStream;
1921
import java.lang.reflect.InvocationTargetException;
22+
import java.security.KeyStore;
23+
import java.security.cert.Certificate;
24+
import java.security.cert.CertificateFactory;
2025
import java.util.*;
2126
import java.util.concurrent.Executor;
2227
import java.util.stream.Collectors;
@@ -30,6 +35,9 @@ public class ArangoConfig {
3035
private String password;
3136
private String jwt;
3237
private Boolean useSsl;
38+
private Optional<String> sslCertValue;
39+
private Optional<String> sslAlgorithm;
40+
private String sslProtocol;
3341
private SSLContext sslContext;
3442
private Boolean verifyHost;
3543
private Integer chunkSize;
@@ -69,6 +77,9 @@ public void loadProperties(final ArangoConfigProperties properties) {
6977
// FIXME: make jwt field Optional
7078
jwt = properties.getJwt().orElse(null);
7179
useSsl = properties.getUseSsl().orElse(ArangoDefaults.DEFAULT_USE_SSL);
80+
sslCertValue = properties.getSslCertValue();
81+
sslAlgorithm = properties.getSslAlgorithm();
82+
sslProtocol = properties.getSslProtocol().orElse(ArangoDefaults.DEFAULT_SSL_PROTOCOL);
7283
verifyHost = properties.getVerifyHost().orElse(ArangoDefaults.DEFAULT_VERIFY_HOST);
7384
chunkSize = properties.getChunkSize().orElse(ArangoDefaults.DEFAULT_CHUNK_SIZE);
7485
pipelining = properties.getPipelining().orElse(ArangoDefaults.DEFAULT_PIPELINING);
@@ -151,7 +162,22 @@ public void setUseSsl(Boolean useSsl) {
151162
this.useSsl = useSsl;
152163
}
153164

165+
public void setSslCertValue(String sslCertValue) {
166+
this.sslCertValue = Optional.ofNullable(sslCertValue);
167+
}
168+
169+
public void setSslAlgorithm(String sslAlgorithm) {
170+
this.sslAlgorithm = Optional.ofNullable(sslAlgorithm);
171+
}
172+
173+
public void setSslProtocol(String sslProtocol) {
174+
this.sslProtocol = sslProtocol;
175+
}
176+
154177
public SSLContext getSslContext() {
178+
if (sslContext == null) {
179+
sslContext = createSslContext();
180+
}
155181
return sslContext;
156182
}
157183

@@ -342,4 +368,26 @@ public ProtocolConfig getProtocolConfig() {
342368
public void setProtocolConfig(ProtocolConfig protocolConfig) {
343369
this.protocolConfig = protocolConfig;
344370
}
371+
372+
private SSLContext createSslContext() {
373+
try {
374+
if (sslCertValue.isPresent()) {
375+
ByteArrayInputStream is = new ByteArrayInputStream(Base64.getDecoder().decode(sslCertValue.get()));
376+
Certificate cert = CertificateFactory.getInstance("X.509").generateCertificate(is);
377+
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
378+
ks.load(null);
379+
ks.setCertificateEntry("arangodb", cert);
380+
TrustManagerFactory tmf = TrustManagerFactory.getInstance(sslAlgorithm.orElseGet(TrustManagerFactory::getDefaultAlgorithm));
381+
tmf.init(ks);
382+
SSLContext sc = SSLContext.getInstance(sslProtocol);
383+
sc.init(null, tmf.getTrustManagers(), null);
384+
return sc;
385+
} else {
386+
return SSLContext.getDefault();
387+
}
388+
} catch (Exception e) {
389+
throw new RuntimeException(e);
390+
}
391+
}
392+
345393
}

‎core/src/main/java/com/arangodb/internal/config/ArangoConfigPropertiesImpl.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,21 @@ public Optional<Boolean> getUseSsl() {
109109
return Optional.ofNullable(getProperty(KEY_USE_SSL)).map(Boolean::valueOf);
110110
}
111111

112+
@Override
113+
public Optional<String> getSslCertValue() {
114+
return Optional.ofNullable(getProperty(KEY_SSL_CERT_VALUE));
115+
}
116+
117+
@Override
118+
public Optional<String> getSslAlgorithm() {
119+
return Optional.ofNullable(getProperty(KEY_SSL_ALGORITHM));
120+
}
121+
122+
@Override
123+
public Optional<String> getSslProtocol() {
124+
return Optional.ofNullable(getProperty(KEY_SSL_PROTOCOL));
125+
}
126+
112127
@Override
113128
public Optional<Boolean> getVerifyHost() {
114129
return Optional.ofNullable(getProperty(KEY_VERIFY_HOST)).map(Boolean::valueOf);

‎driver/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<relativePath>../release-parent</relativePath>
99
<groupId>com.arangodb</groupId>
1010
<artifactId>release-parent</artifactId>
11-
<version>7.20.0</version>
11+
<version>7.21.0-SNAPSHOT</version>
1212
</parent>
1313

1414
<name>arangodb-java-driver</name>

‎http-protocol/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<relativePath>../release-parent</relativePath>
99
<groupId>com.arangodb</groupId>
1010
<artifactId>release-parent</artifactId>
11-
<version>7.20.0</version>
11+
<version>7.21.0-SNAPSHOT</version>
1212
</parent>
1313

1414
<name>http-protocol</name>

‎http-protocol/src/main/java/com/arangodb/http/HttpConnection.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import org.slf4j.LoggerFactory;
5656

5757
import javax.net.ssl.SSLContext;
58-
import java.security.NoSuchAlgorithmException;
5958
import java.util.Collections;
6059
import java.util.Iterator;
6160
import java.util.Map.Entry;
@@ -169,17 +168,7 @@ private static String getUserAgent() {
169168
}
170169

171170
if (Boolean.TRUE.equals(config.getUseSsl())) {
172-
SSLContext ctx;
173-
if (config.getSslContext() != null) {
174-
ctx = config.getSslContext();
175-
} else {
176-
try {
177-
ctx = SSLContext.getDefault();
178-
} catch (NoSuchAlgorithmException e) {
179-
throw ArangoDBException.of(e);
180-
}
181-
}
182-
171+
SSLContext ctx = config.getSslContext();
183172
webClientOptions
184173
.setSsl(true)
185174
.setUseAlpn(true)

‎jackson-serde-json/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<relativePath>../release-parent</relativePath>
99
<groupId>com.arangodb</groupId>
1010
<artifactId>release-parent</artifactId>
11-
<version>7.20.0</version>
11+
<version>7.21.0-SNAPSHOT</version>
1212
</parent>
1313

1414
<name>jackson-serde-json</name>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /