tomcat cannot connect to https site : SNI error

227 Views Asked by At

I have tomcat application running on Ubuntu. When it tries to make a https call to google recaptcha site, I get a error "No SNI provided, please fix client". The same code works fine outside tomcat when I run as a standalone application using same Java. Any ideas how to fix this. URL app is trying to connect : https://www.google.com/recaptcha/api/siteverify

Details :

Java version : openjdk version "1.8.0_352"
Tomcat Details :
Server version: Apache Tomcat/8.5.57
Server built:   Jul 16 2020 22:38:29 UTC
Server number:  8.5.57.0
OS Name:        Linux
OS Version:     5.15.0-1028-aws
Architecture:   amd64
JVM Version:    1.8.0_352-8u352-ga-1~20.04-b08
JVM Vendor:     Private Build

Java code :

public String webRequest(String url) {
    try {
        
        InputStream res = new URL(url).openStream();
        BufferedReader rd = new BufferedReader(new InputStreamReader(res, Charset.forName("UTF-8")));
        StringBuilder sb = new StringBuilder();
        int cp;
        while ((cp = rd.read()) != -1) {
            sb.append((char) cp);
        }
        res.close();
        return sb.toString();
    }catch (Exception e) {
        return "";
    }
}

Error:

javax.net.ssl|FINE|19|http-nio-8080-exec-8|2023-01-24 23:19:20.155 UTC|CertificateMessage.java:366|Consuming server Certificate handshake message (
"Certificates": [
  "certificate" : {
    "version"            : "v3",
    "serial number"      : "00 90 76 89 18 E9 33 93 A0",
    "signature algorithm": "SHA256withRSA",
    "issuer"             : "CN=invalid2.invalid, OU="No SNI provided; please fix your client."",
    "not before"         : "2015-01-01 24:00:00.000 UTC",
    "not  after"         : "2030-01-01 24:00:00.000 UTC",
    "subject"            : "CN=invalid2.invalid, OU="No SNI provided; please fix your client."",
    "subject public key" : "RSA",
    "extensions"         : [
0

There are 0 best solutions below