QNetworkReply does not return requests with expired SSL certificates. Workaround?



  • I have a https connection with expired or self issued certificate. If I want to use a code like:
    @reply = manager->get("https.... not valid certificate.. url");@

    I get a QNetworkReply::sslErrors signal (QList<QSslError>) like:
    "The host name did not match any of the valid hosts for this certificate", "No error"
    and a QNetworkReply::error signal: QNetworkReply::SslHandshakeFailedError
    (in two different signal, both are signaled).
    After this QNetworkAccessManager::replyFinished signal is signaled but returns just an empty string, nothing is read from the host.
    How can I read anyway https replies without having a valid certificate?
    If I read http, the code works fine.
    Thanks for ideas!



  • Answer found after reading documentation:

    void QNetworkReply::ignoreSslErrors() [virtual slot]
    If this function is called, SSL errors related to network connection will be ignored, including certificate validation errors.

    Note that calling this function without restraint may pose a security risk for your application. Use it with care.

    This function can be called from the slot connected to the sslErrors() signal, which indicates which errors were found.



  • Check the:
    @QNetworkReply::sslErrors ( const QList<QSslError> & errors )@

    signal documentation which states that you should call:
    @ignoreSslErrors() @

    from the slot connect to the signal to receive the behaviour you want to..

    Edit: you already found it! :-)


Log in to reply
 

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