jonleech
jonleech

Reputation: 461

Https Connection rejected by server

I am trying to write a standalone program that will be called by a bat file. I found something like a trust all certificate manager.

TrustManager[] trustAllCerts = new TrustManager[]{
        new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            public void checkClientTrusted(
                    java.security.cert.X509Certificate[] certs, String authType) {
            }

            public void checkServerTrusted(
                    java.security.cert.X509Certificate[] certs, String authType) {
            }
        }
    };

// Install the all-trusting trust manager
        try {
            SSLContext sc = SSLContext.getInstance("SSL");
            sc.init(null, trustAllCerts, new java.security.SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

        URL url = new URL("--insert server url here--");
//url.openStream();
//  URLConnection urlConnection = url.openConnection();
            HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
} catch (MalformedURLException mfe) {
            mfe.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

it works fine in my ide but after I built in and run it via the bat file it keeps giving me this error

javax.net.ssl.SSLException: Server key
        at sun.security.ssl.Handshaker.throwSSLException(Unknown Source)
        at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
        at sun.security.ssl.Handshaker.processLoop(Unknown Source)
        at sun.security.ssl.Handshaker.process_record(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source
)
        at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
        at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown So
urce)
        at java.net.HttpURLConnection.getResponseCode(Unknown Source)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unk
nown Source)
        at sss.Sss.main(Sss.java:65)
Caused by: java.security.NoSuchAlgorithmException: NONEwithRSA Signature not ava
ilable
        at java.security.Signature.getInstance(Unknown Source)
        at sun.security.ssl.JsseJce.getSignature(Unknown Source)
        at sun.security.ssl.RSASignature.<init>(Unknown Source)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance0(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at java.security.Provider$Service.newInstance(Unknown Source)
        at sun.security.jca.GetInstance.getInstance(Unknown Source)
        at java.security.Signature.getInstance(Unknown Source)
        at sun.security.ssl.JsseJce.getSignature(Unknown Source)
        at sun.security.ssl.RSASignature.getInstance(Unknown Source)
        at sun.security.ssl.HandshakeMessage$DH_ServerKeyExchange.<init>(Unknown
 Source)
        ... 13 more

am I doing something wrong? Should I sign a certificate in order to connect to the server?

Upvotes: 2

Views: 781

Answers (1)

jonleech
jonleech

Reputation: 461

Have found the answer for the problem above, will need to include the sunjce_provider.jar into the lib folder of the standalone program.

Upvotes: 1

Related Questions