Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. Installing certificates or allowing certain hosts.

Installing certificates or allowing certain hosts.

Scheduled Pinned Locked Moved Unsolved QtWebEngine
2 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • BryanWhiteB Offline
    BryanWhiteB Offline
    BryanWhite
    wrote on last edited by
    #1

    My application has a few places where I display web pages. I am using QWebEngineView. Some of the test servers we use have self-signed certificates. For internal requests I install relevent certificates on startup with code like this:

    // Read the SSL certificate
    QFile file(":/ssl/" + host + ".crt");
    file.open(QIODevice::ReadOnly);
    const QByteArray bytes = file.readAll();
    const QSslCertificate certificate(bytes);
    QSslSocket::addDefaultCaCertificate(certificate);
    

    This does not work in QWebEngineView. Is there are way to install a certificate there?

    Alternatively it looks like the QWebEnginePage::certificateError() is a virtual function that I could override. However I do not see how to get the QWebEnginePage objects created from a derived class.

    1 Reply Last reply
    0
    • McLionM Offline
      McLionM Offline
      McLion
      wrote on last edited by
      #2

      Loading should work this way, if you use the correct file format
      QSslSocket::addDefaultCaCertificates(certdata.pem)
      Look here: https://curl.haxx.se/docs/caextract.html

      You also need SSL error handling - use this as a working base:

        connect(webGUI->page()->networkAccessManager(), SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError> & )),
        this, SLOT(HandleGUIsslErrors(QNetworkReply*, const QList<QSslError> & )));
      
      void QTGUI_MainWindow::HandleGUIsslErrors(QNetworkReply* reply, const QList<QSslError> &errors)
      {
        foreach (QSslError e, errors)
        {
          qDebug() << "GUI SSL error:" << e;
          QByteArray qbTemp;
          qbTemp.append(e.errorString());
        }
        //reply->ignoreSslErrors(); // this is only a hack !!
        reply->abort();
      }
      

      HTH

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved