简体   繁体   English

Android SSL TLS连接到XMPP服务器

[英]Android SSL TLS connection to XMPP server

I am trying to connect to an XMPP server requiring "Encryption (SSL or TLS)". 我正在尝试连接到需要“加密(SSL或TLS)”的XMPP服务器。 I cannot use Smack or other third-party libraries (school project) 我无法使用Smack或其他第三方库(学校项目)

Here is my Java code to initialize an SSL socket : 这是我的Java代码,用于初始化SSL套接字:

KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
TrustManagerFactory trustManagerFactory=TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom());
socket = sslContext.getSocketFactory().createSocket(HOST, PORT);
socket.setKeepAlive(true);

If I try to open the stream on the socket: 如果我尝试在套接字上打开流:

socket.getOutputStream()

I get this error : 我收到此错误:

javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x76cb46a0: Failure in SSL library, usually a protocol error

error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:766 0x72fb3d74:0x00000000)

at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:448)

Does anyone know where is the issue from ? 有人知道问题出在哪里吗?

From having a short look at the XMPP core specification it does not look like you can simple use a socket and upgrade it immediately to TLS. 通过简短地了解XMPP核心规范 ,您似乎无法简单地使用套接字并将其立即升级到TLS。 Instead you have to first use some kind of STARTTLS command and only after that you can upgrade to TLS. 相反,您必须先使用某种STARTTLS命令,然后才能升级到TLS。 This is similar to explicit TLS in SMTP, IMAP etc. 这类似于SMTP,IMAP等中的显式TLS。

For more details please see the specification . 有关更多详细信息,请参见规格 Some shorter information you will find here . 您可以在此处找到一些简短的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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