Skip to content

Commit

Permalink
SmartID support
Browse files Browse the repository at this point in the history
IB-5908

Signed-off-by: Raul Metsma <raul@metsma.ee>
  • Loading branch information
metsma committed Nov 18, 2019
1 parent 3299ef2 commit 1c49151
Show file tree
Hide file tree
Showing 17 changed files with 1,018 additions and 39 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ include_directories( ${LIBDIGIDOCPP_INCLUDE_DIR} )
set_env( TSL_URL "https://ec.europa.eu/tools/lotl/eu-lotl.xml" CACHE STRING "TSL trust list primary URL" )
set_env( TSL_INCLUDE "EE" CACHE STRING "TSL list include in binary" )
set_env( MOBILEID_URL "https://tsp.demo.sk.ee/mid-api" CACHE STRING "URL for Mobile-ID" )
set_env( SMARTID_URL "https://sid.demo.sk.ee/smart-id-rp/v1" CACHE STRING "URL for Smart-ID" )

if(APPLE)
set(BUNDLE_NAME qdigidoc4)
Expand Down
6 changes: 6 additions & 0 deletions client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ void Application::diagnostics(QTextStream &s)
<< "<br />SIVA_URL: " << confValue(SiVaUrl).toString()
#ifdef MOBILEID_URL
<< "<br />MOBILEID_URL: " << MOBILEID_URL
#endif
#ifdef SMARTID_URL
<< "<br />SMARTID_URL: " << SMARTID_URL
#endif
<< "<br /><br /><b>" << tr("TSL signing certs") << ":</b>";
for(const QSslCertificate &cert: confValue(TSLCerts).value<QList<QSslCertificate>>())
Expand Down Expand Up @@ -1027,6 +1030,9 @@ void DdCliApplication::diagnostics(QTextStream &s) const

#ifdef MOBILEID_URL
s << "<br />MOBILEID_URL: " << MOBILEID_URL;
#endif
#ifdef SMARTID_URL
s << "<br />SMARTID_URL: " << SMARTID_URL;
#endif
s << "<br />TSL_URL: " << Application::confValue(Application::TSLUrl).toString();
s << "<br /><br /><b>" << "TSL signing certs:</b>";
Expand Down
5 changes: 4 additions & 1 deletion client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ qt5_wrap_ui( SOURCES
dialogs/RoleAddressDialog.ui
dialogs/SettingsDialog.ui
dialogs/SignatureDialog.ui
dialogs/SmartIDDialog.ui
dialogs/WaitDialog.ui
dialogs/WarningDialog.ui
widgets/Accordion.ui
Expand Down Expand Up @@ -86,6 +87,8 @@ add_executable( ${PROGNAME} WIN32 MACOSX_BUNDLE
dialogs/PinUnblock.cpp
dialogs/RoleAddressDialog.cpp
dialogs/SettingsDialog.cpp
dialogs/SmartIDDialog.cpp
dialogs/SmartIDProgress.cpp
dialogs/SignatureDialog.cpp
dialogs/WaitDialog.cpp
dialogs/WarningDialog.cpp
Expand Down Expand Up @@ -125,7 +128,7 @@ target_link_libraries( ${PROGNAME}
${LDAP_LIBRARIES}
)

target_compile_definitions(${PROGNAME} PRIVATE MOBILEID_URL="${MOBILEID_URL}")
target_compile_definitions(${PROGNAME} PRIVATE MOBILEID_URL="${MOBILEID_URL}" SMARTID_URL="${SMARTID_URL}" )

if( APPLE )
target_sources( ${PROGNAME} PRIVATE Application_mac.mm dialogs/CertificateDetails_mac.mm Diagnostics_unix.cpp)
Expand Down
9 changes: 9 additions & 0 deletions client/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "dialogs/MobileProgress.h"
#include "dialogs/RoleAddressDialog.h"
#include "dialogs/SettingsDialog.h"
#include "dialogs/SmartIDProgress.h"
#include "dialogs/WaitDialog.h"
#include "dialogs/WarningDialog.h"
#include "widgets/WarningList.h"
Expand Down Expand Up @@ -498,6 +499,14 @@ void MainWindow::onSignAction(int action, const QString &info1, const QString &i
return digiDoc->sign(city, state, zip, country, role, &m);
});
break;
case SignatureSmartID:
sign([this, info1, info2](const QString &city, const QString &state, const QString &zip, const QString &country, const QString &role) {
SmartIDProgress s(this);
if(!s.init(info1, info2))
return false;
return digiDoc->sign(city, state, zip, country, role, &s);
});
break;
case ClearSignatureWarning:
ui->signature->warningIcon(false);
warnings->closeWarnings(SignDetails);
Expand Down
1 change: 1 addition & 0 deletions client/common_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ enum Actions {

SignatureAdd,
SignatureMobile,
SignatureSmartID,
SignatureToken,
SignatureRemove,
SignatureWarning,
Expand Down
4 changes: 2 additions & 2 deletions client/dialogs/MobileProgress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ MobileProgress::MobileProgress(QWidget *parent)
returnError(tr("Connecting to SK server failed! Please check your internet connection."));
return;
case QNetworkReply::ConnectionRefusedError:
returnError(tr("Mobile-ID service has encountered technical errors. Please try again later."));
returnError(tr("%1 service has encountered technical errors. Please try again later.").arg(tr("Mobile-ID")));
return;
case QNetworkReply::SslHandshakeFailedError:
d->l.exit(Private::GeneralError);
return;
default:
qCWarning(MIDLog) << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() << "Error :" << reply->error();
if(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 429)
returnError(tr("Failed to sign container. Check your Mobile-ID service access settings. <a href=\"https://www.id.ee/index.php?id=39023\">Additional information</a>"));
returnError(tr("Failed to sign container. Check your %1 service access settings. <a href=\"https://www.id.ee/index.php?id=39023\">Additional information</a>").arg(tr("Mobile-ID")));
else
returnError(tr("Failed to send request ") + reply->errorString());
return;
Expand Down
3 changes: 0 additions & 3 deletions client/dialogs/MobileProgress.ui
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
<height>185</height>
</size>
</property>
<property name="windowTitle">
<string>Signing with Mobile-ID</string>
</property>
<property name="styleSheet">
<string notr="true">border-radius: 2px;
background-color: #FFFFFF;</string>
Expand Down
80 changes: 80 additions & 0 deletions client/dialogs/SmartIDDialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "SmartIDDialog.h"
#include "ui_SmartIDDialog.h"

#include "Settings.h"
#include "Styles.h"
#include "effects/Overlay.h"

#include <common/IKValidator.h>

SmartIDDialog::SmartIDDialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::SmartIDDialog)
{
Overlay *overlay = new Overlay(parent->topLevelWidget());
overlay->show();
connect(this, &SmartIDDialog::destroyed, overlay, &Overlay::deleteLater);

ui->setupUi(this);
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
setWindowModality( Qt::ApplicationModal);
setFixedSize(size());
QFont condensed12 = Styles::font(Styles::Condensed, 12);
QFont condensed14 = Styles::font(Styles::Condensed, 14);
QFont header = Styles::font(Styles::Regular, 14);
QFont regularFont = Styles::font(Styles::Regular, 14);
header.setWeight(QFont::DemiBold);
ui->cbRemember->setFont(Styles::font(Styles::Regular, 14));
ui->labelNameId->setFont(header);
ui->labelCode->setFont(condensed12);
ui->labelCountry->setFont(condensed12);
ui->idCode->setFont(regularFont);
ui->idCountry->setFont(regularFont);
ui->sign->setFont(condensed14);
ui->cancel->setFont(condensed14);

Settings s(qApp->applicationName());
QValidator *ik = new IKValidator(ui->idCode);
ui->idCode->setValidator(ik);
ui->idCode->setText(s.value(QStringLiteral("SmartID")).toString());
ui->idCountry->setItemData(0, "EE");
ui->idCountry->setItemData(1, "LT");
ui->idCountry->setItemData(2, "LV");
ui->idCountry->setCurrentIndex(ui->idCountry->findData(s.value(QStringLiteral("SmartIDCountry"), QStringLiteral("EE")).toString()));
ui->cbRemember->setChecked(s.value(QStringLiteral("SmartIDSettings"), true).toBool());
connect(ui->sign, &QPushButton::clicked, this, &QDialog::accept);
connect(ui->cancel, &QPushButton::clicked, this, &QDialog::reject);

auto enableSign = [=] {
const QString EE = QStringLiteral("EE");
ui->idCode->setValidator(country() == EE ? ik : nullptr);
bool checked = ui->cbRemember->isChecked();
Settings s(qApp->applicationName());
s.setValueEx(QStringLiteral("SmartIDSettings"), checked, true);
s.setValueEx(QStringLiteral("SmartID"), checked ? idCode() : QString(), QString());
s.setValueEx(QStringLiteral("SmartIDCountry"), checked ? country() : EE, EE);
ui->sign->setToolTip(QString());
if(!idCode().isEmpty() && country() == EE && !IKValidator::isValid(idCode()))
ui->sign->setToolTip(tr("Personal code is not valid"));
ui->sign->setEnabled(!idCode().isEmpty() && ui->sign->toolTip().isEmpty());
};
connect(ui->idCode, &QLineEdit::textEdited, this, enableSign);
connect(ui->idCountry, &QComboBox::currentTextChanged, this, enableSign);
connect(ui->cbRemember, &QCheckBox::clicked, this, enableSign);
enableSign();
}

SmartIDDialog::~SmartIDDialog()
{
delete ui;
}

QString SmartIDDialog::country() const
{
return ui->idCountry->currentData().toString();
}

QString SmartIDDialog::idCode() const
{
return ui->idCode->text();
}
20 changes: 20 additions & 0 deletions client/dialogs/SmartIDDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <QDialog>

namespace Ui { class SmartIDDialog; }

class SmartIDDialog : public QDialog
{
Q_OBJECT

public:
explicit SmartIDDialog(QWidget *parent = nullptr);
~SmartIDDialog() final;

QString country() const;
QString idCode() const;

private:
Ui::SmartIDDialog *ui;
};
Loading

0 comments on commit 1c49151

Please sign in to comment.