handling QWebEngineCertificateError
-
I'm trying to load map tiles from a local server on my network. My application can either display a Google Map in my browser (Firefox) or in a QWebEngineView in my app's main window. Because Firefox requires that SSL be used to download web contact, I had to implement SSL with a self-signed certificate on my web server (apache 2 on Ubuntu). Firefox, in order to load the content required that I import my certificate and declare it trusted. This works just fine.
However when running the app using the QWebEngineView, the map overlay tiles failed to load. I discovered that QWebEngineView was catching an SSL error so I put in the following code to handle it and accept the error:
connect(myWebEnginePage, &QWebEnginePage::certificateError, [=](QWebEngineCertificateError error){ QList<QSslCertificate> chain = error.certificateChain(); qDebug() << error.description() << tr(" there are %1 certificates in chain. From %2").arg(chain.count()).arg(error.url().toDisplayString()); foreach (QSslCertificate cert, chain) { //qDebug() << cert.toText(); // not implemented qDebug() << tr("name: %1 expires:%2 isSelf-signed: %3") .arg(cert.subjectDisplayName(),cert.expiryDate().toString(),cert.isSelfSigned()?"yes":"no"); } if(error.type() == QWebEngineCertificateError::CertificateAuthorityInvalid) { return error.acceptCertificate(); } return error.defer(); });
Now I get this error when I start loading the Google Maps overlay tiles:
17:30:05.332 Debug: scriptFunctionResult QVariant(QString, "loadOverlay") QVariant(std::nullptr_t, (nullptr)) (webviewbridge.cpp:135, void WebViewBridge::scriptFunctionResult(QVariant, QVariant)) [355148:355202:1022/173005.352887:ERROR:cert_verify_proc_builtin.cc(874)] CertVerifyProcBuiltin for ubuntu-2 failed: ----- Certificate i=0 (CN=self-signedKey,O=Sagemcom Ca,C=FR) ----- ERROR: No matching issuer found [355148:355220:1022/173005.353104:ERROR:ssl_client_socket_impl.cc(970)] handshake failed; returned -1, SSL error code 1, net_error -202 17:30:05.354 Debug: "Server's certificate is not trusted." " there are 1 certificates in chain. From https://ubuntu-2/public/map_tiles/Berlin_Straube/12/2200/2200_2752_12.png" (mainwindow.cpp:5254, MainWindow::openWebViewPanel()::<lambda(QWebEngineCertificateError)>) 17:30:05.354 Warning: Unimplemented code. (:0, (null)) 17:30:05.354 Debug: "" (mainwindow.cpp:5256, MainWindow::openWebViewPanel()::<lambda(QWebEngineCertificateError)>) 17:30:05.354 Debug: "name: self-signedKey expires:Sun Sep 20 12:32:29 2111 GMT isSelf-signed: yes" (mainwindow.cpp:5257, MainWindow::openWebViewPanel()::<lambda(QWebEngineCertificateError)>) 17:30:05.354 Debug: accepting certificate (mainwindow.cpp:5262, MainWindow::openWebViewPanel()::<lambda(QWebEngineCertificateError)>) [355148:355220:1022/173005.355842:ERROR:ssl_client_socket_impl.cc(970)] handshake failed; returned -1, SSL error code 1, net_error -202 [355148:355220:1022/173005.359438:ERROR:ssl_client_socket_impl.cc(970)] handshake failed; returned -1, SSL error code 1, net_error -202 [355148:355220:1022/173005.362129:ERROR:ssl_client_socket_impl.cc(970)] handshake failed; returned -1, SSL error code 1, net_error -202 [355148:355220:1022/173005.365752:ERROR:ssl_client_socket_impl.cc(970)] handshake failed; returned -1, SSL error code 1, net_error -202 [355148:355220:1022/173005.368785:ERROR:ssl_client_socket_impl.cc(970)] handshake failed; returned -1, SSL error code 1, net_error -202
Note that in my code, I accepted the Certificate, further calls to load tiles fail and do not get caught by the code to catch a QWebEngineCertificateError but instead a QWebEngineView console message displays the SSL error code. also, the call to cert.toText() returns "Warning: Unimplemented code.".
I have tried to determine some way to essentially tell QWebEngineView that my certificate can be trusted in the same way as is done on Firefox. I assume from the message "ERROR: No matching issuer found" that this may be the reason why it cannot continue even though I accepted the error in my code.
Can somebody explain what I need to do in order to get QWebEngineView to accept my certificate?
-