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
10 changes: 5 additions & 5 deletions client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "Configuration.h"
#include "CDocSupport.h"
#include "MainWindow.h"
#include "QSigner.h"
#include "QCryptoBackend.h"
#include "QSmartCard.h"
#include "DigiDoc.h"
#include "Settings.h"
Expand Down Expand Up @@ -296,7 +296,7 @@ class Application::Private
Configuration *conf {};
QAction *closeAction {}, *newClientAction {}, *helpAction {};
std::unique_ptr<MacMenuBar> bar;
QSigner *signer {};
QCryptoManager *cryptoManager {};

QTranslator appTranslator, qtTranslator;
QString lang;
Expand All @@ -307,7 +307,7 @@ class Application::Private
#endif // Q_OS_WIN

~Private() {
delete signer;
delete cryptoManager;
}
};

Expand Down Expand Up @@ -462,7 +462,7 @@ Application::Application( int &argc, char **argv )
try
{
digidoc::Conf::init( new DigidocConf );
d->signer = new QSigner(this);
d->cryptoManager = new QCryptoManager();
updateTSLCache(QDateTime::currentDateTimeUtc().addDays(-7));

digidoc::initialize(applicationName().toUtf8().constData(), QStringLiteral("%1/%2 (%3)")
Expand Down Expand Up @@ -968,7 +968,7 @@ void Application::showWarning(const QString &title, const digidoc::Exception &e)
WarningDialog::create()->withTitle(title)->withDetails(causes.join('\n'))->open();
}

QSigner* Application::signer() const { return d->signer; }
QCryptoManager* Application::cryptoManager() const { return d->cryptoManager; }

void Application::updateTSLCache(const QDateTime &tslTime)
{
Expand Down
4 changes: 2 additions & 2 deletions client/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using BaseApplication = QtSingleApplication;
namespace digidoc { class Exception; }
class Configuration;
class QAction;
class QSigner;
class QCryptoManager;
class Application final: public BaseApplication
{
Q_OBJECT
Expand All @@ -61,7 +61,7 @@ class Application final: public BaseApplication
Configuration *conf();
void loadTranslation( const QString &lang );
bool notify(QObject *object, QEvent *event ) final;
QSigner* signer() const;
QCryptoManager* cryptoManager() const;
int run();
void waitForTSL( const QString &file );

Expand Down
15 changes: 7 additions & 8 deletions client/CDocSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "Application.h"
#include "CheckConnection.h"
#include "QCryptoBackend.h"
#include "QSigner.h"
#include "Settings.h"
#include "TokenData.h"
#include "Utils.h"
Expand Down Expand Up @@ -124,7 +123,7 @@ libcdoc::result_t
DDCryptoBackend::decryptRSA(std::vector<uint8_t>& dst, const std::vector<uint8_t> &data, bool oaep, unsigned int idx)
{
if (!backend) {
auto val = QCryptoBackend::getBackend(qApp->signer()->tokenauth());
auto val = QCryptoBackend::getBackend(qApp->cryptoManager()->tokenauth());
if (!val)
return getDecryptStatus(val.error());
backend.reset(val.value());
Expand All @@ -144,7 +143,7 @@ DDCryptoBackend::deriveConcatKDF(std::vector<uint8_t>& dst, const std::vector<ui
{"http://www.w3.org/2001/04/xmlenc#sha512", QCryptographicHash::Sha512}
};
if (!backend) {
auto val = QCryptoBackend::getBackend(qApp->signer()->tokenauth());
auto val = QCryptoBackend::getBackend(qApp->cryptoManager()->tokenauth());
if (!val)
return getDecryptStatus(val.error());
backend.reset(val.value());
Expand All @@ -159,7 +158,7 @@ libcdoc::result_t
DDCryptoBackend::deriveHMACExtract(std::vector<uint8_t>& dst, const std::vector<uint8_t> &key_material, const std::vector<uint8_t> &salt, unsigned int idx)
{
if (!backend) {
auto val = QCryptoBackend::getBackend(qApp->signer()->tokenauth());
auto val = QCryptoBackend::getBackend(qApp->cryptoManager()->tokenauth());
if (!val)
return getDecryptStatus(val.error());
backend.reset(val.value());
Expand Down Expand Up @@ -189,7 +188,7 @@ DDCryptoBackend::getLastErrorStr(libcdoc::result_t code) const
case IN_PROGRESS:
return "Signing/decrypting is already in progress another window.";
case BACKEND_ERROR:
return qApp->signer()->getLastErrorStr().toStdString();
return "Backend error";
}
return libcdoc::CryptoBackend::getLastErrorStr(code);
}
Expand Down Expand Up @@ -321,8 +320,8 @@ DDNetworkBackend::fetchKey(std::vector<uint8_t> &result, const std::string &url,
return BACKEND_ERROR;
}

TokenData auth = qApp->signer()->tokenauth();
auto val = QCryptoBackend::getBackend(qApp->signer()->tokenauth());
TokenData auth = qApp->cryptoManager()->tokenauth();
auto val = QCryptoBackend::getBackend(auth);
if (!val)
return getDecryptStatus(val.error());
std::unique_ptr<QCryptoBackend> backend(val.value());
Expand All @@ -333,7 +332,7 @@ DDNetworkBackend::fetchKey(std::vector<uint8_t> &result, const std::string &url,
return BACKEND_ERROR;
}
QScopedPointer<QNetworkAccessManager,QScopedPointerDeleteLater> nam(
CheckConnection::setupNAM(req, qApp->signer()->tokenauth().cert(), authKey, Settings::CDOC2_GET_CERT));
CheckConnection::setupNAM(req, auth.cert(), authKey, Settings::CDOC2_GET_CERT));
QEventLoop e;
QNetworkReply *reply = nam->get(req);
connect(reply, &QNetworkReply::finished, &e, &QEventLoop::quit);
Expand Down
2 changes: 1 addition & 1 deletion client/CDocSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct DDConfiguration : public libcdoc::Configuration {
//
// CryptoBackend
//
// Bridges to qApp->signer()
// Bridges to qApp->cryptoManager()
//

struct DDCryptoBackend final : public libcdoc::CryptoBackend {
Expand Down
11 changes: 5 additions & 6 deletions client/CryptoDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "CDocSupport.h"
#include "TokenData.h"
#include "QCryptoBackend.h"
#include "QSigner.h"
#include "Settings.h"
#include "SslCertificate.h"
#include "Utils.h"
Expand Down Expand Up @@ -283,7 +282,7 @@ bool CryptoDoc::decrypt(const libcdoc::Lock *lock, const QByteArray& secret)
if(!d->reader)
{
WarningDialog::create()
->withTitle(QSigner::tr("Failed to decrypt document"))
->withTitle(tr("Failed to decrypt document"))
->withText(tr("Container is not open"))
->open();
return false;
Expand All @@ -292,12 +291,12 @@ bool CryptoDoc::decrypt(const libcdoc::Lock *lock, const QByteArray& secret)
int lock_idx = -1;
const std::vector<libcdoc::Lock> &locks = d->reader->getLocks();
if (lock == nullptr) {
QByteArray der = qApp->signer()->tokenauth().cert().toDer();
QByteArray der = qApp->cryptoManager()->tokenauth().cert().toDer();
lock_idx = d->reader->getLockForCert(
std::vector<uint8_t>(der.cbegin(), der.cend()));
if (lock_idx < 0) {
WarningDialog::create()
->withTitle(QSigner::tr("Failed to decrypt document"))
->withTitle(tr("Failed to decrypt document"))
->withText(tr("You do not have the key to decrypt this document"))
->open();
return false;
Expand All @@ -315,7 +314,7 @@ bool CryptoDoc::decrypt(const libcdoc::Lock *lock, const QByteArray& secret)
}
if (!lock || (lock->isSymmetric() && secret.isEmpty())) {
WarningDialog::create()
->withTitle(QSigner::tr("Failed to decrypt document"))
->withTitle(tr("Failed to decrypt document"))
->withText(tr("You do not have the key to decrypt this document"))
->open();
return false;
Expand Down Expand Up @@ -368,7 +367,7 @@ bool CryptoDoc::decrypt(const libcdoc::Lock *lock, const QByteArray& secret)
break;
}
WarningDialog::create()
->withTitle(QSigner::tr("Failed to decrypt document"))
->withTitle(tr("Failed to decrypt document"))
->withText(str)
->withDetails(QString::fromStdString(msg))
->open();
Expand Down
8 changes: 3 additions & 5 deletions client/DigiDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ bool DigiDoc::extend()
{
QWidget *parent = parentWidget();
try {
auto *signer = qApp->signer();
signer->setUserAgent(QStringLiteral("%1/%2 (%3) Devices: %4").arg(
QSigner signer(qApp->cryptoManager()->tokensign());
signer.setUserAgent(QStringLiteral("%1/%2 (%3) Devices: %4").arg(
QCoreApplication::applicationName(),
QCoreApplication::applicationVersion(),
Common::applicationOs(),
Expand All @@ -434,12 +434,10 @@ bool DigiDoc::extend()
ServiceConfirmation cb(parent);
QString current = m_fileName;
size_t extendCount = 0;
bool wrapped = false;
if(std::unique_ptr<Container> extended = waitFor([&] {
return Container::extendContainerValidity(*b, signer, extendCount);
return Container::extendContainerValidity(*b, &signer, extendCount);
}))
{
wrapped = true;
const QString asics = QCoreApplication::translate("MainWindow", "Documents (%1)").arg(QLatin1String("*.asics *.scs"));
QFileInfo f(current);
QString name = f.absolutePath() + '/' + f.completeBaseName() + QStringLiteral(".asics");
Expand Down
40 changes: 21 additions & 19 deletions client/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "CheckConnection.h"
#include "CryptoDoc.h"
#include "DigiDoc.h"
#include "QCryptoBackend.h"
#include "QPCSC.h"
#include "QSigner.h"
#include "Settings.h"
Expand Down Expand Up @@ -92,13 +93,13 @@ MainWindow::MainWindow( QWidget *parent )
#endif

// Refresh ID card info in card widget
connect(qApp->signer(), &QSigner::cacheChanged, this, &MainWindow::updateSelector);
connect(qApp->signer(), &QSigner::signDataChanged, ui->signContainerPage, &ContainerPage::tokenChanged);
connect(qApp->signer(), &QSigner::authDataChanged, ui->cryptoContainerPage, &ContainerPage::tokenChanged);
connect(qApp->cryptoManager(), &QCryptoManager::cacheChanged, this, &MainWindow::updateSelector);
connect(qApp->cryptoManager(), &QCryptoManager::signDataChanged, ui->signContainerPage, &ContainerPage::tokenChanged);
connect(qApp->cryptoManager(), &QCryptoManager::authDataChanged, ui->cryptoContainerPage, &ContainerPage::tokenChanged);

// Refresh card info on "My EID" page
connect(qApp->signer()->smartcard(), &QSmartCard::tokenChanged, this, &MainWindow::updateMyEID);
connect(qApp->signer()->smartcard(), &QSmartCard::dataChanged, this, &MainWindow::updateMyEid);
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); });
Expand All @@ -119,10 +120,10 @@ MainWindow::MainWindow( QWidget *parent )
connect(ui->accordion, &Accordion::changePinClicked, this, &MainWindow::changePinClicked);
connect(ui->cardInfo, &CardWidget::selected, ui->selector, &QToolButton::toggle);

ui->signContainerPage->tokenChanged(qApp->signer()->tokensign());
ui->cryptoContainerPage->tokenChanged(qApp->signer()->tokenauth());
updateMyEID(qApp->signer()->smartcard()->tokenData());
updateMyEid(qApp->signer()->smartcard()->data());
ui->signContainerPage->tokenChanged(qApp->cryptoManager()->tokensign());
ui->cryptoContainerPage->tokenChanged(qApp->cryptoManager()->tokenauth());
updateMyEID(qApp->cryptoManager()->smartcard()->tokenData());
updateMyEid(qApp->cryptoManager()->smartcard()->data());
}

MainWindow::~MainWindow() noexcept = default;
Expand Down Expand Up @@ -157,8 +158,8 @@ void MainWindow::changeEvent(QEvent* event)

void MainWindow::changePinClicked(QSmartCardData::PinType type, QSmartCard::PinAction action)
{
if(qApp->signer()->smartcard()->pinChange(type, action, ui->topBar))
updateMyEid(qApp->signer()->smartcard()->data());
if(qApp->cryptoManager()->smartcard()->pinChange(type, action, ui->topBar))
updateMyEid(qApp->cryptoManager()->smartcard()->data());
}

void MainWindow::closeEvent(QCloseEvent * /*event*/)
Expand Down Expand Up @@ -274,7 +275,7 @@ void MainWindow::navigateToPage( Pages page, const QStringList &files, bool crea
if(navigate)
{
cryptoDoc = std::move(cryptoContainer);
ui->cryptoContainerPage->transition(cryptoDoc.get(), qApp->signer()->tokenauth().cert());
ui->cryptoContainerPage->transition(cryptoDoc.get(), qApp->cryptoManager()->tokenauth().cert());
}
}

Expand All @@ -289,7 +290,8 @@ void MainWindow::onSignAction(int action, const QString &idCode, const QString &
case SignatureAdd:
case SignatureToken:
sign([this](const QString &city, const QString &state, const QString &zip, const QString &country, const QString &role) {
return digiDoc->sign(city, state, zip, country, role, qApp->signer());
QSigner signer(qApp->cryptoManager()->tokensign());
return digiDoc->sign(city, state, zip, country, role, &signer);
});
break;
case SignatureMobile:
Expand Down Expand Up @@ -344,7 +346,7 @@ void MainWindow::convertToCDoc()
else
cryptoContainer->documentModel()->copyModel(digiDoc->documentModel());

auto cardData = qApp->signer()->tokenauth();
auto cardData = qApp->cryptoManager()->tokenauth();
if (!cardData.cert().isNull()) {
cryptoContainer->addEncryptionKey(CKey(cardData.cert()));
}
Expand Down Expand Up @@ -733,22 +735,22 @@ void MainWindow::updateSelector()
{
case SignIntro:
case SignDetails:
selected = qApp->signer()->tokensign();
selected = qApp->cryptoManager()->tokensign();
filter = Signing;
break;
case CryptoIntro:
case CryptoDetails:
selected = qApp->signer()->tokenauth();
selected = qApp->cryptoManager()->tokenauth();
filter = Decrypting;
break;
case MyEid:
default:
selected = qApp->signer()->smartcard()->tokenData();
selected = qApp->cryptoManager()->smartcard()->tokenData();
filter = MyEID;
break;
}
QVector<TokenData> list;
for(const TokenData &token: qApp->signer()->cache())
for(const TokenData &token: qApp->cryptoManager()->cache())
{
if(token.card() == selected.card())
continue;
Expand Down Expand Up @@ -783,7 +785,7 @@ void MainWindow::updateSelector()
if(show)
{
auto *cardPopup = new CardPopup(list, this);
connect(cardPopup, &CardPopup::activated, qApp->signer(), &QSigner::selectCard);
connect(cardPopup, &CardPopup::activated, qApp->cryptoManager(), &QCryptoManager::selectCard);
connect(cardPopup, &CardPopup::activated, this, [this] { ui->selector->setChecked(false); });
cardPopup->show();
}
Expand Down
Loading
Loading