QSsl client + server, working example



  • Hi all,
    I'm trying to get my client + server applications working with QSslSocket.

    The problem is that I can't find a good working example.

    I found a client example in QtSDK examples but not the server one.

    Have you got a good example to post?



  • I found a working server example:
    @
    m_socket = new QSslSocket(this);
    m_socket->setSocketDescriptor(handle);
    m_socket->setProtocol(QSsl::SslV3);

    QByteArray key;
    QByteArray cert;
    
    QFile file_key("../ssl/server.key");
    if(file_key.open(QIODevice::ReadOnly))
    {
        key = file_key.readAll();
        file_key.close();
    }
    else
    {
        qDebug() << file_key.errorString();
    }
    
    QFile file_cert("../ssl/server.crt");
    if(file_cert.open(QIODevice::ReadOnly))
    {
        cert = file_cert.readAll();
        file_cert.close();
    }
    else
    {
        qDebug() << file_cert.errorString();
    }
    
    //qDebug() << key + "\n" + cert;
    
    
    QSslKey ssl_key(key, QSsl::Rsa);
    
    QSslCertificate ssl_cert(cert);
    
    m_socket->setPrivateKey(ssl_key);
    m_socket->setLocalCertificate(ssl_cert);
    m_socket->startServerEncryption();
    

    @

    This example works fine.

    Now how can I avoid certificate sending to client?
    I'd like to have the certificate already available to the client code so that it can use that certificate to communicate with server .


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.