我在爲我的服務器通過互聯網同步數據的android寫簡單的記事本。我使用https和startssl的免費證書,一切都很順利。後來,我用自己的SSL證書添加了新的虛擬主機,並且我的應用程序突然停止了服務器。它拋出:Java SSLException:證書中的主機名不匹配。非常錯誤的證書?
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來涵蓋多個端點? – 2014-10-20 23:20:20
由於SSL驗證在重定向之前發生,所以它會失敗並在開始時停止。 – Dzarafata 2014-10-21 08:47:35