1

I’m opening QWebView and loading https://xxx.xx.xx which requires from client to pass p12 certificate. All browsers displaying list of clients certificates and asking to choose one for use. QWebView doesn’t handling this case. maybe there are way to tell QWebView to handle this case ?

László Papp
  • 51,870
  • 39
  • 111
  • 135
lvshuchengyin
  • 235
  • 1
  • 4
  • 19

1 Answers1

0

Allowing the user to select a certificate from a list is not demonstrated here, but once you have a certificate that you want to use for this you can use the below.


First Method: This sets it globally and I believe QWebView should use it

QSslConfiguration config = QSslConfiguration::defaultConfiguration();
config.setLocalCertificate(yourCert);
config.setPrivateKey(yourKey);
QSslConfiguration::setDefaultConfiguration(config);

Second Method: Only possible if using WebKit browser and not WebEngine browser

extend QNetworkAccessManager and set the protocol in createRequest:

class NetworkAccessManager : public QNetworkAccessManager
{
    Q_OBJECT
public:
    explicit NetworkAccessManager(QObject *parent = 0);

protected:
    virtual QNetworkReply * createRequest(Operation operation, const QNetworkRequest & request, QIODevice * outgoingData = 0) {
        // I have no idea why request is const, but I need to change it
        QNetworkRequest notConstRequest = request;
        QSslConfiguration conf = notConstRequest.sslConfiguration();
        conf.setLocalCertificate(yourCert);
        conf.setPrivateKey(yourKey);
        notConstRequest.setSslConfiguration(conf);
        return QNetworkAccessManager::createRequest(operation, notConstRequest, outgoingData);
    }
};

Then set it setNetworkAccessManager.


(The methods above are modified versions of information provided in the below SO post that should address this issue. )

Is this the right way to set the SSL protocol with QWebPage?

Community
  • 1
  • 1
jp36
  • 1,873
  • 18
  • 28