【发布时间】:2017-01-02 01:29:53
【问题描述】:
我们使用自己的自定义密钥库,还使用 JSSEImplementation 和 ServerSocketFactory 提供了自定义类实现,并在 server.xml 中为“store”和“sslImplementation”属性进行了配置。
但是现在升级到 8.5,我开始收到很多 ClassNotFoundException for JSSESocketFactory 等。
再做一些研究,我发现他们已经删除了许多类和方法,如 JSSESocketFactory.java、getServerSocketFactory()、getSSLUtil(AbstractEndpoint endpoint) 等。
所以现在,我的问题是:
在 apache tomcat 8.5 中有什么方法可以在 server.xml 的“存储”下配置我的自定义密钥库并使用我自己的 sslImplementation?
我在方法签名中使用 AbstractEndpoint 来获取在server.xml 中设置的商店名称,然后像这样在 MyJSSESocketFactory 中加载该密钥库:
public class MySSLImplementation extends JSSEImplementation
{
@Override
public org.apache.tomcat.util.net.ServerSocketFactory getServerSocketFactory(
AbstractEndpoint endpoint) {
kStore = endpoint.getProperty("store");
return new MyJSSESocketFactory(endpoint, kStore);
}
}
public class MyJSSESocketFactory extends JSSESocketFactory {
private final AbstractEndpoint _endpoint;
private final String store;
public MyJSSESocketFactory(AbstractEndpoint endpoint, String store) {
super(endpoint);
this._endpoint = endpoint;
this.store = store;
}
/*
* Gets the SSL server's keystore.
*/
@Override
protected KeyStore getKeystore(String type, String provider, String pass)
throws IOException {
if ("MYKS".equalsIgnoreCase(type)) {
String keystoreName = store;
KeyStore ks = null;
try {
if (provider == null || provider.isEmpty()) {
ks = KeyStore.getInstance(type);
} else {
ks = KeyStore.getInstance(type, provider);
}
MyStoreParameter params = new MyStoreParameter(
keystoreName);
ks.load(params);
} catch (Exception ex) {
throw new IOException(
"Failed to load keystore " + keystoreName, ex);
}
return ks;
} else {
return super.getKeystore(type, provider, pass);
}
}
}
在 server.xml 中为“store”属性设置“MYKS”
【问题讨论】:
-
嗨:我相信答案是“是”,解决方案是使用 JSSE 定义您自己的自定义(与现在显然已经过时的 Tomcat API 相比)。我只能找到一篇关于如何做到这一点的文章:angelfire.com/or/abhilash/site/articles/jsse-km/…
-
我很好奇...你为什么需要自己的
SocketFactory?