I'm writing simple notepad for android that sync data over internet with my server. I used https and free certificate from startssl and everything worked smooth. Later I added new virtualhost with it's own ssl certificate and my app suddenly stoped connscting to server. It throws:
javax.net.ssl.SSLException: hostname in certificate didn't match: <www.rapidnote.emendus.ovh> != <othersite.emendus.ovh> OR <othersite.emendus.ovh> OR <emendus.ovh>
It tries to verify totally different certificate from different apache virtual host. My apache config for rapidnote virtual host is:
<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>
My code looks following:
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("https://www.rapidnote.emendus.ovh/" + paramScriptName);
HttpResponse response = httpClient.execute(httpPost);
If i turn off othersite.emendus.ovh
virtual host in apache, then SSLException message says:
<www.rapidnote.emendus.ovh> != <rapidnote.emendus.ovh> OR <rapidnote.emendus.ovh> OR <emendus.ovh>
and if then I change "https://www.rapidnote.emendus.ovh/"
to "https://rapidnote.emendus.ovh/"
, it starts to work. I checked both (www. and non www) certificates and common names in both are correct.
I think it should verify a certificate for domain that I gave him in HttpPost
constructor, not some other random cert from my server...
I used some testing website to verify my ssl configuration and it stated that it's all fine.
Everything happend on android 4.2.2 (API 17)
.
I build app with min SDK 14
and target SDK API 20 Android 4.4 (KitKat Wear)
How can I tell him to verify correct cert, specified for this domain? Is the problem on site of application or apache?