1

Qt用作服务器端和 android客户端。我设置了SSLSocketFactory认证

    private ConnectionManager(MBoxConfiguration config) {
    try {
        this.config = config;


         try {
                trusted.load(in, "password".toCharArray());
        } finally {
            in.close();
        }

          SSLSocketFactory sf = new SSLSocketFactory(trusted);
          Socket socket;
          socket = ssf.createSocket();
      socket.connect(new InetSocketAddress(config.ip, config.port));
           KeyStore trusted = KeyStore.getInstance("BKS");

        InputStream in = MainActivity.context.getResources().openRawResource(R.raw.truststore);
        try {

            trusted.load(in, "password".toCharArray());
        } finally {
            in.close();
        }

        ssf = new SSLSocketFactory(trusted);
             ssf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);                                                                                                                   


    } catch (Exception e) {

        e.printStackTrace();

    }

}

当我想连接到服务器时,QT给我那个错误

Thread Address in peerVerifyError "The peer did not present any certificate" Thread Address in sslErrors ("The peer did not present any certificate") Thread Address in error QAbstractSocket::SocketError( 13 ) Thread Address in destroyThreadfirst: QThread(0x12ec9448) Thread Address in destroyThread: QThread(0x12ec9238)

4

1 回答 1

0

http://qt-project.org/doc/qt-5.1/qtnetwork/qsslsocket.html

看QSslSocket::sslErrors的描述

尝试连接sslErrors信号,然后ignoreSslErrors()从那里调用插槽以忽略错误,这应该会有所帮助。

于 2013-09-18T17:37:49.383 回答