Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ Application::Application( int &argc, char **argv )

// Clear obsolete registriy settings
Settings::CDOC2_NOTIFICATION.clear();
Settings::MOBILEID_ORDER.clear();
#ifndef Q_OS_DARWIN
Settings::DEFAULT_DIR.clear();
#endif
Expand Down
7 changes: 4 additions & 3 deletions client/CDocSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,13 @@ DDCryptoBackend::getLastErrorStr(libcdoc::result_t code) const
static bool
checkConnection()
{
if(CheckConnection().check()) {
CheckConnection check;
if(check.check()) {
return true;
}
return dispatchToMain([] {
return dispatchToMain([check] {
FadeInNotification::error(Application::mainWindow()->findChild<QWidget*>(QStringLiteral("topBar")),
QCoreApplication::translate("MainWindow", "Check internet connection"));
check.errorString());
return false;
});
}
Expand Down
3 changes: 1 addition & 2 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_subdirectory(libcdoc EXCLUDE_FROM_ALL)
file(GLOB WIDGETS CONFIGURE_DEPENDS
"dialogs/*.cpp" "dialogs/*.h" "dialogs/*.ui"
"effects/*.cpp" "effects/*.h" "effects/*.ui"
"signer/*.cpp" "signer/*.h"
"widgets/*.cpp" "widgets/*.h" "widgets/*.ui"
)
add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE
Expand Down Expand Up @@ -66,8 +67,6 @@ add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE
QPCSC.h
QPKCS11.cpp
QPKCS11.h
QSigner.cpp
QSigner.h
QSmartCard.cpp
QSmartCard_p.h
QSmartCard.h
Expand Down
2 changes: 1 addition & 1 deletion client/CheckConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ QString CheckConnection::errorString() const
case QNetworkReply::ProxyAuthenticationRequiredError:
return QCoreApplication::translate("CheckConnection", "Check proxy username and password");
default:
return QCoreApplication::translate("CheckConnection", "Cannot connect to certificate status service!");
return QCoreApplication::translate("CheckConnection", "Check internet connection");
}
}

Expand Down
123 changes: 46 additions & 77 deletions client/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@
#include "DigiDoc.h"
#include "QCryptoBackend.h"
#include "QPCSC.h"
#include "QSigner.h"
#include "Settings.h"
#include "SslCertificate.h"
#include "TokenData.h"
#include "effects/FadeInNotification.h"
#include "effects/Overlay.h"
#include "dialogs/FileDialog.h"
#include "dialogs/MobileProgress.h"
#include "dialogs/RoleAddressDialog.h"
#include "dialogs/SettingsDialog.h"
#include "dialogs/SmartIDProgress.h"
#include "dialogs/SigningDialog.h"
#include "dialogs/WaitDialog.h"
#include "dialogs/WarningDialog.h"
#include "widgets/CardPopup.h"
Expand Down Expand Up @@ -101,8 +99,11 @@ MainWindow::MainWindow( QWidget *parent )
connect(qApp->cryptoManager()->smartcard(), &QSmartCard::tokenChanged, this, &MainWindow::updateMyEID);
connect(qApp->cryptoManager()->smartcard(), &QSmartCard::dataChanged, this, &MainWindow::updateMyEid);

connect(ui->signIntroButton, &QPushButton::clicked, this, [this] { openContainer(true); });
connect(ui->cryptoIntroButton, &QPushButton::clicked, this, [this] { openContainer(false); });
connect(ui->signIntroButton, &QPushButton::clicked, this, [this] {
openContainer(QStringLiteral("*.bdoc *.ddoc *.asice *.sce *.asics *.scs *.edoc *.adoc%1")
.arg(Application::confValue(Application::SiVaUrl).toString().isEmpty() ? QLatin1String() : QLatin1String(" *.pdf")));
});
connect(ui->cryptoIntroButton, &QPushButton::clicked, this, [this] { openContainer(QLatin1String("*.cdoc *.cdoc2")); });
connect(ui->signContainerPage, &ContainerPage::action, this, &MainWindow::onSignAction);
connect(ui->signContainerPage, &ContainerPage::addFiles, this, [this](const QStringList &files) { openFiles(files); } );
connect(ui->signContainerPage, &ContainerPage::warning, this, [this](WarningText warningText) {
Expand All @@ -117,7 +118,7 @@ MainWindow::MainWindow( QWidget *parent )
ui->crypto->warningIcon(true);
});

