Solved

java.net.ProtocolException: Can't reset method: already connected

Posted on 2011-09-27
25
4,457 Views
Last Modified: 2012-06-27
Hello everyone!

I get the following exception when I run my application under Netbeans.

java.net.ProtocolException: Can't reset method: already connected

Your input would be greatly appreciated!

Thanks

Here's the code associated with that exception!
package gimp;

/**
 *
 * @author sam
 */
import java.net.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.io.*;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
import sun.misc.BASE64Encoder;

public class EstablishConnection {
   
    public EstablishConnection(String username, char [] password, String host, String port) {
        this.userName = username;
        this.password = password;
        this.host = host;
        if (port != null)
            this.port = port;
    }
   
   
    public static class MyHostnameVerifier implements HostnameVerifier {
        public boolean verify(String hostname, SSLSession session) {
            // verification of hostname is switched off
            return true;
        }
    }

   
    public void setConnection() throws Exception {
       
        // connection and authentication

        Map paramNameToValue = new HashMap(); // parameter name to value map
        String URL_BASE = "https://";
        String method = "POST";
        String authentication = userName + ':' + password;

        final String HTTP_MODE_POST = "POST";
        command = "gs";
        // construct URL
        StringBuffer params = new StringBuffer();
       
        if (paramNameToValue.keySet().size() > 0) {
            boolean isFirstParam = true;
            for (Iterator paramIter = paramNameToValue.keySet().iterator();paramIter.hasNext();) {
                String paramStr = (String)paramIter.next();
                if (isFirstParam) {
                    params.append("?" + paramStr);
                    isFirstParam = false;
                } else {
                    params.append("&" + paramStr);
                }
                params.append("=" +
                        URLEncoder.encode((String)paramNameToValue.get(paramStr),"UTF-8"));
            }
        }
        URL url = null;
        if (method.equals(HTTP_MODE_POST))
            url = new URL(URL_BASE + host + ':' + port + "/services/gimp/result.php/" + command);
        else
            url = new URL(URL_BASE + host + ':' + port +
                    "/services/gimp/result.php/" + command + params.toString());
        // open HTTPS connection
        HttpURLConnection connection = null;
        connection = (HttpsURLConnection)url.openConnection();
        ((HttpsURLConnection) connection).setHostnameVerifier(new MyHostnameVerifier());
        //connection.setRequestProperty("Content-Type", "text/plain; charset=\"utf8\"");
        connection.getContentType();
        connection.setRequestMethod(method);
        BASE64Encoder encoder = new BASE64Encoder();
        String encoded = encoder.encode((authentication).getBytes("UTF-8"));
        connection.setRequestProperty("Authorization", "Basic " + encoded);
        int returnCode = connection.getResponseCode();
        InputStream connectionIn = null;
        if (returnCode==200)
            connectionIn = connection.getInputStream();
        else
            connectionIn = connection.getErrorStream();
        // print resulting stream
        BufferedReader buffer = new BufferedReader(new InputStreamReader(connectionIn));
        String inputLine;
        while ((inputLine = buffer.readLine()) != null)
            System.out.println(inputLine);
        buffer.close();  
    }
 
   
    //Defining local variables
    String userName;
    char [] password;
    String host;
    String port = "443";
    String command;
}
0
Comment
Question by:snajalm
  • 10
  • 10
  • 5
25 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36708207

do you know which line throws this exception and
can you post the stacktrace ?

It looks like sometimes this eroor happens if you try to establish the saem connection again, while previous
is still active
0
 

Author Comment

by:snajalm
ID: 36708249
I'm making a call to this method via an Action event within another class,

try {
            conn.setConnection();
        } catch(Exception e) {
            System.out.println(e.toString());
        }

I'm not sure how to trace this withing the IDE or the code itself!  If you let me know I can perform this operation for you to help identifying the problem!
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36708267
Yes, you add
e.printStackTrace();
after System.out.println(e.toString())
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36708299
>>
try {
            conn.setConnection();
        } catch(Exception e) {
            System.out.println(e.toString());
        }
>>

Don't do that - it's not going to give you enough info. e.toString is redundant as that should be
e.printStackTrace();

Open in new window

0
 

Author Comment

by:snajalm
ID: 36708302
I have added the following line in bold to the code,

connection.setRequestProperty("Authorization", "Basic " + encoded);
connection.connect();
((HttpsURLConnection) connection).setHostnameVerifier(new MyHostnameVerifier());

And after adding e.printStackTrace(); to the catch clause I got the following list,

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
      at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1649)
      at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:241)
      at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:235)
      at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1206)
      at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:136)
      at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:593)
      at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:529)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:893)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1165)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1149)
      at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434)
      at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
      at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:133)
      at ida.EstablishDMZConnection.setDMZConnection(EstablishDMZConnection.java:84)
      at ida.IDAView.jButton_UserInfo_Next_NewPageActionPerformed(IDAView.java:644)
      at ida.IDAView.access$800(IDAView.java:33)
      at ida.IDAView$4.actionPerformed(IDAView.java:223)
      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
      at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
      at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
      at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
      at java.awt.Component.processMouseEvent(Component.java:6289)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
      at java.awt.Component.processEvent(Component.java:6054)
      at java.awt.Container.processEvent(Container.java:2041)
      at java.awt.Component.dispatchEventImpl(Component.java:4652)
      at java.awt.Container.dispatchEventImpl(Container.java:2099)
      at java.awt.Component.dispatchEvent(Component.java:4482)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
      at java.awt.Container.dispatchEventImpl(Container.java:2085)
      at java.awt.Window.dispatchEventImpl(Window.java:2478)
      at java.awt.Component.dispatchEvent(Component.java:4482)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
      at java.awt.EventQueue.access$000(EventQueue.java:85)
      at java.awt.EventQueue$1.run(EventQueue.java:603)
      at java.awt.EventQueue$1.run(EventQueue.java:601)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
      at java.awt.EventQueue$2.run(EventQueue.java:617)
      at java.awt.EventQueue$2.run(EventQueue.java:615)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
      at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:323)
      at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:217)
      at sun.security.validator.Validator.validate(Validator.java:218)
      at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126)
      at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209)
      at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)
      at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1185)
      ... 50 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
      at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174)
      at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238)
      at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:318)
      ... 56 more

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36708313
Looks like you need to import the cert into your trust store
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36708329
This looks like aboslutely different error about authentication ?
And what about your previous Protocol exception ?
0
 

Author Comment

by:snajalm
ID: 36708388
I know "for_yan" and that it because I entered connection.connect(); inside the code which apparently fixed the previous exception but got me a few more, the main one being,

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Now I have no idea how to get around this one, ANY SUGGESTIONS?!

Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36708400
>>Now I have no idea how to get around this one, ANY SUGGESTIONS?!

I just told you the reason for the error
0
 
LVL 47

Accepted Solution

by:
for_yan earned 250 total points
ID: 36708414
0
 

Author Comment

by:snajalm
ID: 36709049
Thanks "CEHJ" for pointing out to the issue and "for_yan" for these great links.  However, it all seem a bit confusing to me since I don't have much knowledge and experience with SSL handshake.  I'm writing this little application where it should receive username, password, https address from the user and make the connection to the server to retrieve certain files.  That code that I put up there is the connection module which would need to automatically handle the SSL handshake based on a random URL entered by the user.  So it could be any server the client would want to link into.  

Now my question is that how would it be possible to embed this code into my application so that the certificates are acquired each time a different request is made??!
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
ID: 36709347
>>
Now my question is that how would it be possible to embed this code into my application so that the certificates are acquired each time a different request is made??!
>>

If the cert is not correct (i.e. untrusted) the only thing you can do is to install your own TrustManager that can ignore the fact the server cert is untrusted

http://www.exampledepot.com/egs/javax.net.ssl/TrustAll.html
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:snajalm
ID: 36716430
Thanks CEHJ!  This is a useful routine if you just plan to test, however, I would need to validate certificates for each of those servers entered.  I thought I might be able to modify the "InstallCert.java" code as an internal class so that whenever a new server is entered the keyStore file gets updated and used and that was exactly what I did.  I cut and pasted the contents of the InstallCert.java into a class with the same name under my own package as follows,

Now theoretically everytime there is a new host, the cert for that server should be installed or updated accordingly.  Running the code, however, renders me with the following exception which I hope you'd as usual be kind enough to help me with,

java.io.EOFException
.
.
and a whole lot of exceptions relating to this one

which I think it means that the "jssecacerts" is created but for some reason can't be filled in and I can't see the reason why!

InstallCertModified.java
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36716452
Again, please post full stack traces

>>I would need to validate certificates for each of those servers entered.

Not entirely certain what you're doing, but of course if you know ahead of time which servers you're going to need to deal with, then you can just decide to trust them with a TrustManager. If otoh you *don't* know, how are you going to know that they are trustworthy enough to use your modified InstallCert on?
0
 

Author Comment

by:snajalm
ID: 36716513
Loading KeyStore jssecacerts...
java.io.EOFException
      at java.io.DataInputStream.readInt(DataInputStream.java:375)
      at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:628)
      at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:38)
      at java.security.KeyStore.load(KeyStore.java:1185)
      at ida.InstallCert.addServerCertificate(InstallCert.java:87)
      at ida.IDAView.jButton_UserInfo_Next_NewPageActionPerformed(IDAView.java:640)
      at ida.IDAView.access$800(IDAView.java:33)
      at ida.IDAView$4.actionPerformed(IDAView.java:223)
      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
      at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
      at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
      at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
      at java.awt.Component.processMouseEvent(Component.java:6289)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
      at java.awt.Component.processEvent(Component.java:6054)
      at java.awt.Container.processEvent(Container.java:2041)
      at java.awt.Component.dispatchEventImpl(Component.java:4652)
      at java.awt.Container.dispatchEventImpl(Container.java:2099)
      at java.awt.Component.dispatchEvent(Component.java:4482)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
      at java.awt.Container.dispatchEventImpl(Container.java:2085)
      at java.awt.Window.dispatchEventImpl(Window.java:2478)
      at java.awt.Component.dispatchEvent(Component.java:4482)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
      at java.awt.EventQueue.access$000(EventQueue.java:85)
      at java.awt.EventQueue$1.run(EventQueue.java:603)
      at java.awt.EventQueue$1.run(EventQueue.java:601)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
      at java.awt.EventQueue$2.run(EventQueue.java:617)
      at java.awt.EventQueue$2.run(EventQueue.java:615)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
