blob: 44a9c6065764d74aaf3a9528a0b2368ea2f81632 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.http.ssl;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import java.security.KeyStore;
import java.util.function.Consumer;
/**
* @author bjorncs
*/
public class DefaultSslKeyStoreContext implements SslKeyStoreContext {
private final SslContextFactory sslContextFactory;
public DefaultSslKeyStoreContext(SslContextFactory sslContextFactory) {
this.sslContextFactory = sslContextFactory;
}
@Override
public void updateKeyStore(KeyStore keyStore) {
updateKeyStore(keyStore, null);
}
@Override
public void updateKeyStore(KeyStore keyStore, String password) {
updateKeyStore(sslContextFactory -> {
sslContextFactory.setKeyStore(keyStore);
if (password != null) {
sslContextFactory.setKeyStorePassword(password);
}
});
}
@Override
public void updateKeyStore(String keyStorePath, String keyStoreType, String keyStorePassword) {
updateKeyStore(sslContextFactory -> {
sslContextFactory.setKeyStorePath(keyStorePath);
sslContextFactory.setKeyStoreType(keyStoreType);
sslContextFactory.setKeyStorePassword(keyStorePassword);
});
}
private void updateKeyStore(Consumer<SslContextFactory> reloader) {
try {
sslContextFactory.reload(reloader);
} catch (Exception e) {
throw new RuntimeException("Could not update keystore: " + e.getMessage(), e);
}
}
}
|