aSmack - create TLS configuration

String host = "example.com"; int port = 5222; String service = "example.com"; ConnectionConfiguration config = new AndroidConnectionConfiguration(host, port, service); config.setRosterLoadedAtLogin(false); config.setReconnectionAllowed(false); // or true if you want to use built in reconnection config.setDebuggerEnabled(true); config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled); // enable TLS 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); } // then use config for connection.
Using aSmack (Android library for XMPP), we need to use certain ConnectionConfiguration to 'connect' to the server.
This snippet is about how to create configuration for secured connection.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.