Spring集成TCP连接工厂SSL - 使用java密钥库

时间:2013-01-14 07:31:52

标签: java spring spring-integration

更新已修复Spring Integration 2.2.1

我有tcp-connection-factory

<int-ip:tcp-connection-factory id="tranServer" type="client" host="127.0.0.1" port="1234"
    single-use="true" ssl-context-support="sslContext" />

<bean id="sslContext" class="org.springframework.integration.ip.tcp.connection.support.DefaultTcpSSLContextSupport">
    <constructor-arg value="client.ks" />
    <constructor-arg value="client.truststore.ks" />
    <constructor-arg value="secret" />
    <constructor-arg value="secret" />
</bean>

我想使用默认的java密钥库作为SSL上下文,因为安装过程的一部分是将SSL证书加载到其中。如何指定默认密钥库和信任库密码。

1 个答案:

答案 0 :(得分:2)

更新已修复Spring Integration 2.2.1

基本上问题是DefaultTcpSSLContextSupport从方法ClassPathResource中的getSSLContext()加载密钥库和信任库

ks.load(new FileInputStream(new ClassPathResource(keyStore).getFile()), keyStorePassword);
ts.load(new FileInputStream(new ClassPathResource(trustStore).getFile()), trustStorePassword);

我创建了自己的FileTcpSSLContextSupport类,删除了ClassPathResource

ks.load(new FileInputStream(keyStore), keyStorePassword);
ts.load(new FileInputStream(trustStore), trustStorePassword);

然后我用

创建bean
<bean id="sslContext" class="com.liquidtelecoms.tillintegration.FileTcpSSLContextSupport">
    <constructor-arg value="${java.home}/lib/security/cacerts" />
    <constructor-arg value="${java.home}/lib/security/cacerts" />
    <constructor-arg value="changeit" />
    <constructor-arg value="changeit" />
</bean>