0

We are trying to have complete control regarding which CA certificates a QNetworkRequest will be allowed to use. 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.

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. But the request actually completes successfully, the reply contains the webpage content, and the slotSslErrors slot is not executed.

How would one actually disable all certificates for such a request ?

Ad N
  • 7,930
  • 6
  • 36
  • 80

1 Answers1

1

Whatever CA certificates you are setting, that should be done before SSL handshake.

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

QNetworkReply *reply = manager.get(request);

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);
Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34
  • Thank you for your answer. I saw the pre-handshake requirement in the doc, and my understanding is that when you don't explicitly call one of `QNetworkAccessManager` connect method, the handshake happens when you issue the request (i.e., the call to `get` in the example). Anyway, I tried adding the call to `connectToHostEncrypted` as you suggested, and the behaviour remains the same. – Ad N May 19 '17 at 10:02