繁体   English   中英

将证书与https URL关联

[英]Associate a certificate with a https url

我想连接到https://twitter.com/

URL url = new URL("https://twitter.com/");
HttpURLConnection uc1 = (HttpURLConnection) url.openConnection();

我验证了我的信任库和密钥库(及其密码)的位置,没关系。 我将Twitter证书和别名保存在密钥库和信任库中。 我验证了,它在里面。

我不知道如何将url与我保存的证书链接; 我得到错误:

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

我该怎么做?

****** UPDATE ********

我已经使用setProperty设置了信任库和密钥库。 当我在控制台上执行keytool -list -keystore .keystore时,我得到

...

twittercert,2岁。 2017年,trustCertEntry,Empreinte du certificat(SHA1):10:F0:40:F2:93:7F:E0:69:2D:C1:B9:8C:8B:32:CC:E0:1E:43:82:52

...

与keytool -list相同

Twitter证书由DigiCert颁发,作为JVM的默认信任库中的受信任根包含在内,因此您无需进行任何配置。

如果已配置自己的JKS信任库,则可能配置错误。 确保使用System.setProperty-D VM参数为信任库设置了正确的路径。

System.setProperty("javax.net.ssl.trustStore", trustStorePath); 
System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword)

还要验证信任库是否包含Digicert的证书

更新后请注意,您发布的Twitter证书的SHA-1指纹不等于今天提取的SHA-1指纹。 可能您有旧副本?

在此处输入图片说明

避免将此导入根目录CA而不是叶证书的信任库

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM