【发布时间】:2014-12-16 00:09:46
【问题描述】:
我正在为 android 编写简单的记事本,通过互联网与我的服务器同步数据。我使用了来自startssl的https和免费证书,一切都很顺利。后来我用它自己的 ssl 证书添加了新的虚拟主机,我的应用程序突然停止连接到服务器。它抛出:
javax.net.ssl.SSLException: hostname in certificate didn't match: <www.rapidnote.emendus.ovh> != <othersite.emendus.ovh> OR <othersite.emendus.ovh> OR <emendus.ovh>
它尝试验证来自不同 apache 虚拟主机的完全不同的证书。我对 rapidnote 虚拟主机的 apache 配置是:
<VirtualHost *:80>
ServerName rapidnote.emendus.ovh
ServerAlias www.rapidnote.emendus.ovh
Redirect Permanent / https://www.rapidnote.emendus.ovh
</VirtualHost>
<VirtualHost *:443>
ServerName rapidnote.emendus.ovh
DocumentRoot /var/www/rapidnote
SSLEngine on
SSLCertificateFile cert_location/rapidnote.emendus.ovh.crt
SSLCertificateKeyFile key_location/rapidnote.emendus.ovh.key
SSLCertificateChainFile cert_location/sub.class1.server.ca.pem
</VirtualHost>
<VirtualHost *:443>
ServerName www.rapidnote.emendus.ovh
DocumentRoot /var/www/rapidnote
SSLEngine on
SSLCertificateFile cert_location/www.rapidnote.emendus.ovh.crt
SSLCertificateKeyFile key_location/www.rapidnote.emendus.ovh.key
SSLCertificateChainFile cert_location/sub.class1.server.ca.pem
</VirtualHost>
我的代码如下所示:
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("https://www.rapidnote.emendus.ovh/" + paramScriptName);
HttpResponse response = httpClient.execute(httpPost);
如果我在 apache 中关闭 othersite.emendus.ovh 虚拟主机,那么 SSLException 消息会显示:
<www.rapidnote.emendus.ovh> != <rapidnote.emendus.ovh> OR <rapidnote.emendus.ovh> OR <emendus.ovh>
如果然后我将"https://www.rapidnote.emendus.ovh/" 更改为"https://rapidnote.emendus.ovh/",它就会开始工作。我检查了(www. 和非 www)证书,两者中的通用名称都是正确的。
我认为它应该验证我在HttpPost 构造函数中给他的域证书,而不是来自我的服务器的其他随机证书...
我使用了一些测试网站来验证我的 ssl 配置,它说一切都很好。
一切都发生在android 4.2.2 (API 17)。
我用min SDK 14 和target SDK API 20 Android 4.4 (KitKat Wear) 构建应用程序
我如何告诉他验证为此域指定的正确证书? 是应用现场的问题还是apache的问题?
【问题讨论】:
-
为什么不将所有 :80 请求和 :443 www 请求重定向到单个 443 rapidnote.emendus.ovh 地址,而不是尝试使用单个 SSL 覆盖多个端点?
-
因为 SSL 验证发生在重定向之前,所以它会失败并在开始时停止。