Search code examples
qtsslsslv3

How do I force QWebView to use SSLv3?


There is a web server which does not support the SSLv2 HELO and therefore I must force QWebView to do an SSLv3 HELO. Unfortunately, the following does not work:

QList ciphers = QSslSocket::supportedCiphers();
for (int i = ciphers.count() - 1; i >= 0; i--){
    QSslCipher cipher = ciphers.at(i);
    QSsl::SslProtocol protocol = cipher.protocol();
    if (protocol == QSsl::SslV2){
        ciphers.removeAt(i);
    }
}
QSslSocket::setDefaultCiphers(ciphers);

Solution

  • By overriding the QNetworkAccessManager's createRequest virtual function you can force it to a specific ssl protocol:

    MyNetworkAccessManager::MyNetworkAccessManager(
                   QNetworkAccessManager *oldManager, QObject *parent /*= 0*/)
        : QNetworkAccessManager(parent)
    {
        setCache(oldManager->cache());
        setCookieJar(oldManager->cookieJar());
        setProxy(oldManager->proxy());
        setProxyFactory(oldManager->proxyFactory());
    }
    
    
    QNetworkReply* MyNetworkAccessManager::createRequest(
             QNetworkAccessManager::Operation op, const QNetworkRequest &req, 
             QIODevice *device)
    {
        QSslConfiguration sslConfig = req.sslConfiguration();
        sslConfig.setProtocol(QSsl::SslV3);
        req.setSslConfiguration(sslConfig);
        return QNetworkAccessManager::createRequest(op, req, outgoingData);
    }
    
    
    view = new QWebView(this);
    QNetworkAccessManager *oldManager = view->page()->networkAccessManager();
    MyNetworkAccessManager *newManager = new MyNetworkAccessManager(oldManager, this);
    view->page()->setNetworkAccessManager(newManager);