Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unable to load HTTPS url using QWebEngineView
QtWS25 Last Chance

Unable to load HTTPS url using QWebEngineView

Scheduled Pinned Locked Moved Solved General and Desktop
qwebengineviewqwebenginepageqwebenginehttpsssl error
5 Posts 2 Posters 3.9k 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.
  • R Offline
    R Offline
    Ryna
    wrote on 18 Feb 2020, 20:23 last edited by Ryna
    #1

    I am trying to load https link via QWebEngineView. I have done following steps-

    LoadWebviewWindow::LoadWebviewWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::LoadWebviewWindow)
    {
        ui->setupUi(this);
        m_view = new QWebEngineView(this);
        ui->m_webviewGL->addWidget(m_view);
    
        connect(m_view->page(), &QWebEnginePage::selectClientCertificate,
                this, &LoadWebviewWindow::slot_handleSelectClientCertificate);
        page->profile()->clearHttpCache();
        page->profile()->setUseForGlobalCertificateVerification(true);
    
        loadCertificate();
        connect(m_view, SIGNAL(loadFinished(bool)), this, SLOT(slot_loadPageFinished(bool)));
        m_view->load(QUrl("https://192.168.x.x/testurl"));
    }
    
    void LoadWebviewWindow::loadCertificate()
    {
        QFile pfxFile("/home/xyz/Downloads/Certificate_PKCS12.p12");
        bool isOpen = pfxFile.open(QFile::ReadOnly);
        QSslKey key;
        QSslCertificate certificate;
        QList<QSslCertificate> certChain;
    
        // now import into those three
        bool imported = QSslCertificate::importPkcs12(&pfxFile, &key, &certificate, &certChain, "password");
    
        QSslConfiguration config = QSslConfiguration();
        config.setCaCertificates(certChain);
        config.setPrivateKey(key);
        m_view->page()->profile()->clientCertificateStore()->add(certificate, key);
        config.setProtocol(QSsl::TlsV1_2);
        config.setPeerVerifyMode(QSslSocket::VerifyNone);
    }
    
    void LoadWebviewWindow::slot_handleSelectClientCertificate(QWebEngineClientCertificateSelection selection)
    {
        if (selection.certificates().count() > 0)
        {
            qInfo() << selection.certificates().at(0).expiryDate();
            selection.select(selection.certificates().at(0));
            return;
        }
    }
    

    but I am getting following error every time in linux-.

    [9386:9404:0218/115119.131010:ERROR:cert_verify_proc_nss.cc(969)] CERT_PKIXVerifyCert for 192.168.x.x failed err=-8172
    [9386:9400:0218/115119.132489:ERROR:ssl_client_socket_impl.cc(941)] handshake failed; returned -1, SSL error code 1, net_error -202

    On interesting side, it works on one single laptop which is running on Windows OS. Rest on all other windows OS, linux OS it fails. I had tried loading this https url on mozilla and chrome after installing same certificate and it worked fine. Error I am receiving on Qt application is for QSslError::UnableToGetIssuerCertificate. I wonder why is it not calling slot_handleSelectClientCertificate slot when I have already handled it. Any idea is appreciated. Thank you

    R 1 Reply Last reply 25 Feb 2020, 18:22
    1
    • R Offline
      R Offline
      Ryna
      wrote on 12 Mar 2020, 23:09 last edited by
      #5

      https://stackoverflow.com/questions/58875159/how-to-ignore-ssl-certificate-errors-with-qwebengineview link helped me to resolve the issue. Now HTTPS page load after ignoring ssl warning is fine. Thanks for ideas :)

      1 Reply Last reply
      1
      • R Ryna
        18 Feb 2020, 20:23

        I am trying to load https link via QWebEngineView. I have done following steps-

        LoadWebviewWindow::LoadWebviewWindow(QWidget *parent)
            : QMainWindow(parent)
            , ui(new Ui::LoadWebviewWindow)
        {
            ui->setupUi(this);
            m_view = new QWebEngineView(this);
            ui->m_webviewGL->addWidget(m_view);
        
            connect(m_view->page(), &QWebEnginePage::selectClientCertificate,
                    this, &LoadWebviewWindow::slot_handleSelectClientCertificate);
            page->profile()->clearHttpCache();
            page->profile()->setUseForGlobalCertificateVerification(true);
        
            loadCertificate();
            connect(m_view, SIGNAL(loadFinished(bool)), this, SLOT(slot_loadPageFinished(bool)));
            m_view->load(QUrl("https://192.168.x.x/testurl"));
        }
        
        void LoadWebviewWindow::loadCertificate()
        {
            QFile pfxFile("/home/xyz/Downloads/Certificate_PKCS12.p12");
            bool isOpen = pfxFile.open(QFile::ReadOnly);
            QSslKey key;
            QSslCertificate certificate;
            QList<QSslCertificate> certChain;
        
            // now import into those three
            bool imported = QSslCertificate::importPkcs12(&pfxFile, &key, &certificate, &certChain, "password");
        
            QSslConfiguration config = QSslConfiguration();
            config.setCaCertificates(certChain);
            config.setPrivateKey(key);
            m_view->page()->profile()->clientCertificateStore()->add(certificate, key);
            config.setProtocol(QSsl::TlsV1_2);
            config.setPeerVerifyMode(QSslSocket::VerifyNone);
        }
        
        void LoadWebviewWindow::slot_handleSelectClientCertificate(QWebEngineClientCertificateSelection selection)
        {
            if (selection.certificates().count() > 0)
            {
                qInfo() << selection.certificates().at(0).expiryDate();
                selection.select(selection.certificates().at(0));
                return;
            }
        }
        

        but I am getting following error every time in linux-.

        [9386:9404:0218/115119.131010:ERROR:cert_verify_proc_nss.cc(969)] CERT_PKIXVerifyCert for 192.168.x.x failed err=-8172
        [9386:9400:0218/115119.132489:ERROR:ssl_client_socket_impl.cc(941)] handshake failed; returned -1, SSL error code 1, net_error -202

        On interesting side, it works on one single laptop which is running on Windows OS. Rest on all other windows OS, linux OS it fails. I had tried loading this https url on mozilla and chrome after installing same certificate and it worked fine. Error I am receiving on Qt application is for QSslError::UnableToGetIssuerCertificate. I wonder why is it not calling slot_handleSelectClientCertificate slot when I have already handled it. Any idea is appreciated. Thank you

        R Offline
        R Offline
        Ryna
        wrote on 25 Feb 2020, 18:22 last edited by
        #2

        Any hints anyone? Appreciate your help.

        P 1 Reply Last reply 27 Feb 2020, 17:06
        0
        • R Ryna
          25 Feb 2020, 18:22

          Any hints anyone? Appreciate your help.

          P Offline
          P Offline
          Pablo J. Rogina
          wrote on 27 Feb 2020, 17:06 last edited by
          #3

          @Ryna said in Unable to load HTTPS url using QWebEngineView:

          Any hints anyone?

          I'd try capturing network traffic (Wireshark is your friend...) both with your Qt app and the browsers and compare them to see what's going on

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          R 1 Reply Last reply 10 Mar 2020, 18:36
          0
          • P Pablo J. Rogina
            27 Feb 2020, 17:06

            @Ryna said in Unable to load HTTPS url using QWebEngineView:

            Any hints anyone?

            I'd try capturing network traffic (Wireshark is your friend...) both with your Qt app and the browsers and compare them to see what's going on

            R Offline
            R Offline
            Ryna
            wrote on 10 Mar 2020, 18:36 last edited by
            #4

            @Pablo-J-Rogina Thanks for your reply. Now I am able to get the exact issue at least. So client is not able to trust server certificate, that's the reason application is not even asking for client installed certificate. So to the best of my understanding, I need to do something similar to "I trust the certificate"/"Add exception" kind of thing, when server responds with its certificate details.

            Any idea on how can I do that? Am I supposed to create SSL socket first? I am clueless here.
            TIA

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Ryna
              wrote on 12 Mar 2020, 23:09 last edited by
              #5

              https://stackoverflow.com/questions/58875159/how-to-ignore-ssl-certificate-errors-with-qwebengineview link helped me to resolve the issue. Now HTTPS page load after ignoring ssl warning is fine. Thanks for ideas :)

              1 Reply Last reply
              1

              • Login

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