0

While sending a get request to www.sunnyportal.com the error code appeared in the console, it is as follows:

    javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1979)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1086)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1301)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at personal.Project.GetUrl.getReq(GetUrl.java:25)
at personal.Project.GetUrl.main(GetUrl.java:34)

I tried the following pages with no luck:

+Received fatal alert: handshake_failure through SSLHandshakeException

+How to solve javax.net.ssl.SSLHandshakeException Error?

Here is my code:

package personal.Project;

    import java.io.IOException;

    import java.io.InputStream;

    import java.net.MalformedURLException;

    import java.net.URL;

    import java.net.URLConnection;

    import java.net.URLEncoder;

    public class GetUrl {

        private String url = "https://www.sunnyportal.com/Templates/ChartValues.aspx";

private String charset = "UTF-8";  // Or in Java 7 and later, use the constant: java.nio.charset.StandardCharsets.UTF_8.name()
private String login = "<>";
private String password = "<>";

public String getReq() throws MalformedURLException, IOException
{
    String query = String.format("login=%s&password=%s", 

            URLEncoder.encode(login, charset), 
            URLEncoder.encode(password, charset));

        URLConnection c = new URL(url + "?" + query).openConnection();
        c.setRequestProperty("Accept-Charset", charset);
        InputStream response = c.getInputStream();  

        return response.toString();
}
public static void main (String args[])
{
    GetUrl data = new GetUrl();
    String getString = null;
    try {
        getString = data.getReq();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.exit(1);
    }

    System.out.println( getString );
}

}

Would love help with this problem, Thanks in advance!

Community
  • 1
  • 1

1 Answers1

2

According to https://www.ssllabs.com/ssltest/analyze.html?d=sunnyportal.com that server negotiates only one ciphersuite, TLS_RSA_WITH_AES_256_CBC_SHA, which uses AES with 256-bit key.

If you are using Oracle Java to use any symmetric cipher above 128 bits, which includes AES 256, you must download and install the JCE Unlimited Strength Jurisdiction Policy Files for your version. For the currently supported version, 8, near the bottom of the general download page http://www.oracle.com/technetwork/java/javase/downloads/index.html it links to http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html . For older versions search finds http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html and http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html .

PS: dupe of SSLHandshakeException while connecting to a https site although I'm not sure you could have been expected to find that.

Community
  • 1
  • 1
dave_thompson_085
  • 24,048
  • 4
  • 34
  • 52
  • Now that I have the file is there a certain folder that I have to put it into? or do I just up and run it? – Peter Sparks Nov 29 '15 at 21:05
  • @PeterSparks you unzip it (on modern Windows opening in explorer does this) and put the two 'jar's into your JRE's `lib/security` directory replacing the 'limited' ones. Where your JRE is varies quite a lot depending on your platform and (often) how you installed it, which you didn't say. There's also a README file inside the zip that tries to explain this, but still doesn't cover all possible cases. – dave_thompson_085 Nov 30 '15 at 14:12