NoSuchAlgorithmException when using aSmack 0.8.3 f

2019-05-27 05:06发布

I have included the logcat output. Please help me resolve this issue.

08-09 11:06:32.762: WARN/NetworkManagementSocketTagger(883): setKernelCountSet(10012, 0) failed with errno -2

08-09 11:06:32.856: WARN/System.err(1567): java.security.KeyStoreException: ava.security.NoSuchAlgorithmException: KeyStore jks implementation not found

08-09 11:06:32.856: WARN/System.err(1567): at java.security.KeyStore.getInstance(KeyStore.java:119)

08-09 11:06:32.856: WARN/System.err(1567): at org.jivesoftware.smack.ServerTrustManager.(ServerTrustManager.java:70)

08-09 11:06:32.856: WARN/System.err(1567): at org.jivesoftware.smack.XMPPConnection.proceedTLSReceived(XMPPConnection.java:871)

08-09 11:06:32.856: WARN/System.err(1567): at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:221)

08-09 11:06:32.856: WARN/System.err(1567): at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)

08-09 11:06:32.856: WARN/System.err(1567): at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)

08-09 11:06:32.856: WARN/System.err(1567): Caused by: java.security.NoSuchAlgorithmException: KeyStore jks implementation not found

08-09 11:06:32.856: WARN/System.err(1567): at org.apache.harmony.security.fortress.Engine.notFound(Engine.java:177)

08-09 11:06:32.856: WARN/System.err(1567): at org.apache.harmony.security.fortress.Engine.getInstance(Engine.java:151)

08-09 11:06:32.856: WARN/System.err(1567): at java.security.KeyStore.getInstance(KeyStore.java:116)

08-09 11:06:32.856: WARN/System.err(1567): ... 5 more


here is the logcat message iam getting now after adding ur code..

08-09 11:35:34.469: WARN/System.err(1733): java.lang.NullPointerException
08-09 11:35:34.469: WARN/System.err(1733):     at java.io.File.fixSlashes(File.java:185)
08-09 11:35:34.469: WARN/System.err(1733):     at java.io.File.<init>(File.java:134)
08-09 11:35:34.469: WARN/System.err(1733):     at java.io.FileInputStream.<init>(FileInputStream.java:105)
08-09 11:35:34.469: WARN/System.err(1733):     at org.jivesoftware.smack.ServerTrustManager.<init>(ServerTrustManager.java:71)
08-09 11:35:34.469: WARN/System.err(1733):     at org.jivesoftware.smack.XMPPConnection.proceedTLSReceived(XMPPConnection.java:871)
08-09 11:35:34.469: WARN/System.err(1733):     at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:221)
08-09 11:35:34.469: WARN/System.err(1733):     at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
08-09 11:35:34.469: WARN/System.err(1733):     at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)

Its not referring any line in my code...

08-09 11:57:32.126: W/BackupManagerService(868): dataChanged but no participant pkg='com.android.providers.settings' uid=1001
08-09 11:57:32.147: W/NetworkManagementSocketTagger(868): setKernelCountSet(10012, 0) failed with errno -2
08-09 11:57:32.198: W/System.err(1497): java.lang.NullPointerException
08-09 11:57:32.198: W/System.err(1497):     at java.io.File.fixSlashes(File.java:185)
08-09 11:57:32.198: W/System.err(1497):     at java.io.File.<init>(File.java:134)
08-09 11:57:32.198: W/System.err(1497):     at java.io.FileInputStream.<init>(FileInputStream.java:105)
08-09 11:57:32.198: W/System.err(1497):     at org.jivesoftware.smack.ServerTrustManager.<init>(ServerTrustManager.java:71)
08-09 11:57:32.198: W/System.err(1497):     at org.jivesoftware.smack.XMPPConnection.proceedTLSReceived(XMPPConnection.java:871)
08-09 11:57:32.198: W/System.err(1497):     at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:221)
08-09 11:57:32.198: W/System.err(1497):     at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
08-09 11:57:32.198: W/System.err(1497):     at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)

1条回答
姐就是有狂的资本
2楼-- · 2019-05-27 05:39

This is how I handle it

ConnectionConfiguration config = new ConnectionConfiguration("your_server", port_no);
config.setSASLAuthenticationEnabled(true);
config.setCompressionEnabled(true);
config.setSecurityMode(SecurityMode.enabled);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    config.setTruststoreType("AndroidCAStore");
    config.setTruststorePassword(null);
    config.setTruststorePath(null);
} else {
    config.setTruststoreType("BKS");
    String path = System.getProperty("javax.net.ssl.trustStore");
    if (path == null)
        path = System.getProperty("java.home") + File.separator + "etc"
            + File.separator + "security" + File.separator
            + "cacerts.bks";
    config.setTruststorePath(path);
}
查看更多
登录 后发表回答