首页 > 解决方案 > 将证书添加到 Mirth Keystore

问题描述

这似乎应该是一件简单的事情。我希望能够信任来自 Mirth 所依赖的服务的证书,而无需修改全局 Java 证书存储(或为 SSL 插件删除每个实例的几个宏)。我尝试了以下方法:

生成我自己的密钥库:

键盘工具命令:

keytool -genkey -keystore appdata\my.jks -storetype PKCS12 -keyalg RSA -keysize 2048 -storepass xxxxxxxx
keytool -importcert -alias my-ca-cert -file myCaCert.pem -keystore appdata\my.jks -trustcacerts -storepass xxxxxxxx
keytool -importcert -alias my-server-cert -file myServerCert.pem -keystore appdata\my.jks -trustcacerts -storepass xxxxxxxx

欢乐属性:

keystore.path = ${dir.appdata}/my.jks
keystore.storepass = xxxxxxxx
keystore.keypass = xxxxxxxx
keystore.type = pkcs12

在这种情况下,Mirth 完全无法启动。日志中的第一个错误是

java.io.IOException: Invalid keystore format
  at com.sun.crypto.provider.JceKeyStore.engineLoad(JceKeyStore.java:724)
  at java.security.KeyStore.load(Unknown Source)
  at com.mirth.connect.server.MirthWebServer.createSSLConnector(MirthWebServer.java:370)
  at com.mirth.connect.server.MirthWebServer.<init>(MirthWebServer.java:150)
  at com.mirth.connect.server.Mirth.startWebServer(Mirth.java:385)
  at com.mirth.connect.server.Mirth.startup(Mirth.java:265)
  at com.mirth.connect.server.Mirth.run(Mirth.java:154)

更新 Mirth 内置密钥库:

键盘工具命令:

keytool -importcert -alias my-ca-cert -file myCaCert.pem -keystore appdata\keystore.jks -trustcacerts -storetype jceks -storepass xxxxxxxx
keytool -importcert -alias my-server-cert -file myServerCert.pem -keystore appdata\keystore.jks -trustcacerts -storetype jceks -storepass xxxxxxxx

欢乐属性:

keystore.path = ${dir.appdata}/keystore.jks
keystore.storepass = xxxxxxxx
keystore.keypass = xxxxxxxx
keystore.type = JCEKS

在这种情况下,Mirth 完全启动,但服务器证书无效。错误日志是

DETAILS:    JavaException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  at 69352923-b68f-4e96-95a3-ad7681a7f3c1_Deploy:112 (doScript)
  at 69352923-b68f-4e96-95a3-ad7681a7f3c1_Deploy:118
  at com.mirth.connect.server.util.javascript.JavaScriptUtil.executeScript(JavaScriptUtil.java:547)
  at com.mirth.connect.server.util.javascript.JavaScriptUtil$2.doCall(JavaScriptUtil.java:379)
  at com.mirth.connect.server.util.javascript.JavaScriptTask.call(JavaScriptTask.java:113)
  at java.util.concurrent.FutureTask.run(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)

更新 Java 全局密钥库

键盘工具命令:

keytool.exe -importcert -alias my-ca-cert -file myCaCert.pem -keystore cacerts -storepass xxxxxxxx
keytool.exe -importcert -alias my-server-cert -file myServerCert.pem -keystore cacerts -storepass xxxxxxxx

Mirth.properties:(同上)

keystore.path = ${dir.appdata}/keystore.jks
keystore.storepass = xxxxxxxx
keystore.keypass = xxxxxxxx
keystore.type = JCEKS

这可行但不可取,因为它使部署复杂化(我们无法控制客户环境),而且我不相信 Java 升级不会简单地覆盖存储。

标签: javasslmirth

解决方案


通过太多的试验和错误,这是我能够学到的

  1. 本机 Mirth 发送者/接收者自己使用 Mirth.properties 中定义的 Mirth Keystore。如上所述导入证书将适用于这些渠道。

  2. 如果您使用 Rhino 引擎(例如 Java/JavaScript)来发送/接收 http 请求,则忽略 Mirth 密钥库并使用全局 Java 存储。同样,上述过程有效。由于我的证书来自 Windows,事实证明我可以通过添加-Djavax.net.ssl.trustStoreType=WINDOWS-ROOT到 Mirth.properties 来简化一点,而不是让我的现场技术人员使用 Java 的 keytool

我最初没有看到 Mirth 频道工作的原因是因为我的频道的部署脚本从身份验证提供程序获取了访问令牌,并且我没有考虑独立测试频道发送者。我不认为我是以编程方式做事还是通过 UI 配置频道无关紧要,但是,这对你来说是 Mirth。:/

无论如何,希望有一天这会对某人有所帮助。


推荐阅读