1 Reply Latest reply on Feb 20, 2017 7:02 AM by demirhan

    connection with ssl fails with java.security.KeyStoreException: jks not found

    demirhan

      Hi,

      I'm using smack 4.2.0-rc3 when I am trying to connect to my server with this code;

       

      builder.setHost(mServiceName);

      builder.setUsernameAndPassword(mUsername, mPassword);

      builder.setSecurityMode(ConnectionConfiguration.SecurityMode.required);

      try {

          builder.setXmppDomain(JidCreate.domainBareFrom(mServiceName));

      }

      catch (XmppStringprepException e){

          e.printStackTrace();

      }

      HostnameVerifier hostnameVerifier = new HostnameVerifier() {

          @Override

          public boolean verify(String hostname, SSLSession session)

          {

              if (mServiceName.equals(hostname))

              {

                  return true;

              }

              else

              {

                  Log.e(TAG,"Hostname is not correct: "+ hostname);

                  return false;

              }

          }

      };

      builder.setHostnameVerifier(hostnameVerifier);

       

       

      when I am trying to connect I am getting this error

       

      W/System.err: org.jivesoftware.smack.SmackException: java.security.KeyStoreException: jks not found

      W/System.err:     at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPC onnection.java:1058)

      W/System.err:     at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPCon nection.java:980)

      W/System.err:     at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnecti on.java:996)

      W/System.err:     at java.lang.Thread.run(Thread.java:761)

      W/System.err: Caused by: java.security.KeyStoreException: jks not found

      W/System.err:     at java.security.KeyStore.getInstance(KeyStore.java:649)

      W/System.err:     at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnecti on.java:730)

      W/System.err:     at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$1200(XMPPTCPConnection.java :149)

      W/System.err:     at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPC onnection.java:1053)

      W/System.err: ... 3 more

      W/System.err: Caused by: java.security.NoSuchAlgorithmException: jks KeyStore not available

      W/System.err:     at sun.security.jca.GetInstance.getInstance(GetInstance.java:159)

      W/System.err:     at java.security.Security.getImpl(Security.java:587)

      W/System.err:     at java.security.KeyStore.getInstance(KeyStore.java:646)

      W/System.err: ... 6 more

      W/AbstractXMPPConnection: Connection XMPPTCPConnection[not-authenticated] (0) closed with error

                                java.security.KeyStoreException: jks not found

                                    at java.security.KeyStore.getInstance(KeyStore.java:649)

                                    at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnecti on.java:730)

                                    at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$1200(XMPPTCPConnection.java :149)

                                    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPC onnection.java:1053)

                                    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPCon nection.java:980)

                                    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnecti on.java:996)

                                    at java.lang.Thread.run(Thread.java:761)

                                 Caused by: java.security.NoSuchAlgorithmException: jks KeyStore not available

                                    at sun.security.jca.GetInstance.getInstance(GetInstance.java:159)

                                    at java.security.Security.getImpl(Security.java:587)

                                    at java.security.KeyStore.getInstance(KeyStore.java:646)

                                    at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnecti on.java:730)

                                    at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$1200(XMPPTCPConnection.java :149)

                                    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPC onnection.java:1053)

                                    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPCon nection.java:980)

                                    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnecti on.java:996)

                                    at java.lang.Thread.run(Thread.java:761)

       

      When I debug the code it fails in this code below

       

      else if (keyStoreType != null)

      {

          ks = KeyStore.getInstance(keyStoreType); ///////////////////////////////// AT THIS LINE keyStoreType value is  ---> JKS

          if (callbackHandler != null && StringUtils.isNotEmpty(keystorePath)) {

              try {

                  pcb = new PasswordCallback("Keystore Password: ", false);

                  callbackHandler.handle(new Callback[] { pcb });

                  ks.load(new FileInputStream(keystorePath), pcb.getPassword());

              }

              catch (Exception e) {

                  LOGGER.log(Level.WARNING, "Exception", e);

                  ks = null;

              }

          } else {

              ks.load(null, null);

          }

      }

       

      Thanks in Advance,