summaryrefslogtreecommitdiffstats
path: root/src/core/type_conversion.cpp
diff options
context:
space:
mode:
authorKirill Burtsev <kirill.burtsev@qt.io>2019-08-26 13:46:35 +0200
committerKirill Burtsev <kirill.burtsev@qt.io>2019-09-05 23:33:12 +0200
commit8d045ce2a4cc65660bdf6ee8b555899c5c6119de (patch)
treef25ecfc6b167993215f6808d1a6ada105c069524 /src/core/type_conversion.cpp
parentbf3753f02402b44455038c4fa2a897d41aadf850 (diff)
Api to get certificate's chain on error
Expose certificate's chain on validation error starting with the immediate certificate and ending with the CA's certificate. [ChangeLog][QtWebEngineWidgets][QWebEngineCertificateError] New method to get the peer's chain of digital certificates. Fixes: QTBUG-51176 Change-Id: I799dfe9e44f9f2517f4691d175beee256114af79 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'src/core/type_conversion.cpp')
-rw-r--r--src/core/type_conversion.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/core/type_conversion.cpp b/src/core/type_conversion.cpp
index 02d2db448..ddadeb9f2 100644
--- a/src/core/type_conversion.cpp
+++ b/src/core/type_conversion.cpp
@@ -40,11 +40,14 @@
#include "type_conversion.h"
#include <content/public/common/favicon_url.h>
+#include <net/cert/x509_certificate.h>
+#include <net/cert/x509_util.h>
#include <ui/events/event_constants.h>
#include <ui/gfx/image/image_skia.h>
#include <QtCore/qcoreapplication.h>
#include <QtGui/qmatrix4x4.h>
+#include <QtNetwork/qsslcertificate.h>
namespace QtWebEngineCore {
@@ -256,4 +259,20 @@ void convertToQt(const SkMatrix44 &m, QMatrix4x4 &c)
c = qtMatrix;
}
+static QSslCertificate toCertificate(CRYPTO_BUFFER *buffer)
+{
+ auto derCert = net::x509_util::CryptoBufferAsStringPiece(buffer);
+ return QSslCertificate(QByteArray::fromRawData(derCert.data(), derCert.size()), QSsl::Der);
+}
+
+QList<QSslCertificate> toCertificateChain(net::X509Certificate *certificate)
+{
+ // from leaf to root as in QtNetwork
+ QList<QSslCertificate> chain;
+ chain.append(toCertificate(certificate->cert_buffer()));
+ for (auto &&buffer : certificate->intermediate_buffers())
+ chain.append(toCertificate(buffer.get()));
+ return chain;
+}
+
} // namespace QtWebEngineCore