简体   繁体   中英

Cannot establish TLS connection to Openfire 4.1.3 server with Smack 4.2 on Android: SSLProtocolException: SSL handshake aborted

I'm trying to connect to my Openfire 4.1.3 server with Smack 4.2, the current config works ok:

XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();
    config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
    config.setXmppDomain(serviceName);
    config.setHost(context.getString(R.string.server));
    config.setHostnameVerifier(verifier);
    config.setHostAddress(addr);
    config.setResource("Android");
    config.setPort(Integer.parseInt(context.getString(R.string.server_port)));
    config.setDebuggerEnabled(true);

    XMPPTCPConnection.setUseStreamManagementResumptionDefault(true);
    XMPPTCPConnection.setUseStreamManagementDefault(true);
    connection = new XMPPTCPConnection(config.build());

If I try to connect with SecurityMode.required I can't establish any connection. I read aroud about setting CA on device, but I don't know what to do. Any help?

EDIT: These are the new lines added for trying to connect with SecurityMode.required

config.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
    config.setCompressionEnabled(false);

    SSLContext sslContext = null;
    try {
        sslContext = createSSLContext(context);
    } catch (KeyStoreException | NoSuchAlgorithmException
            | KeyManagementException | IOException | CertificateException e) {
        e.printStackTrace();
    }

    config.setCustomSSLContext(sslContext);
    config.setSocketFactory(sslContext.getSocketFactory());

It generates this error stack:

W/System.err: javax.net.ssl.SSLHandshakeException: Handshake failed
W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:429)
W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.waitForHandshake(OpenSSLSocketImpl.java:682)
W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.java:644)
W/System.err:     at org.jivesoftware.smack.tcp.XMPPTCPConnection.initReaderAndWriter(XMPPTCPConnection.java:656)
W/System.err:     at org.jivesoftware.smack.tcp.XMPPTCPConnection.initConnection(XMPPTCPConnection.java:633)
W/System.err:     at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:891)
W/System.err:     at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:377)
W/System.err:     at it.chiaia.portaleragazze.chat.xmpp.XmppServer$2.doInBackground(XmppServer.java:176)
W/System.err:     at it.chiaia.portaleragazze.chat.xmpp.XmppServer$2.doInBackground(XmppServer.java:169)
W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:305)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
W/System.err:     at java.lang.Thread.run(Thread.java:761)
W/System.err: Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb38b1400: Failure in SSL library, usually a protocol error
W/System.err: error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER (external/boringssl/src/ssl/tls_record.c:192 0xa769d1aa: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:357)
W/System.err:   ... 14 more

setUsernameAndPassword() method is missing.

 val config= XMPPTCPConnectionConfiguration.builder()
                    .setXmppDomain(mDomainName)
                    .setUsernameAndPassword(mUsername,mPassword)
                    .setDebuggerEnabled(true)
                    .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)



            mConnection= XMPPTCPConnection(config.build())
            mConnection!!.connect().login()
W/System.err: Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb38b1400: Failure in SSL library, usually a protocol error
W/System.err: error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER (external/boringssl/src/ssl/tls_record.c:192 0xa769d1aa:0x00000000)

Your Android platform does not like the SSL/TLS version your Openfire uses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM