ssl - Java - HTTPS GET call fails from EC2 instance with handshake_failure, works locally -


i'm running out of ideas, why i'm asking here. have small class rest call on https. i'm doing kind of scraping, , avoid installing ssl certificates if possible.

the code works locally (both eclipse , standalone tomcat), fails javax.net.ssl.sslhandshakeexception: received fatal alert: handshake_failure every time when running aws ec2 instance.

code is:

// apiurl looks https://hsreplay.net/api/v1/games/jdubsjsecbl5rct7dgmxrn private string restgetcall(string apiurl) throws exception {     system.setproperty("javax.net.debug", "all");     sslcontextbuilder builder = new sslcontextbuilder();     builder.loadtrustmaterial(null, new trustselfsignedstrategy());     sslconnectionsocketfactory sslsf = new sslconnectionsocketfactory(builder.build(),             sslconnectionsocketfactory.allow_all_hostname_verifier) {         @override         protected void preparesocket(sslsocket socket) throws ioexception {             try {                 log.debug("************ setting socket host property *************");                 propertyutils.setproperty(socket, "host", "hsreplay.net");                 socket.setenabledprotocols(new string[] { "sslv3", "tlsv1", "tlsv1.1", "tlsv1.2" });             }             catch (illegalaccessexception | nosuchmethodexception | invocationtargetexception ex) {                 log.error(ex.getmessage());                 slacknotifier.notifyerror(ex);             }             super.preparesocket(socket);         }      };     closeablehttpclient httpclient = httpclients.custom().setsslsocketfactory(sslsf).build();      httpget httpget = new httpget(apiurl);     closeablehttpresponse response1 = httpclient.execute(httpget);     stringbuilder result = new stringbuilder();     try {         system.out.println(response1.getstatusline());         httpentity entity1 = response1.getentity();         bufferedreader rd = new bufferedreader(new inputstreamreader(entity1.getcontent()));         string line;         while ((line = rd.readline()) != null) {             result.append(line);         }         // useful response body         // , ensure consumed         entityutils.consume(entity1);     }     {         response1.close();     } } 

i tried basic version (without override of sslfactory methods), no avail.

also, don't manage logs javax.net.debug on tomcat (neither on remote nor on local one), if have idea here useful.

please let me know if can provide more information, , lot help!

sébastien

handshake failures might caused lots of different reasons, wrong java version, server settings, setting hostname verifier (bad idea anyway), sni ... . current information in question not enough sure problem is.

when looking @ ssllabs report server 2 information interesting:

  • the server needs sni.
  • the server supports ecdhe ciphers.

the first might problem older java versions or jdk8 if set hostname verifier (which although not necessary site).

the second might problem older java version or if cryptography extensions unlimited strength not installed.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -