我正在尝试将图像上传到 backblaze 在线存储。我使用 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 安装的信任库中。所以我使用 chrome 从https://www.backblaze.com/下载了证书(另存为 .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 信任库错误。