简体   繁体   English

在Qt中,如何从QNetworkRequest中删除所有证书颁发机构证书?

[英]In Qt, how to remove all Certificate Authorities certificates from a QNetworkRequest?

We are trying to have complete control regarding which CA certificates a QNetworkRequest will be allowed to use. 我们正在尝试完全控制QNetworkRequest将被允许​​使用哪些CA证书。 The first 'simple' test we wanted to run was to remove all CA certificates and make sure it triggers and error on any https attempt. 我们要运行的第一个“简单”测试是删除所有CA证书,并确保它在任何https尝试中均触发并出错。

Here is the minimal example showing how we set up the instances: 这是显示我们如何设置实例的最小示例:

QNetworkAccessManager manager;
QUrl requestedUrl("https://www.google.com");
QNetworkRequest request(requestedUrl);

QSslConfiguration sslConfig = request.sslConfiguration();
// Set the QList of certificates to an empty list
sslConfig.setCaCertificates({});
request.setSslConfiguration(sslConfig);

QNetworkReply *reply = manager.get(request);
connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
        this, SLOT(slotSslErrors(QList<QSslError>)));

We would expect that to fail at runtime, as the request intentionally does not have any CA certificates to complete the authentication. 我们希望在运行时失败,因为请求是故意没有任何CA证书来完成身份验证的。 But the request actually completes successfully, the reply contains the webpage content, and the slotSslErrors slot is not executed. 但是请求实际上已成功完成,答复包含网页内容,并且未执行slotSslErrors插槽。

How would one actually disable all certificates for such a request ? 一个人实际上如何禁用这种请求的所有证书?

Whatever CA certificates you are setting, that should be done before SSL handshake. 无论您设置什么CA证书,都应在SSL握手之前完成。

http://doc.qt.io/qt-5/qsslconfiguration.html#setCaCertificates http://doc.qt.io/qt-5/qsslconfiguration.html#setCaCertificates

So probably you may need to call void QNetworkAccessManager::connectToHostEncrypted and set the QSslConfiguration object, before calling the 因此,您可能需要先调用void QNetworkAccessManager::connectToHostEncrypted并设置QSslConfiguration对象,然后再调用

QNetworkReply *reply = manager.get(request);

http://doc.qt.io/qt-5/qnetworkaccessmanager.html#connectToHostEncrypted http://doc.qt.io/qt-5/qnetworkaccessmanager.html#connectToHostEncrypted

Try something like below: 尝试如下所示:

QSslConfiguration sslConfig = request.sslConfiguration();
// Set the QList of certificates to an empty list
sslConfig.setCaCertificates({});
request.setSslConfiguration(sslConfig);

//ONCE YOU SET THE CONFIG ESTABLISH HAND SHAKE 
manager.connectToHostEncrypted("....",..,sslConfig);


QNetworkReply *reply = manager.get(request);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM