powered by Jive Software

Smack 3.0.4 OLD SSL Connection

I’m converting my application from using Smack 2.2.1 code to 3.0.4. In doing so it is necessary to create and use a ConnectionConfiguration object when creating an XMPPConnection. Our server supports both no encryption on one port and the old style SSL (not TLS) encryption on another port. When using no encryption, I connect just fine. When attempting to use encryption, the connection fails. What I’m missing is how to setup the ConnectionConfiguration object for use with our server. Essentially I need to do the same thing that the Spark client does, which connects just fine using the “OLD SSL port method” to our server.

I’m still digging through the Smack docs, etc., but any adivce on setting up the configuration object would be appreciated.

Thanks,

Steve

Simpler than I thought. I established an SSLSocketFactory and TrustManager similar to version 2.2.1 and set the configuration to use my SSLSocketFactory.

Steve

How did you do that. I tried and failed. Here is what I did.


 boolean _encrypted = true ;

 String _server = "jabber.topiatechnology.com" ;

 boolean _saslEncryption = false ;

 String _username = "XXXX" ;

 String _password = "YYYY" ;

 String _recipient = "mgmcgrady.jabber.topiatechnology.com" ;

 String _jobID = "abcd1234" ;

 XMPPConnection conn = null ;

 try

 {

 // Encrypted connections are made on 5223, unencrypted on 5222

 int port = ( _encrypted ? 5223 : 5222 ) ;

         ConnectionConfiguration config = new ConnectionConfiguration( _server, port, "gmail.com");

         // Disable SASL Authentication

         config.setSASLAuthenticationEnabled ( _saslEncryption ) ;

         config.setSecurityMode ( SecurityMode.enabled ) ;

         config.setVerifyChainEnabled ( false ) ;

         config.setVerifyRootCAEnabled ( false ) ;

         config.setSelfSignedCertificateEnabled ( true ) ;

         config.setNotMatchingDomainCheckEnabled ( false ) ;

         if ( _encrypted )

         {

          SSLContext sc = SSLContext.getInstance ( "TLS" ) ;

          TrustManager tm = new X509TrustManager ( ) {

          public void checkServerTrusted ( X509Certificate[] chain,

          String authType ) throws CertificateException

          {

          // NOOP

          }

 public void checkClientTrusted ( X509Certificate[] chain,

 String authType ) throws CertificateException

 {

 // TODO Replace with Real Code

 }

 public X509Certificate[] getAcceptedIssuers ( )

 {

 // TODO Replace with Real Code

 return null ;

 }

          } ;

        

          TrustManager[] tms = new TrustManager[] { tm } ;

 sc.init ( null, tms, new java.security.SecureRandom() ) ;

          SSLSocketFactory sslSocketFactory = sc.getSocketFactory ( ) ;

         // Enable SSL Encrypted Connections

 config.setSocketFactory ( sslSocketFactory ) ;

         }

 XMPPConnection.DEBUG_ENABLED = true ;

 conn = new XMPPConnection ( config ) ;

 System.out.println ( "Connecting to Jabber Server " + _server + ":" + port ) ;

 conn.connect ( ) ;

 if (conn.isConnected()) {

 System.out.println( "Connected: " + conn.isConnected() ) ;

 String conID = conn.getConnectionID ( ) ;

 System.out.println( "Connection ID: " + conID ) ;

 System.out.println("Is secure connection: " + conn.isSecureConnection ( ) ) ;

     System.out.println( "Connected to Jabber Server. Logging in as " + _username ) ;

 conn.login (_username, _password ) ;

 // SAME

     //conn.login (_username, _password, "Smack" ) ;

 System.out.println ( "Logged in as " + _username ) ;

 ChatManager manager = conn.getChatManager ( ) ;

 Chat chat = manager.createChat ( _recipient, new MessageListener ( ) {

 public void processMessage ( Chat arg0, Message arg1 ) {

 System.out.println ( "Message: " + arg1.getBody ( ) );

 }

 }) ;

 System.out.println ( "Created Chat Session with " + _recipient ) ;

     String message = "The Data Ingest Job #" + _jobID + " has completed successfully" ;

 chat.sendMessage ( message ) ;

 System.out.println ( "Message Sent" ) ;

 } else {

 System.out.println("Not connected.") ;

 }

 }

 catch ( XMPPException e )

 {

 e.printStackTrace ( ) ;

 }

 catch ( NoSuchAlgorithmException e )

 {

 // TODO Replace With Real Code

 throw new RuntimeException ( "Need to implement this catch block", e ) ;

 }

 catch ( KeyManagementException e )

 {

 // TODO Replace With Real Code

 throw new RuntimeException ( "Need to implement this catch block", e ) ;

 }

 finally

 {

 if ( conn != null )

 {

 conn.disconnect ( ) ;

 }

 }

The error I get is as follows. Any ideas?


--------------------topia

Connecting to Jabber Server jabber.topiatechnology.com:5223

stream:error (text)

 at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:306)

 at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)

 at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:76)

Connected: true

Connection ID: qt5gubs3c12ux2jbdjizvxzkvlubbuapaolc07p0

Is secure connection: false

Connected to Jabber Server. Logging in as mgmcgrady

No response from the server.:

 at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication.java:74)

 at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:404)

 at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:349)

 at jabber.TestClass.oldStyleTopiaJohn(TestClass.java:283)

 at jabber.TestClass.main(TestClass.java:69)

--------------------topia