Good afternoon, as said in the title, I'm unable to connect to a subdomain on my caddy-powered website in my Android app. I'm migrating the backend of the app from Heroku to my own digitalocean droplet and the app used to work while it was using Heroku.
The error message I get is as follows:
W/System.err: javax.net.ssl.SSLException: hostname in certificate didn't match: <sub.domain.com> != <domain.com> OR <domain.com>
W/System.err: at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:185)
W/System.err: at org.apache.http.conn.ssl.BrowserCompatHostnameVerifier.verify(BrowserCompatHostnameVerifier.java:54)
W/System.err: at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:114)
W/System.err: at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:95)
W/System.err: at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:388)
W/System.err: at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
W/System.err: at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
W/System.err: at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
W/System.err: at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
The relevant Android code is:
try {
HttpClient client = new DefaultHttpClient();
final HttpPostHC4 post = new HttpPostHC4(url);
String json = "";
ArrayList<NameValuePair> nameValuePairs = new ArrayList<>();
for (Map.Entry<String, String> entry : valuePair.entrySet()) {
nameValuePairs.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
UrlEncodedFormEntityHC4 entity = new UrlEncodedFormEntityHC4(nameValuePairs, "UTF-8");
content = entity.getContent();
System.out.println(entity);
post.setEntity(entity);
final HttpResponse response = client.execute(post);
code = response.getStatusLine().getStatusCode();
responseText = EntityUtils.toString(response.getEntity());
} catch (Exception exc) {
exc.printStackTrace();
if (responseText != null) {
System.out.println(responseText);
}
}
And this is the relevant section of my Caddyfile
sub.domain.com {
root /var/www/sub.domain.com/public
log /var/www/sub.domain.com/storage/logs/caddy-access.log
errors /var/www/sub.domain.com/storage/logs/caddy-error.log
fastcgi / /run/php/php7.0-fpm.sock php {
index index.php
}
rewrite {
r .*
ext /
to /index.php?{query}
}
}
I can connect to the subdomain in my web browser, so I'm really not sure why this is happening. I'm not really too keen on disabling hostname verification, so I'm wondering if there's a way to fix it on the Caddy side.