Skip to content

Commit

Permalink
Enc SSL cert
Browse files Browse the repository at this point in the history
Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma committed Nov 27, 2024
1 parent ef37cc8 commit 788c384
Show file tree
Hide file tree
Showing 6 changed files with 589 additions and 425 deletions.
46 changes: 39 additions & 7 deletions client/dialogs/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ SettingsDialog::SettingsDialog(int page, QWidget *parent)
ui->txtMIDUUID->setReadOnly(Settings::MID_UUID.isLocked());
ui->txtMIDUUID->setVisible(ui->rdMIDUUIDCustom->isChecked());
ui->txtMIDUUID->setText(Settings::MID_UUID);
connect(ui->rdMIDUUIDCustom, &QRadioButton::toggled, ui->txtMIDUUID, [=](bool checked) {
connect(ui->rdMIDUUIDCustom, &QRadioButton::toggled, ui->txtMIDUUID, [this](bool checked) {
ui->txtMIDUUID->setVisible(checked);
Settings::MID_UUID_CUSTOM = checked;
Settings::SID_UUID_CUSTOM = checked;
Expand Down Expand Up @@ -221,6 +221,7 @@ SettingsDialog::SettingsDialog(int page, QWidget *parent)
ui->txtCdoc2UUID->setReadOnly(disabled);
ui->txtCdoc2Fetch->setReadOnly(disabled);
ui->txtCdoc2Post->setReadOnly(disabled);
ui->wgtCDoc2Cert->setHidden(disabled);
};
for(QJsonObject::const_iterator i = list.constBegin(); i != list.constEnd(); ++i)
ui->cmbCdoc2Name->addItem(i.value().toObject().value(QLatin1String("NAME")).toString(), i.key());
Expand All @@ -234,14 +235,40 @@ SettingsDialog::SettingsDialog(int page, QWidget *parent)
});
setCDoc2Values(cdoc2Service);
connect(ui->txtCdoc2UUID, &QLineEdit::textEdited, this, Settings::CDOC2_UUID);
connect(ui->txtCdoc2Fetch, &QLineEdit::textEdited, this, Settings::CDOC2_GET);
connect(ui->txtCdoc2Post, &QLineEdit::textEdited, this, Settings::CDOC2_POST);
connect(ui->txtCdoc2Fetch, &QLineEdit::textEdited, this, [this](const QString &url) {
Settings::CDOC2_GET = url;
if(url.isEmpty())
{
Settings::CDOC2_GET_CERT.clear();
Settings::CDOC2_POST_CERT.clear();
updateCDoc2Cert(QSslCertificate());
}
});
connect(ui->txtCdoc2Post, &QLineEdit::textEdited, this, [this](const QString &url) {
Settings::CDOC2_POST = url;
if(url.isEmpty())
{
Settings::CDOC2_GET_CERT.clear();
Settings::CDOC2_POST_CERT.clear();
updateCDoc2Cert(QSslCertificate());
}
});
#else
ui->cmbCdoc2Name->addItem(QStringLiteral("Default"));
ui->txtCdoc2UUID->setText(QStringLiteral("00000000-0000-0000-0000-000000000000"));
ui->txtCdoc2Fetch->setText(QStringLiteral(CDOC2_GET_URL));
ui->txtCdoc2Post->setText(QStringLiteral(CDOC2_POST_URL));
#endif
connect(ui->btInstallCDoc2Cert, &QPushButton::clicked, this, [this] {
QSslCertificate cert = selectCert(tr("Select encryption server certificate"),
tr("Encryption Service SSL certificate"));
if(cert.isNull())
return;
Settings::CDOC2_GET_CERT = cert.toDer().toBase64();
Settings::CDOC2_POST_CERT = cert.toDer().toBase64();
updateCDoc2Cert(cert);
});
updateCDoc2Cert(QSslCertificate(QByteArray::fromBase64(Settings::CDOC2_GET_CERT), QSsl::Der));

// pageProxy
connect(this, &SettingsDialog::finished, this, &SettingsDialog::saveProxy);
Expand Down Expand Up @@ -313,7 +340,7 @@ SettingsDialog::SettingsDialog(int page, QWidget *parent)
dlg->open();
});
#ifdef CONFIG_URL
connect(qApp->conf(), &Configuration::finished, this, [=](bool /*update*/, const QString &error){
connect(qApp->conf(), &Configuration::finished, this, [this](bool /*update*/, const QString &error){
if(!error.isEmpty()) {
WarningDialog::show(this, tr("Checking updates has failed.") + "<br />" + tr("Please try again."), error);
return;
Expand All @@ -334,10 +361,10 @@ SettingsDialog::SettingsDialog(int page, QWidget *parent)
Application::updateTSLCache({});
});
connect(ui->btnNavUseByDefault, &QPushButton::clicked, this, &SettingsDialog::useDefaultSettings);
connect(ui->btnNavSaveReport, &QPushButton::clicked, this, [=]{
connect(ui->btnNavSaveReport, &QPushButton::clicked, this, [this]{
saveFile(QStringLiteral("diagnostics.txt"), ui->txtDiagnostics->toPlainText().toUtf8());
});
connect(ui->btnNavSaveLibdigidocpp, &QPushButton::clicked, this, [=]{
connect(ui->btnNavSaveLibdigidocpp, &QPushButton::clicked, this, [this]{
Settings::LIBDIGIDOCPP_DEBUG = false;
QString log = QStringLiteral("%1/libdigidocpp.log").arg(QDir::tempPath());
saveFile(QStringLiteral("libdigidocpp.txt"), log);
Expand Down Expand Up @@ -439,6 +466,11 @@ void SettingsDialog::updateCert(const QSslCertificate &c, QPushButton *btn, Cert
});
}

void SettingsDialog::updateCDoc2Cert(const QSslCertificate &c)
{
updateCert(c, ui->btShowCDoc2Cert, ui->txtCDoc2Cert);
}

void SettingsDialog::updateSiVaCert(const QSslCertificate &c)
{
updateCert(c, ui->btShowSiVaCert, ui->txtSiVaCert);
Expand Down Expand Up @@ -519,7 +551,7 @@ void SettingsDialog::updateDiagnostics()
QApplication::setOverrideCursor( Qt::WaitCursor );
auto *worker = new Diagnostics();
connect(worker, &Diagnostics::update, ui->txtDiagnostics, &QTextBrowser::insertHtml, Qt::QueuedConnection);
connect(worker, &Diagnostics::destroyed, this, [=]{
connect(worker, &Diagnostics::destroyed, this, [this]{
ui->txtDiagnostics->setEnabled(true);
ui->txtDiagnostics->moveCursor(QTextCursor::Start);
ui->txtDiagnostics->ensureCursorVisible();
Expand Down
1 change: 1 addition & 0 deletions client/dialogs/SettingsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class SettingsDialog final: public QDialog
QSslCertificate selectCert(const QString &label, const QString &format);
void selectLanguage();
void updateCert(const QSslCertificate &c, QPushButton *btn, CertLabel *lbl);
void updateCDoc2Cert(const QSslCertificate &c);
void updateSiVaCert(const QSslCertificate &c);
void updateTSACert(const QSslCertificate &c);
void updateVersion();
Expand Down
Loading

0 comments on commit 788c384

Please sign in to comment.