From bbf88cad77213ad78b7e480c1e57023f686a023a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20V=C3=B6lker?= Date: Wed, 10 Jul 2024 14:42:10 +0200 Subject: [PATCH] Add own certificate to the settings view The own certificate can be viewed and replaced --- src/backend.cpp | 15 +++- src/backend.h | 7 ++ src/languages/English_en_GB.ts | 8 ++ src/languages/German_de_DE.ts | 8 ++ src/qml/SettingsView.qml | 156 +++++++++++++++++++++++++++++++++ 5 files changed, 193 insertions(+), 1 deletion(-) diff --git a/src/backend.cpp b/src/backend.cpp index fb3ca00..34c94af 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -64,6 +64,8 @@ static void removeItemFromStringListModel(QStringListModel *model, const QString BackEnd::BackEnd(QObject *parent) : QObject{ parent }, mCertificateItemModel(new CertificateItemModel(defaultTrustedCertsPath(), this)), + mOwnCertificateItemModel( + new CertificateItemModel(defaultPkiPath() % QStringLiteral("/own/certs/"), this)), mLoggingViewModel(new LoggingViewModel(this)), mOpcUaModel(new OpcUaModel(this)), mOpcUaProvider(new QOpcUaProvider(this)), @@ -165,6 +167,11 @@ CertificateItemModel *BackEnd::certificateItemModel() const noexcept return mCertificateItemModel; } +CertificateItemModel *BackEnd::ownCertificateItemModel() const noexcept +{ + return mOwnCertificateItemModel; +} + LoggingViewFilterModel *BackEnd::loggingViewModel() const noexcept { return mLoggingViewModel->getFilteredModel(); @@ -558,7 +565,6 @@ int BackEnd::instantiateDefaultEventDashboard(const QString &name) void BackEnd::renameSavedVariableDashboard(const QString &previousName, const QString &newName) { - QSettings settings; const QString settingsGroupName = Constants::SettingsKey::DashboardsVariables % QChar::fromLatin1('/') % previousName; @@ -998,6 +1004,13 @@ void BackEnd::removeRecentConnection(const QString &name) } } +void BackEnd::regenerateOwnCertificate() +{ + X509Certificate::createCertificate(defaultPkiPath()); + mOwnCertificateItemModel->updateCertificateList(); + emit ownCertificateItemModelChanged(); +} + void BackEnd::saveLastDashboards() { Q_ASSERT(mDashboardItemModel); diff --git a/src/backend.h b/src/backend.h index c5e5b5e..1845536 100644 --- a/src/backend.h +++ b/src/backend.h @@ -125,6 +125,8 @@ class BackEnd : public QObject Q_PROPERTY(QVector endpointList READ endpointList NOTIFY endpointListChanged FINAL) Q_PROPERTY(CertificateItemModel *certificateItemModel READ certificateItemModel NOTIFY certificateItemModelChanged FINAL) + Q_PROPERTY(CertificateItemModel *ownCertificateItemModel READ ownCertificateItemModel NOTIFY + ownCertificateItemModelChanged FINAL) Q_PROPERTY(LoggingViewFilterModel *loggingViewModel READ loggingViewModel NOTIFY loggingViewModelChanged FINAL) Q_PROPERTY(OpcUaModel *opcUaModel READ opcUaModel NOTIFY opcUaModelChanged FINAL) @@ -156,6 +158,7 @@ class BackEnd : public QObject const QVector &serverList() const noexcept; QVector endpointList() const; CertificateItemModel *certificateItemModel() const noexcept; + CertificateItemModel *ownCertificateItemModel() const noexcept; LoggingViewFilterModel *loggingViewModel() const noexcept; OpcUaModel *opcUaModel() const noexcept; DashboardItemModel *dashboardItemModel() const noexcept; @@ -223,6 +226,8 @@ class BackEnd : public QObject Q_INVOKABLE void removeRecentConnection(const QString &name); + Q_INVOKABLE void regenerateOwnCertificate(); + int maxEventsPerObject() const; void setMaxEventsPerObject(int newMaxEventsPerObject); @@ -233,6 +238,7 @@ class BackEnd : public QObject void stateTextChanged(); void connectionStateChanged(); void certificateItemModelChanged(); + void ownCertificateItemModelChanged(); void loggingViewModelChanged(); void opcUaModelChanged(); void defaultVariableDashboardsChanged(); @@ -283,6 +289,7 @@ private slots: std::shared_ptr> visitedNodes = nullptr); CertificateItemModel *mCertificateItemModel; + CertificateItemModel *mOwnCertificateItemModel; LoggingViewModel *mLoggingViewModel; OpcUaModel *mOpcUaModel; diff --git a/src/languages/English_en_GB.ts b/src/languages/English_en_GB.ts index a5a9b6c..de34e30 100644 --- a/src/languages/English_en_GB.ts +++ b/src/languages/English_en_GB.ts @@ -146,6 +146,14 @@ Certificates + + Own certificate + + + + Trusted certificates + + Connection diff --git a/src/languages/German_de_DE.ts b/src/languages/German_de_DE.ts index 1910d44..9b54f6b 100644 --- a/src/languages/German_de_DE.ts +++ b/src/languages/German_de_DE.ts @@ -146,6 +146,14 @@ Certificates Zertifikate + + Own certificate + Eigenes Zertifikat + + + Trusted certificates + Vertrauenswürdige Zertifikate + Connection diff --git a/src/qml/SettingsView.qml b/src/qml/SettingsView.qml index 8c93ccf..c4180ed 100644 --- a/src/qml/SettingsView.qml +++ b/src/qml/SettingsView.qml @@ -545,6 +545,162 @@ Rectangle { text: qsTranslate("Certificate", "Certificates") } + Text { + color: view.theme.textColor + font { + pointSize: 12 + bold: true + } + text: qsTranslate("Certificate", "Own certificate") + } + + Rectangle { + color: view.theme.backgroundListView + radius: 5 + + width: parent.width + height: childrenRect.height + + ListView { + id: ownCert + + width: parent.width + height: 265 + + clip: true + + model: BackEnd.ownCertificateItemModel + boundsBehavior: Flickable.StopAtBounds + boundsMovement: Flickable.StopAtBounds + + ScrollBar.vertical: StyledScrollBar { + policy: ScrollBar.AsNeeded + } + + delegate: Rectangle { + id: ownCertListViewDelegate + + component OwnSubitemText : Text { + Layout.leftMargin: 5 + Layout.rightMargin: 5 + Layout.fillWidth: true + verticalAlignment: Qt.AlignVCenter + color: view.theme.textColor + } + + component OwnSubitemTitle : OwnSubitemText { + elide: Qt.ElideRight + font { + pointSize: 11 + bold: true + } + } + + required property int index + required property string issuerDisplayName + required property date effectiveDate + required property string fingerprint + required property date expiryDate + required property string commonName + required property string serialNumber + + radius: 5 + width: ownCert.width + implicitHeight: delegateLayout.height + color: view.theme.backgroundSelected + clip: true + + ColumnLayout { + id: delegateLayout + + width: parent.width + spacing: 0 + + RowLayout { + Layout.fillWidth: true + Layout.preferredHeight: 36 + + Text { + Layout.fillWidth: true + Layout.leftMargin: 5 + font.pointSize: 14 + text: ownCertListViewDelegate.issuerDisplayName + color: view.theme.textColor + elide: Text.ElideRight + } + + IconImage { + Layout.alignment: Qt.AlignVCenter + Layout.rightMargin: 10 + sourceSize.width: 24 + sourceSize.height: 24 + source: "qrc:/icons/refresh.svg" + color: view.theme.textColor + + MouseArea { + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + onClicked: BackEnd.regenerateOwnCertificate() + } + } + } + + OwnSubitemTitle { + text: qsTranslate("Certificate", "Valid from") + } + + OwnSubitemText { + text: ownCertListViewDelegate.effectiveDate.toLocaleString(Qt.locale(), qsTranslate("General", "MM/dd/yyyy")) + } + + OwnSubitemTitle { + text: qsTranslate("Certificate", "Valid to") + } + + OwnSubitemText { + text: ownCertListViewDelegate.expiryDate.toLocaleString(Qt.locale(), qsTranslate("General", "MM/dd/yyyy")) + } + + OwnSubitemTitle { + text: qsTranslate("Certificate", "Fingerprint (SHA-256)") + } + + OwnSubitemText { + text: ownCertListViewDelegate.fingerprint + wrapMode: Text.Wrap + } + + OwnSubitemTitle { + text: qsTranslate("Certificate", "Common name") + } + + OwnSubitemText { + text: ownCertListViewDelegate.commonName + } + + OwnSubitemTitle { + text: qsTranslate("Certificate", "Serial number") + } + + OwnSubitemText { + Layout.bottomMargin: 5 + text: ownCertListViewDelegate.serialNumber + wrapMode: Text.Wrap + } + } + } + } + } + + Text { + color: view.theme.textColor + font { + pointSize: 12 + bold: true + } + text: qsTranslate("Certificate", "Trusted certificates") + } + Rectangle { color: view.theme.backgroundListView radius: 5