使用Fuel Kotlin库时,如何配置信任库的路径?

问题描述

背景

我正在使用kotlin Fuel库(https://github.com/kittinunf/fuel

我需要致电支持SSL的网站。 我不需要提供客户证书。 我只需要验证服务器的SSL证书。 我已使用以下命令将服务器的证书导入密钥库:

keytool -trustcacerts -keystore mykeystore.jks -storepass changeit -importcert -file "server.crt"

要求

我想在配置中指定mykeystore.jks的位置,并通过代码将信任库加载到FuelManager中。 我该怎么办?

我尝试了什么?

我成功使用此解决方案绕过了证书验证:

kotlin library that can do httpS connection without certificate verification (like curl --insecure)

这有效。

然后,我尝试构建自己的密钥库,从文件中加载它,并将其提供给FuelManager。

这行不通。

这是我使用的代码

private fun createFuelManager(): FuelManager {
   return FuelManager().apply {
     val ks: KeyStore = KeyStore.getInstance("JKS")
     ks.load(FileInputStream(<path to truststore.jks>),"changeit".tochararray())

     // sets the keystore field of the new FuelManager

     keystore = ks 
  }
}

在我的代码中,我调用createFuelManager()并使用它执行我的请求。 我收到以下错误

pkix path building Failed unable to find valid certification path to requested target

注意

在我的尝试中,我验证了密钥存储区已成功在上面提供的代码中加载。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)