173.9. SSL 支持(HTTPS)
使用 JSSE 配置实用程序
从 Camel 2.8 开始,Jetty 组件通过 Camel JSSE 配置实用程序 支持 SSL/TLS 配置。 这个实用程序可大大减少您需要编写的组件特定代码的数量,并在端点和组件级别进行配置。 以下示例演示了如何将 实用程序与 Jetty 组件搭配使用。
组件的程序配置
KeyStoreParameters ksp = new KeyStoreParameters(); ksp.setResource("/users/home/server/keystore.jks"); ksp.setPassword("keystorePassword"); KeyManagersParameters kmp = new KeyManagersParameters(); kmp.setKeyStore(ksp); kmp.setKeyPassword("keyPassword"); SSLContextParameters scp = new SSLContextParameters(); scp.setKeyManagers(kmp); JettyComponent jettyComponent = getContext().getComponent("jetty", JettyComponent.class); jettyComponent.setSslContextParameters(scp);
基于 Spring DSL 端点配置
... <camel:sslContextParameters id="sslContextParameters"> <camel:keyManagers keyPassword="keyPassword"> <camel:keyStore resource="/users/home/server/keystore.jks" password="keystorePassword"/> </camel:keyManagers> </camel:sslContextParameters>... ... <to uri="jetty:https://127.0.0.1/mail/?sslContextParameters=#sslContextParameters"/> ...
配置 Jetty Directly
Jetty 提供 SSL 支持开箱即用。要启用 Jetty 以 SSL 模式运行,只需将 URI 格式化为 https://
前缀--例如:
<from uri="jetty:https://0.0.0.0/myapp/myservice/"/>
Jetty 还需要了解从何处加载您的密钥存储以及要使用哪些密码才能加载正确的 SSL 证书。设置以下 JVM 系统属性:
直至 Camel 2.2
-
jetty.ssl.keystore
指定 Java 密钥存储文件的位置,该文件在 键条目 中包含 Jetty 服务器自己的 X.509 证书。密钥条目存储 X.509 证书(有效地、公钥)及其关联的私钥。 -
jetty.ssl.password
,存储密码才能访问密钥存储文件(这是提供给密钥存储
命令的-storepass
选项的密码)。 -
jetty.ssl.keypassword
,密钥密码用于访问密钥存储中的证书密钥条目(这是提供给密钥存储
命令的-keypass
选项时所用的密码)。
从 Camel 2.3 开始
-
org.eclipse.jetty.ssl.keystore
指定 Java 密钥存储文件的位置,该文件在 密钥条目 中包含 Jetty 服务器自己的 X.509 证书。密钥条目存储 X.509 证书(有效地、公钥)及其关联的私钥。 -
org.eclipse.jetty.ssl.password
,该存储密码需要访问密钥存储文件(这是提供给密钥存储
命令的-storepass
选项时所用的密码)。 -
org.eclipse.jetty.ssl.keypassword
,密钥密码用于访问密钥存储中的证书密钥条目(这是提供给密钥存储
命令的-keypass
选项)的密码。
有关如何在 Jetty 端点上配置 SSL 的详情,请阅读 Jetty Site 的以下文档 :http://docs.codehaus.org/display/JETTY/How+to+configure+SSL
Camel 不直接公开某些 SSL 属性,但 Camel 确实公开底层 SslSocketConnector,这将允许您设置属性,例如:需要客户端证书或想要ClientAuth 进行相互验证,而客户端不需要证书但可以有证书。各种 Camel 版本之间存在一些差异:
最多 Camel 2.2
<bean id="jetty" class="org.apache.camel.component.jetty.JettyHttpComponent"> <property name="sslSocketConnectors"> <map> <entry key="8043"> <bean class="org.mortbay.jetty.security.SslSocketConnector"> <property name="password"value="..."/> <property name="keyPassword"value="..."/> <property name="keystore"value="..."/> <property name="needClientAuth"value="..."/> <property name="truststore"value="..."/> </bean> </entry> </map> </property> </bean>
Camel 2.3, 2.4
<bean id="jetty" class="org.apache.camel.component.jetty.JettyHttpComponent"> <property name="sslSocketConnectors"> <map> <entry key="8043"> <bean class="org.eclipse.jetty.server.ssl.SslSocketConnector"> <property name="password"value="..."/> <property name="keyPassword"value="..."/> <property name="keystore"value="..."/> <property name="needClientAuth"value="..."/> <property name="truststore"value="..."/> </bean> </entry> </map> </property> </bean>
*来自 Camel 2.5,我们切换为使用 SslSelectChannelConnector *
<bean id="jetty" class="org.apache.camel.component.jetty.JettyHttpComponent"> <property name="sslSocketConnectors"> <map> <entry key="8043"> <bean class="org.eclipse.jetty.server.ssl.SslSelectChannelConnector"> <property name="password"value="..."/> <property name="keyPassword"value="..."/> <property name="keystore"value="..."/> <property name="needClientAuth"value="..."/> <property name="truststore"value="..."/> </bean> </entry> </map> </property> </bean>
作为上述映射中的键使用的值是您配置 Jetty 要侦听的端口。
173.9.1. 在 IBM Java 中使用 TLS 安全性配置 camel-jetty9
camel-jetty9
组件中的默认 TLS 安全设置与 IBM Java 虚拟机不兼容。IBM Java 中的所有密码都以 前缀 SSL_*
开头,甚至是 TLS 协议从 SSL_*
开始的密码。Camel-jetty9
仅支持 RFC Cipher Suite 名称,且所有 SSL_* 密码
都不受保护,且将被排除。Jetty 排除所有 SSL_*
密码,因此没有可用于 TLS 1.2 和连接失败的密码。因为无法更改 Jetty 的 ssl 上下文的行为,只有临时解决方案是覆盖 Jetty9 组件上的默认 TLS 安全配置。为达成此目标,请在 Application.java
文件中的"sslContextParameters ()"末尾添加以下代码。
FilterParameters fp = new FilterParameters(); fp.getInclude().add(".*"); // Exclude weak / insecure ciphers fp.getExclude().add("^.*_(MD5|SHA|SHA1)$"); // Exclude ciphers that don't support forward secrecy fp.getExclude().add("^TLS_RSA_.*$"); // The following exclusions are present to cleanup known bad cipher // suites that may be accidentally included via include patterns. // The default enabled cipher list in Java will not include these // (but they are available in the supported list). /* SSL_ ciphers are not excluded fp.getExclude().add("^SSL_.*$"); */ fp.getExclude().add("^.NULL.$"); fp.getExclude().add("^.anon.$"); p.setCipherSuitesFilter(fp);
此代码覆盖 Jetty 中定义的排除密码,方法是移除所有 SSL_*
密码的排除。