Hi there
I'm using aSmack on my project enabling Facebook chat on Android. I tried aSmack 0.8.10 and it work really good except one thing that when I'm on wifi or 3G the connection lost without saying a word. I spent almost all my week on that problem but I cannot solve it.
Then I try latest version 4.0.4 and I got the error org.jivesoftware.smack.SmackException$NoResponseException: Here is full of the stack trace:
10-12 02:14:01.921: W/System.err(21797): java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
10-12 02:14:01.921: W/System.err(21797): at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkTrusted(TrustManage rImpl.java:192)
10-12 02:14:01.921: W/System.err(21797): at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(Trust ManagerImpl.java:163)
10-12 02:14:01.921: W/System.err(21797): at de.duenndns.ssl.MemorizingTrustManager.checkCertTrusted(MemorizingTrustManager. java:387)
10-12 02:14:01.921: W/System.err(21797): at de.duenndns.ssl.MemorizingTrustManager.checkServerTrusted(MemorizingTrustManage r.java:425)
10-12 02:14:01.921: W/System.err(21797): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain( OpenSSLSocketImpl.java:597)
10-12 02:14:01.921: W/System.err(21797): at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
10-12 02:14:01.921: W/System.err(21797): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLS ocketImpl.java:395)
10-12 02:14:01.921: W/System.err(21797): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.<init>(O penSSLSocketImpl.java:647)
10-12 02:14:01.921: W/System.err(21797): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.getInputStream(OpenSSLS ocketImpl.java:618)
10-12 02:14:01.921: W/System.err(21797): at org.jivesoftware.smack.tcp.XMPPTCPConnection.initReaderAndWriter(XMPPTCPConnect ion.java:503)
10-12 02:14:01.921: W/System.err(21797): at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnecti on.java:650)
10-12 02:14:01.921: W/System.err(21797): at org.jivesoftware.smack.tcp.PacketReader.parsePackets(PacketReader.java:221)
10-12 02:14:01.921: W/System.err(21797): at org.jivesoftware.smack.tcp.PacketReader.access$000(PacketReader.java:47)
10-12 02:14:01.921: W/System.err(21797): at org.jivesoftware.smack.tcp.PacketReader$1.run(PacketReader.java:81)
10-12 02:14:01.925: W/System.err(21797): Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
10-12 02:14:01.925: W/System.err(21797): ... 14 more
10-12 02:14:01.925: D/MemorizingTrustManager(21797): checkCertTrusted: trying defaultTrustManager
10-12 02:14:02.185: D/dalvikvm(21797): GC_CONCURRENT freed 308K, 4% free 11656K/12103K, paused 10ms+0ms, total 13ms
10-12 02:14:03.317: W/IQReplyFilter(21797): Rejected potentially spoofed reply to IQ-packet. Filter settings: packetId=BOkaA-0, to=null, local=null, server=chat.facebook.com. Received packet with from=userA
10-12 02:14:08.093: W/System.err(21797): org.jivesoftware.smack.SmackException$NoResponseException
10-12 02:14:08.093: W/System.err(21797): at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:1 77)
10-12 02:14:08.093: W/System.err(21797): at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:1 61)
10-12 02:14:08.093: W/System.err(21797): at org.jivesoftware.smack.XMPPConnection.bindResourceAndEstablishSession(XMPPConne ction.java:530)
10-12 02:14:08.093: W/System.err(21797): at org.jivesoftware.smack.tcp.XMPPTCPConnection.login(XMPPTCPConnection.java:260)
10-12 02:14:08.093: W/System.err(21797): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:442)
10-12 02:14:08.093: W/System.err(21797): at com.example.facebooktrustmanagertest.FBTrustMainActivity.intConnection(FBTrustM ainActivity.java:294)
10-12 02:14:08.093: W/System.err(21797): at com.example.facebooktrustmanagertest.FBTrustMainActivity.access$0(FBTrustMainAc tivity.java:239)
10-12 02:14:08.093: W/System.err(21797): at com.example.facebooktrustmanagertest.FBTrustMainActivity$LoginTestTask.doInBack ground(FBTrustMainActivity.java:88)
10-12 02:14:08.093: W/System.err(21797): at com.example.facebooktrustmanagertest.FBTrustMainActivity$LoginTestTask.doInBack ground(FBTrustMainActivity.java:1)
10-12 02:14:08.093: W/System.err(21797): at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-12 02:14:08.093: W/System.err(21797): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-12 02:14:08.093: W/System.err(21797): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-12 02:14:08.093: W/System.err(21797): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-12 02:14:08.093: W/System.err(21797): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-12 02:14:08.093: W/System.err(21797): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-12 02:14:08.093: W/System.err(21797): at java.lang.Thread.run(Thread.java:856)
Here is my code using aSmack version 4.0.4:
//Connect to xmpp server when internet comes
private void intConnection()
{
mSmack = SmackAndroid.init(getApplicationContext());
xMPPConfig = new ConnectionConfiguration("chat.facebook.com", 5222);
SASLAuthentication.supportSASLMechanism("PLAIN");
xMPPConfig.setSecurityMode(SecurityMode.enabled);
xMPPConfig.setReconnectionAllowed(false);
xMPPConfig.setSendPresence(false);
//get key store
KeyStore trustStore = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
try {
trustStore = KeyStore.getInstance("AndroidCAStore");
} catch (KeyStoreException e) {
Log.v("FBTrust Smack 4.0", "KeyStoreException");
e.printStackTrace();
}
} else {
try {
trustStore = KeyStore.getInstance("BKS");
} catch (KeyStoreException e) {
Log.v("FBTrust Smack 4.0", "KeyStoreException");
e.printStackTrace();
}
}
TrustManagerFactory trustManagerFactory = null;
try {
trustManagerFactory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
} catch (NoSuchAlgorithmException e2) {
Log.v("FBTrust Smack 4.0", "NoSuchAlgorithmException");
e2.printStackTrace();
}
try {
trustManagerFactory.init(trustStore);
} catch (KeyStoreException e2) {
Log.v("FBTrust Smack 4.0", "KeyStoreException");
e2.printStackTrace();
}
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, MemorizingTrustManager.getInstanceList(FBTrustMainActivity.this),
new java.security.SecureRandom());
xMPPConfig.setCustomSSLContext(sc);
} catch (java.security.GeneralSecurityException e) {
e.printStackTrace();
}
connection = new XMPPTCPConnection(xMPPConfig);
try {
connection.connect();
connection.login("username", "password");
} catch (SmackException e2) {
e2.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
} catch (XMPPException e2) {
e2.printStackTrace();
}
}
@Override
protected void onDestroy() {
mSmack.onDestroy();
super.onDestroy();
}
I desperately need you help and I will really appreciate it
Thank you guys!