2

有一个不支持 SSLv2 HELO 的 Web 服务器,因此我必须强制QWebView执行 SSLv3 HELO。不幸的是,以下方法不起作用:

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);
4

1 回答 1

4

通过覆盖 QNetworkAccessManager 的 createRequest 虚函数,您可以强制它使用特定的 ssl 协议:

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);
于 2012-10-07T13:49:02.030 回答