got here!
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
      at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1649)
      at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:241)
      at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:235)
      at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1206)
      at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:136)
      at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:593)
      at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:529)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:893)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1165)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1149)
      at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434)
      at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
      at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1014)
      at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
      at ida.EstablishDMZConnection.setDMZConnection(EstablishDMZConnection.java:141)
      at ida.IDAView.jButton_UserInfo_Next_NewPageActionPerformed(IDAView.java:651)
      at ida.IDAView.access$800(IDAView.java:33)
      at ida.IDAView$4.actionPerformed(IDAView.java:223)
      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
      at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
      at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
      at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
      at java.awt.Component.processMouseEvent(Component.java:6289)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
      at java.awt.Component.processEvent(Component.java:6054)
      at java.awt.Container.processEvent(Container.java:2041)
      at java.awt.Component.dispatchEventImpl(Component.java:4652)
      at java.awt.Container.dispatchEventImpl(Container.java:2099)
      at java.awt.Component.dispatchEvent(Component.java:4482)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
      at java.awt.Container.dispatchEventImpl(Container.java:2085)
      at java.awt.Window.dispatchEventImpl(Window.java:2478)
      at java.awt.Component.dispatchEvent(Component.java:4482)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
      at java.awt.EventQueue.access$000(EventQueue.java:85)
      at java.awt.EventQueue$1.run(EventQueue.java:603)
      at java.awt.EventQueue$1.run(EventQueue.java:601)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
      at java.awt.EventQueue$2.run(EventQueue.java:617)
      at java.awt.EventQueue$2.run(EventQueue.java:615)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
      at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:323)
      at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:217)
      at sun.security.validator.Validator.validate(Validator.java:218)
      at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126)
      at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209)
      at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)
      at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1185)
      ... 51 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
      at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174)
      at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238)
      at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:318)
      ... 57 more
BUILD SUCCESSFUL (total time: 27 seconds)
0
 

Author Comment

by:snajalm
ID: 36716527
I do trust the servers but I would need to ensure secure transactions between the servers and client who's trying to access information via this client application I'm writing.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
ID: 36716801
>>I do trust the servers but I would need to ensure secure transactions between the servers and client who's trying to access information via this client application I'm writing.

You would still get that. The only purpose of installing the cert into the trust store is to save the trouble of deciding whether to trust the server and writing the code to get into a position to do that.

If the code to import the cert automatically is proving more difficult than the code i just mentioned, wouldn't it be easier to take the line of least resistance.

A more subtle point - if you think about it, the fact that the cert needs importing at all is because it's not a 'proper' cert, i.e. potentially insecure. It's less secure to import it in those circumstances than to allow ad hoc trust with your own trust manager.
0
 

Author Comment

by:snajalm
ID: 36717319
Thank you CEHJ for your valuable comments and I can understand where you're coming from, however, I've become very curious to know how to make this thing work anyway.  Well I managed to make this modified InstallCert work and dynamically update the keystore under the project directory under the name "jssecacerts".  Now I'm getting this exceptions which apparently means that the application can't find the certificate file containing the certificate associated with the server I'm trying to connect to.

How would it be possible under Netbeans to point to the location of the new keystore so that my application can pick that up??!

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification

Solving the issue would definitely end all the exceptions!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36717588
>>How would it be possible under Netbeans to point to the location of the new keystore so that my application can pick that up??!

Set something like the following as a jvm arg
-Djava.net.ssl.trustStore=/foo/bar/jssecacerts

Open in new window

0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
ID: 36717597
Oops
-Djavax.net.ssl.trustStore=/foo/bar/jssecacerts

Open in new window

0
 

Author Comment

by:snajalm
ID: 36717981
Yep, it worked just right as expected and I'm getting data off the server.   Just having some minor authentication issues which is nothing serious,

Thanks so much for helping me with the task, you're a super star...

Just as a final question,

What happens if I package this application and run it off the client's machine running either apple or windows?!  Would this still point to the right place or it has to be configured manually every time??!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36718042
The cert has to be imported (if it's not a 'proper' one) each time into the trust store. You can make that easier by starting the whole thing up with Ant, with which you can handle certs, but that's another topic.
0
 

Author Closing Comment

by:snajalm
ID: 36812977
I would like to give my warmest thanks to "for_yan" and "CEHJ" for their most valuable help!  Thanks "for_yan" for linking me to the right lead and many thanks to "CEHJ" for providing more valuable input, keeping up with me through the rest of this task and helping me complete it even though my knowledge of the mentioned technologies was limited!  I hope you keep contributing to this forum and benefit many others such as myself!

All the best
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36812998
Thanks for the kind words. Good luck!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36813211
Yes, of course i told you right away what the  problem was after you'd posted the stack trace -  http:#36708313 ;)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now