5
votes

I run ejabberd in my cloud server and I think it is working well because I can connect to it from my PC using pidgin.(ejabberdctl connected-users-number answers 1 when I connect and 0 when I'm offline.)

Now I try to connect to if from my android application using the smack package, and I get IOException :

javax.net.ssl.SSLHandshakeException: Handshake failed

Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb897c858: Failure in SSL library, usually a protocol error
error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:795 0xacf6bf89:0x00000000)
W/System.err﹕ at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
W/System.err﹕ at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:318)

this is my Application code:

XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();
config.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
config.setConnectTimeout(30000);
config.setUsernameAndPassword(username + "@" + service, password);
config.setServiceName(service);
config.setHost(host);
config.setCompressionEnabled(true);
config.setPort(port);
config.setDebuggerEnabled(true);
config.setSocketFactory(SSLSocketFactory.getDefault());

SmackConfiguration.DEBUG = true;
try {
    TLSUtils.acceptAllCertificates(config);
    XMPPTCPConnection connection = new XMPPTCPConnection(config.build());
    connection.connect();
    connection.login();

} catch (SmackException ex) {
    ex.printStackTrace();
    chatClient.setConnection(null);
} catch(IOException ex){
    ex.printStackTrace();
    chatClient.setConnection(null);                 
} catch ( XMPPException ex){
    ex.printStackTrace();
    chatClient.setConnection(null);                 
}catch (NoSuchAlgorithmException ex) {
    ex.printStackTrace();
    chatClient.setConnection(null);
}catch (KeyManagementException ex) {
    ex.printStackTrace();
    chatClient.setConnection(null);
}
return null;

I'd really appreciate any help!!

1
config.setSocketFactory(SSLSocketFactory.getDefault()); why do you do that?Flow
thanks for your comment. I added it because I thought it was crucial for the SSL. (as seen in several examples ) when I removed it I got this SmackException: java.security.cert.CertificateException: Hostname verification of certificate failed. Certificate does not authenticate localhost and then I changed config.setSecurityMode(ConnectionConfiguration.SecurityMode.required); to config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled); then the connect() passed! but now I get this XMPPException at login(): SASLError using SCRAM-SHA-1: not-authorized :(user3698465
It looks like your certificate is not matching your domain (localhost). You should build a true correct certificate and probably use that same real domain.Mickaël Rémond
@user3698465 you got any solution i have same issue just post solution if achivePankajAndroid

1 Answers

0
votes

Disable SSL if SSL isn't enabled in your server. To disable,

config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);