connect(ui->accordion, &Accordion::changePinClicked, this, &MainWindow::changePinClicked);
connect(ui->infoStack, &MyEidInfo::changePinClicked, this, &MainWindow::changePinClicked);
connect(ui->cardInfo, &CardWidget::selected, ui->selector, &QToolButton::toggle);

ui->signContainerPage->tokenChanged(qApp->cryptoManager()->tokensign());
Expand Down Expand Up @@ -218,7 +219,6 @@ void MainWindow::mouseReleaseEvent(QMouseEvent *event)
{
if(auto *cardPopup = findChild<CardPopup*>())
cardPopup->deleteLater();
ui->signContainerPage->clearPopups();
QWidget::mouseReleaseEvent(event);
}

Expand Down Expand Up @@ -283,32 +283,14 @@ void MainWindow::navigateToPage( Pages page, const QStringList &files, bool crea
selectPage(page);
}

void MainWindow::onSignAction(int action, const QString &idCode, const QString &info2)
void MainWindow::onSignAction(int action)
{
switch(action)
{
case SignatureAdd:
case SignatureToken:
sign([this](const QString &city, const QString &state, const QString &zip, const QString &country, const QString &role) {
QSigner signer(qApp->cryptoManager()->tokensign());
return digiDoc->sign(city, state, zip, country, role, &signer);
});
break;
case SignatureMobile:
sign([this, idCode, info2](const QString &city, const QString &state, const QString &zip, const QString &country, const QString &role) {
MobileProgress m(this);
return m.init(idCode, info2) &&
digiDoc->sign(city, state, zip, country, role, &m);
});
sign();
break;
case SignatureSmartID:
sign([this, idCode, info2](const QString &city, const QString &state, const QString &zip, const QString &country, const QString &role) {
SmartIDProgress s(this);
return s.init(info2, idCode, digiDoc->fileName()) &&
digiDoc->sign(city, state, zip, country, role, &s);
});
break;
case ClearSignatureWarning:
case ContainerClearWarning:
ui->signature->warningIcon(false);
ui->warnings->closeWarnings(SignDetails);
break;
Expand Down Expand Up @@ -360,7 +342,7 @@ void MainWindow::convertToCDoc()
FadeInNotification::success(ui->topBar, tr("Converted to crypto container!"));
}

void MainWindow::onCryptoAction(int action, const QString &/*id*/, const QString &/*phone*/)
void MainWindow::onCryptoAction(int action)
{
switch(action)
{
Expand All @@ -379,7 +361,7 @@ void MainWindow::onCryptoAction(int action, const QString &/*id*/, const QString
case EncryptContainerSuccess:
FadeInNotification::success(ui->topBar, tr("Encryption succeeded!"));
break;
case ClearCryptoWarning:
case ContainerClearWarning:
ui->crypto->warningIcon(false);
ui->warnings->closeWarnings(CryptoDetails);
break;
Expand Down Expand Up @@ -451,13 +433,20 @@ void MainWindow::openFiles(QStringList files, bool addFile, bool forceCreate)
default:
if(addFile)
{
bool crypto = state & CryptoContainers;
if(wrapContainer(!crypto))
page = (state & CryptoContainers) ? CryptoDetails : SignDetails;
if(WarningDialog::create(this)
->withTitle(page == CryptoDetails ?
tr("Files can not be added to the cryptocontainer") :
tr("Files can not be added to the signed container"))
->withText(page == CryptoDetails ?
tr("The system will create a new container which shall contain the cypto-document and the files you wish to add.") :
tr("The system will create a new container which shall contain the signed document and the files you wish to add."))
->setCancelText(WarningDialog::Cancel)
->addButton(tr("Continue"), QMessageBox::Ok)
->exec() == QMessageBox::Ok)
files.insert(files.begin(), digiDoc->fileName());
else
create = false;

page = crypto ? CryptoDetails : SignDetails;
}
else
{
Expand All @@ -472,15 +461,10 @@ void MainWindow::openFiles(QStringList files, bool addFile, bool forceCreate)
navigateToPage(page, files, create);
}

void MainWindow::openContainer(bool signature)
void MainWindow::openContainer(const QString &filter)
{
QString filter = QFileDialog::tr("All Files (*)") + QStringLiteral(";;") + FileDialog::tr("Documents (%1)");
if(signature)
filter = filter.arg(QStringLiteral("*.bdoc *.ddoc *.asice *.sce *.asics *.scs *.edoc *.adoc%1")
.arg(Application::confValue(Application::SiVaUrl).toString().isEmpty() ? QLatin1String() : QLatin1String(" *.pdf")));
else
filter = filter.arg(QLatin1String("*.cdoc *.cdoc2"));
QStringList files = FileDialog::getOpenFileNames(this, tr("Select documents"), {}, filter);
QStringList files = FileDialog::getOpenFileNames(this, tr("Select documents"), {},
QFileDialog::tr("All Files (*)") + QStringLiteral(";;") + FileDialog::tr("Documents (%1)").arg(filter));
if(!files.isEmpty())
openFiles(std::move(files));
}
Expand Down Expand Up @@ -546,46 +530,51 @@ void MainWindow::showSettings(int page)
settings->show();
return;
}
SettingsDialog dlg(page, this);
connect(&dlg, &SettingsDialog::togglePrinting, ui->signContainerPage, &ContainerPage::togglePrinting);
dlg.exec();
auto *dlg = new SettingsDialog(page, this);
connect(dlg, &SettingsDialog::togglePrinting, ui->signContainerPage, &ContainerPage::togglePrinting);
dlg->open();
}

template<typename F>
void MainWindow::sign(F &&sign)
void MainWindow::sign()
{
if(!CheckConnection().check())
if(CheckConnection check; !check.check())
{
FadeInNotification::error(ui->topBar, tr("Check internet connection"));
FadeInNotification::error(ui->topBar, check.errorString());
return;
}

QString role, city, state, country, zip;
if(RoleAddressDialog(this).get(city, country, state, zip, role) == QDialog::Rejected)
return;

WaitDialogHolder waitDialog(this, tr("Signing"));
if(digiDoc->isPDF())
{
QString wrappedFile = digiDoc->fileName();
if(!wrap(wrappedFile, true))
QString pdfFile = digiDoc->fileName();
if(!wrap(pdfFile, true))
return;

if(!sign(city, state, zip, country, role))
SigningDialog dlg(digiDoc.get(), ui->signContainerPage);
dlg.setRoleAddress(city, country, state, zip, role);
if(dlg.exec() != QDialog::Accepted)
{
digiDoc.reset();
openFiles({std::move(wrappedFile)});
openFiles({std::move(pdfFile)});
return;
}
}
else if(!sign(city, state, zip, country, role))
return;
else
{
SigningDialog dlg(digiDoc.get(), ui->signContainerPage);
dlg.setRoleAddress(city, country, state, zip, role);
if(dlg.exec() != QDialog::Accepted)
return;
}
WaitDialogHolder waitDialog(this, tr("Signing"));

if(!digiDoc->save())
return;

ui->signContainerPage->transition(digiDoc.get());

FadeInNotification::success(ui->topBar, tr("The container has been successfully signed!"));
}

Expand All @@ -612,18 +601,6 @@ bool MainWindow::wrap(const QString& wrappedFile, bool pdf)
return true;
}

bool MainWindow::wrapContainer(bool signing)
{
return WarningDialog::create(this)
->withTitle(signing ? tr("Files can not be added to the signed container") : tr("Files can not be added to the cryptocontainer"))
->withText(signing ?
tr("The system will create a new container which shall contain the signed document and the files you wish to add.") :
tr("The system will create a new container which shall contain the cypto-document and the files you wish to add."))
->setCancelText(WarningDialog::Cancel)
->addButton(tr("Continue"), QMessageBox::Ok)
->exec() == QMessageBox::Ok;
}

void MainWindow::updateMyEID(const TokenData &t)
{
updateSelector();
Expand All @@ -633,7 +610,6 @@ void MainWindow::updateMyEID(const TokenData &t)
SslCertificate cert(t.cert());
auto type = cert.type();
ui->infoStack->setHidden(type == SslCertificate::UnknownType);
ui->accordion->setHidden(type == SslCertificate::UnknownType);
ui->noReaderInfo->setVisible(type == SslCertificate::UnknownType);

auto setText = [this](const char *text) {
Expand All @@ -643,26 +619,19 @@ void MainWindow::updateMyEID(const TokenData &t)
if(!t.isNull())
{
setText(QT_TR_NOOP("The card in the card reader is not an Estonian ID-card"));
if(ui->cardInfo->token().card() != t.card())
ui->accordion->clear();
if(type & SslCertificate::TempelType)
{
ui->infoStack->update(cert);
ui->accordion->updateInfo(cert);
}
}
else
{
ui->infoStack->clearData();
ui->accordion->clear();
setText(QT_TR_NOOP("Connect the card reader to your computer and insert your ID card into the reader"));
}
}

void MainWindow::updateMyEid(const QSmartCardData &data)
{
ui->infoStack->update(data);
ui->accordion->updateInfo(data);
ui->myEid->warningIcon(false);
ui->myEid->invalidIcon(false);
ui->warnings->closeWarnings(MyEid);
Expand Down
10 changes: 4 additions & 6 deletions client/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,15 @@ class MainWindow final : public QWidget
void changePinClicked(QSmartCardData::PinType type, QSmartCard::PinAction action);
void convertToCDoc();
void navigateToPage(Pages page, const QStringList &files = QStringList(), bool create = true);
void onCryptoAction(int action, const QString &id, const QString &phone);
void onSignAction(int action, const QString &idCode, const QString &info2);
void openContainer(bool signature);
void onCryptoAction(int action);
void onSignAction(int action);
void openContainer(const QString &filter);
void resetDigiDoc(std::unique_ptr<DigiDoc> &&doc);
template <typename F>
void sign(F &&sign);
void sign();
void updateSelector();
void updateMyEID(const TokenData &t);
void updateMyEid(const QSmartCardData &data);
bool wrap(const QString& wrappedFile, bool pdf);
bool wrapContainer(bool signing);

static QStringList dropEventFiles(QDropEvent *event);

Expand Down
22 changes: 7 additions & 15 deletions client/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>1025</width>
<height>600</height>
<width>1280</width>
<height>710</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>1024</width>
<height>600</height>
<width>1280</width>
<height>710</height>
</size>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -683,10 +683,7 @@ color: #BFD3E8;
<number>0</number>
</property>
<item>
<widget class="InfoStack" name="infoStack" native="true"/>
</item>
<item>
<widget class="Accordion" name="accordion" native="true"/>
<widget class="MyEidInfo" name="infoStack" native="true"/>
</item>
<item>
<widget class="QWidget" name="noReaderInfo" native="true">
Expand Down Expand Up @@ -790,14 +787,9 @@ color: #BFD3E8;
<container>1</container>
</customwidget>
<customwidget>
<class>InfoStack</class>
<extends>QWidget</extends>
<header>widgets/InfoStack.h</header>
</customwidget>
<customwidget>
<class>Accordion</class>
<class>MyEidInfo</class>
<extends>QWidget</extends>
<header>widgets/Accordion.h</header>
<header>widgets/MyEidInfo.h</header>
</customwidget>
<customwidget>
<class>NoCardInfo</class>
Expand Down
1 change: 1 addition & 0 deletions client/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#pragma once

#include <QCoreApplication>
#include <QEventLoop>
#include <QIODevice>
#include <QTimer>
Expand Down
Loading
Loading