英文:
SSLHanshakeException while establishing communication from Springboot service to 3rd part api using p12 keystore
问题
从我们的Springboot应用程序中,我们需要连接到第三方服务。我们已经从第三方供应商那里获得了p12证书。
我已经成功地通过浏览器和Postman客户端导入p12证书作为pfx文件来与该服务建立通信。
现在我正在尝试在我的服务中导入或使用这个P12证书进行通信。
但是一直在收到以下错误。
feign.RetryableException: sun.security.validator.ValidatorException: PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException: 无法找到到请求目标的有效认证路径
我尝试过的方法:
- 使用OpenSSL命令提取证书,并使用keytool从p12文件中导入jks信任库到我的一个文件夹中
-Djavax.net.ssl.keyStoreType=pkcs12
-Djavax.net.ssl.keyStore=C:\thirdparty.p12
-Djavax.net.ssl.keyStorePassword=<密码>
-Djavax.net.ssl.trustStoreType=jks
-Djavax.net.ssl.trustStore=C:\\thirdparty.jks
-Djavax.net.ssl.trustStorePassword=<密码>
- 根据指定创建了一个自定义的Feign配置
https://dzone.com/articles/ssl-based-feignclient-example-in-java-microcervice - 只在Dockerfile中导入了p12证书,并尝试运行Docker
RUN cd /usr/lib/jvm/java-1.8-openjdk/jre/bin && keytool -importkeystore -deststorepass changeit -
destkeypass changeit -destkeystore cacerts -deststoretype pkcs12 -srckeystore thirdparty.p12 -
srcstoretype PKCS12 -srcstorepass <密码>
所有方法都出现了相同的错误。
我认为我可能漏掉了一些可能很简单的东西。
问题:
- 当我从供应商那里获得p12文件时,是否需要单独创建一个信任库?
- 是否有办法只使用p12文件和密码来建立通信?
- 我需要在服务级别还是Feign客户端级别进行配置?
提前感谢。
英文:
From our Springboot application we need to connect to a 3rd party service. And we have the p12 certificate provided by the third party vendor.
I was successfully establish communication with this service via browser and postman client just by importing the p12 certificate as pfx file.
Now I am trying to import or use this P12 certificate in my service to communicate.
But keep getting the following error.
feign.RetryableException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Methods that I tried:
- using open ssl commands extracted the certificates and imported jks truststore from p12 file in one of my folders using keytool
-Djavax.net.ssl.keyStoreType=pkcs12
-Djavax.net.ssl.keyStore=C:\thirdparty.p12
-Djavax.net.ssl.keyStorePassword=<pwd>
-Djavax.net.ssl.trustStoreType=jks
-Djavax.net.ssl.trustStore=C:\\thirdparty.jks
-Djavax.net.ssl.trustStorePassword=<pwd>
- created a custom feignconfiguration as specified
https://dzone.com/articles/ssl-based-feignclient-example-in-java-microcervice - Just imported p12 certificate in dockerfile and tried running the docker
RUN cd /usr/lib/jvm/java-1.8-openjdk/jre/bin && keytool -importkeystore -deststorepass changeit -
destkeypass changeit -destkeystore cacerts -deststoretype pkcs12 -srckeystore thirdparty.p12 -
srcstoretype PKCS12 -srcstorepass <pwd>
everything gives the same error.
I think I am missing something that could be very simple too.
Questions:
- When I have p12 file from the vendor, do I need a separate truststore created for this?
- Is there way I can just use the p12 and the password to establish the communication ?
- Do I need to do the configuration in service level or in feign client level?
Thanks In advance.
答案1
得分: 1
-
在浏览器中打开URL并导出证书。
-
查找cacerts文件的位置:
示例:C:\Program Files(x86)\Java\jre1.6.0_22\lib\security\cacerts。
-
在命令行中将.cer文件导入cacerts:
keytool -import -alias example -keystore C:\Program Files (x86)\Java\jre1.6.0_22\lib\security\cacerts -file example.cer
注意:如果要求输入密码,请输入:changeit
重新启动您的JVM/计算机。
英文:
-
Open URL in your browser and export certificate.
-
Find location of cacerts files :
Example : C:\Program Files(x86)\Java\jre1.6.0_22\lib\security\cacerts.
-
Import the .cer file into cacerts in command line:
keytool -import -alias example -keystore C:\Program Files (x86)\Java\jre1.6.0_22\lib\security\cacerts -file example.cer
Note : If asked for password enter : changeit
Restart your JVM/PC.
答案2
得分: 0
感谢您的输入,Amit Kumar。
是的,通过在信任存储中导入证书,并按照我在问题中提到的那样提供密钥库,它可以工作。
但是,Springboot JPA Hikari 正在自动尝试验证我在 Java 命令行中提供的信任证书,因此服务器无法启动。
现在正在尝试解决这个问题。
英文:
Thank for your input Amit Kumar.
Yes it works by importing the certificates in Truststore and providing the keystore as I mentioned in my question.
But the Springboot JPA Hikari is automatically trying to verify the Trustcertificates that I provided in java command line and hence the server was not coming up.
Trying to resolve that problem now.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论