java - 找不到与 ex.ample.com 匹配的主题备用 DNS 名称

标签 java security ssl ssl-certificate

对于我在 ex.ample.com 上运行的应用程序,我有以下来自 StartSSL/StartCom 的证书:

Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 163069 (0x27cfd)
        Signature Algorithm: sha1WithRSAEncryption
        Issuer: C=IL, O=StartCom Ltd., OU=Secure Digital Certificate Signing, CN=StartCom Class 1 Primary Intermediate Server CA
        Validity
            Not Before: Nov 27 21:26:01 2010 GMT
            Not After : Nov 29 15:32:05 2011 GMT
        Subject: description=303703-Sv1xMdnmzg6garMt, C=NL, O=Persona Not Validated, OU=StartCom Free Certificate Member, CN=ex.ample.com/emailAddress=postmaster@ex.ample.com
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
            RSA Public Key: (2048 bit)
                Modulus (2048 bit):
                    ....
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            X509v3 Key Usage: 
                Digital Signature, Key Encipherment, Key Agreement
            X509v3 Extended Key Usage: 
                TLS Web Server Authentication
            X509v3 Subject Key Identifier: 
                31:68:B2:7B:A2:7C:79:54:B7:3E:66:FD:12:04:18:FC:FB:9B:34:64
            X509v3 Authority Key Identifier: 
                keyid:EB:42:34:D0:98:B0:AB:9F:F4:1B:6B:08:F7:CC:64:2E:EF:0E:2C:45

            X509v3 Subject Alternative Name: 
                DNS:ex.ample.com, DNS:ample.com
            X509v3 Certificate Policies: 
                Policy: 1.3.6.1.4.1.23223.1.2.2
                  CPS: http://www.startssl.com/policy.pdf
                  CPS: http://www.startssl.com/intermediate.pdf
                  User Notice:
                    Organization: StartCom Ltd.
                    Number: 1
                    Explicit Text: Limited Liability, see section *Legal Limitations* of the StartCom Certification Authority Policy available at http://www.startssl.com/policy.pdf

            X509v3 CRL Distribution Points: 
                URI:http://www.startssl.com/crt1-crl.crl
                URI:http://crl.startssl.com/crt1-crl.crl

            Authority Information Access: 
                OCSP - URI:http://ocsp.startssl.com/sub/class1/server/ca
                CA Issuers - URI:http://www.startssl.com/certs/sub.class1.server.ca.crt

            X509v3 Issuer Alternative Name: 
                URI:http://www.startssl.com/
    Signature Algorithm: sha1WithRSAEncryption
        .....

我已正确安装此证书。当我使用 Firefox 访问该应用程序时,它会起作用。 但是,当我使用 Java 的 HttpURLConnection 从中检索页面时,出现以下错误:

Caused by: java.security.cert.CertificateException: No subject alternative DNS name matching ex.ample.com found.
    at sun.security.util.HostnameChecker.matchDNS(HostnameChecker.java:208)
    at sun.security.util.HostnameChecker.match(HostnameChecker.java:94)
    at sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:285)
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:271)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1012)
    ... 14 more

我不明白为什么会这样。 ex.ample.com 是证书中的通用名称 (CN),也列在 SAN 中。 我已经在我的信任库中导入了 StarSLL 的证书,所以这不是这里的问题。

最佳答案

不确定您是否仍在寻找答案。可能不会!

这里的问题是您证书中的 DNS 条目与您在应用程序中提供的服务器/主机名不匹配。您的代码在某处进行了主机名验证。删除那段代码或将您提供的主机名更改为证书中的 DNS 名称。

关于java - 找不到与 ex.ample.com 匹配的主题备用 DNS 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4297555/

相关文章:

java - 无需类即可从 span 获取内容?

java - 实例化 RobotFixture 的新实例以传递给构造函数

javascript - HP Fortify 问题,可能存在 XSS 漏洞?

ruby-on-rails - Rails Neo4j 结构错误中没有成员 'ssl' 是什么意思

java - 查找 ""之间字符串的正则表达式是什么

java - 检查从连接到服务器套接字java的所有套接字接收信息

javascript - Flash 播放器不允许脚本

php - 保护服务器上的一个特定文件; .htaccess 有什么好办法吗?

ssl - 网盘控制面板 Windows 7

ssl - 使用 Erlang 无需验证即可获取客户端证书