Skip to content

Commit

Permalink
Add own certificate to the settings view
Browse files Browse the repository at this point in the history
The own certificate can be viewed and replaced
  • Loading branch information
basyskom-jvoe committed Jul 10, 2024
1 parent 4d3d329 commit 6d0e605
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -998,6 +1004,12 @@ void BackEnd::removeRecentConnection(const QString &name)
}
}

void BackEnd::regenerateOwnCertificate()
{
X509Certificate::createCertificate(defaultPkiPath());
mOwnCertificateItemModel->updateCertificateList();
}

void BackEnd::saveLastDashboards()
{
Q_ASSERT(mDashboardItemModel);
Expand Down
6 changes: 6 additions & 0 deletions src/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class BackEnd : public QObject
Q_PROPERTY(QVector<QString> endpointList READ endpointList NOTIFY endpointListChanged FINAL)
Q_PROPERTY(CertificateItemModel *certificateItemModel READ certificateItemModel NOTIFY
certificateItemModelChanged FINAL)
Q_PROPERTY(CertificateItemModel *ownCertificateItemModel READ ownCertificateItemModel CONSTANT
FINAL)
Q_PROPERTY(LoggingViewFilterModel *loggingViewModel READ loggingViewModel NOTIFY
loggingViewModelChanged FINAL)
Q_PROPERTY(OpcUaModel *opcUaModel READ opcUaModel NOTIFY opcUaModelChanged FINAL)
Expand Down Expand Up @@ -156,6 +158,7 @@ class BackEnd : public QObject
const QVector<QString> &serverList() const noexcept;
QVector<QString> endpointList() const;
CertificateItemModel *certificateItemModel() const noexcept;
CertificateItemModel *ownCertificateItemModel() const noexcept;
LoggingViewFilterModel *loggingViewModel() const noexcept;
OpcUaModel *opcUaModel() const noexcept;
DashboardItemModel *dashboardItemModel() const noexcept;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -283,6 +288,7 @@ private slots:
std::shared_ptr<QSet<QString>> visitedNodes = nullptr);

CertificateItemModel *mCertificateItemModel;
CertificateItemModel *mOwnCertificateItemModel;
LoggingViewModel *mLoggingViewModel;

OpcUaModel *mOpcUaModel;
Expand Down
8 changes: 8 additions & 0 deletions src/languages/English_en_GB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@
<source>Certificates</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Own certificate</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Trusted certificates</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Connection</name>
Expand Down
8 changes: 8 additions & 0 deletions src/languages/German_de_DE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@
<source>Certificates</source>
<translation>Zertifikate</translation>
</message>
<message>
<source>Own certificate</source>
<translation>Eigenes Zertifikat</translation>
</message>
<message>
<source>Trusted certificates</source>
<translation>Vertrauenswürdige Zertifikate</translation>
</message>
</context>
<context>
<name>Connection</name>
Expand Down
156 changes: 156 additions & 0 deletions src/qml/SettingsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6d0e605

Please sign in to comment.