我正在尝试将图像上传到后备在线存储。我使用backblaze java-sdk进行了调用。尝试上传图片时,出现以下错误:
2020-04-25 11:19:45,443 ERROR [stderr] (default task-10) <B2Exception 904 io_exception: 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 talking to https://api.backblazeb2.com/b2api/v2/b2_authorize_account>
我找不到有关在backblaze网站上添加任何证书的必要性的任何信息。
经过互联网上的研究,我发现我应该?将backblaze证书添加到我的Java安装的信任库中。因此,我从https://www.backblaze.com/使用chrome(保存为.cer文件)下载了证书,并使用以下命令将其安装到了我的Java中:
keytool -import -alias backblaze -keystore "%JAVA_HOME%/jre/lib/security/cacerts" -storepass <password> -keypass changeit -file .../backblaze.cer -noprompt
执行此命令时,我也可以看到它:
keytool -list -v -keystore "%JAVA_HOME%/jre/lib/security/cacerts"
有一个别名条目:backblaze
在我的jboss启动过程中使用VM选项
-Djavax.net.debug=ssl
,我可以看到Java使用了正确的信任库并找到了带有backblaze别名的条目:2020-04-25 10:46:52,483 INFO [stdout] (default task-2) trustStore is: C:\Program Files\Java\jdk1.8.0_77\jre\lib\security\cacerts
2020-04-25 10:46:52,483 INFO [stdout] (default task-2) trustStore type is : jks
2020-04-25 10:46:52,483 INFO [stdout] (default task-2) trustStore provider is :
2020-04-25 10:46:52,484 INFO [stdout] (default task-2) init truststore
...
2020-04-25 10:46:52,564 INFO [stdout] (default task-2) adding as trusted cert:
2020-04-25 10:46:52,739 INFO [stdout] (default task-2) Subject: CN=backblaze.com, O="Backblaze, Inc.", L=San Mateo, ST=California, C=US, SERIALNUMBER=4337553, OID.1.3.6.1.4.1.311.60.2.1.2=Delaware, OID.1.3.6.1.4.1.311.60.2.1.3=US, OID.2.5.4.15=Private Organization
2020-04-25 10:46:52,739 INFO [stdout] (default task-2) Issuer: CN=DigiCert SHA2 Extended Validation Server CA, OU=www.digicert.com, O=DigiCert Inc, C=US
...
因此,我认为Java进程可以找到正确的证书,但是当我无法连接api.backblaze端点时,会收到握手异常:
2020-04-25 11:19:45,443 ERROR [stderr] (default task-10) <B2Exception 904 io_exception: 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 talking to https://api.backblazeb2.com/b2api/v2/b2_authorize_account>
2020-04-25 11:19:45,444 ERROR [stderr] (default task-10) at com.backblaze.b2.client.webApiHttpClient.B2WebApiHttpClientImpl.translateToB2Exception(B2WebApiHttpClientImpl.java:256)
2020-04-25 11:19:45,445 ERROR [stderr] (default task-10) at com.backblaze.b2.client.webApiHttpClient.B2WebApiHttpClientImpl.postAndReturnString(B2WebApiHttpClientImpl.java:223)
2020-04-25 11:19:45,445 ERROR [stderr] (default task-10) at com.backblaze.b2.client.webApiHttpClient.B2WebApiHttpClientImpl.postJsonAndReturnString(B2WebApiHttpClientImpl.java:185)
2020-04-25 11:19:45,445 ERROR [stderr] (default task-10) at com.backblaze.b2.client.webApiHttpClient.B2WebApiHttpClientImpl.postJsonReturnJson(B2WebApiHttpClientImpl.java:71)
2020-04-25 11:19:45,445 ERROR [stderr] (default task-10) at com.backblaze.b2.client.B2StorageClientWebifierImpl.authorizeAccount(B2StorageClientWebifierImpl.java:141)
2020-04-25 11:19:45,445 ERROR [stderr] (default task-10) at com.backblaze.b2.client.B2AccountAuthorizerSimpleImpl.authorize(B2AccountAuthorizerSimpleImpl.java:38)
2020-04-25 11:19:45,446 ERROR [stderr] (default task-10) at com.backblaze.b2.client.B2AccountAuthorizationCache.get(B2AccountAuthorizationCache.java:50)
2020-04-25 11:19:45,446 ERROR [stderr] (default task-10) at com.backblaze.b2.client.B2UploadUrlCache.get(B2UploadUrlCache.java:87)
2020-04-25 11:19:45,446 ERROR [stderr] (default task-10) at com.backblaze.b2.client.B2StorageClientImpl.lambda$uploadSmallFile$4(B2StorageClientImpl.java:207)
2020-04-25 11:19:45,446 ERROR [stderr] (default task-10) at com.backblaze.b2.client.B2Retryer.doRetry(B2Retryer.java:85)
2020-04-25 11:19:45,446 ERROR [stderr] (default task-10) at com.backblaze.b2.client.B2StorageClientImpl.uploadSmallFile(B2StorageClientImpl.java:204)
我是SSL新手,但我不明白自己在做什么错。我下载了错误的证书(并且api.backblaze有一个额外的证书,我必须安装)或我配置的Java信任库错误。
最佳答案
好吧,经过一番挣扎之后,我发现我使用了错误的vertical。我必须从api.backblazeb2.com下载证书并安装它:
下载:
keytool -printcert -sslserver api.backblazeb2.com:443 -rfc > api.backblazeb2.cer
安装:
keytool -import -alias api.backblazeb2 -keystore "%JAVA_HOME%/jre/lib/security/cacerts" -storepass changeit -keypass changeit -file api.backblazeb2.cer -nopro
mpt
为确保此后重启Java进程。