Skip to content

Commit 959e719

Browse files
committed
Adjust PasswordDialog UI
Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent b7ff162 commit 959e719

22 files changed

Lines changed: 615 additions & 524 deletions

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ jobs:
187187
dotnet tool install -g wix --version 6.0.2
188188
wix extension -g add WixToolset.UI.wixext/6.0.2
189189
- name: Build
190-
env:
191-
VCPKG_MANIFEST_DIR: ${{ github.workspace }}/client/libcdoc
192190
run: |
193-
cmake "-GNinja" -B build -S . -DCMAKE_BUILD_TYPE=RelWithDebInfo "-DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake" -DVCPKG_MANIFEST_DIR=${{ github.workspace }}/client/libcdoc
191+
cmake "-GNinja" -B build -S . -DCMAKE_BUILD_TYPE=RelWithDebInfo `
192+
-DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake `
193+
-DVCPKG_MANIFEST_DIR=${{ github.workspace }}/client/libcdoc
194194
cmake --build build --target msi
195195
cmake --build build --target msishellext
196196
cmake --build build --target appx

client/CDocSupport.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#define __CDOCSUPPORT_CPP__
2-
31
/*
4-
* QDigiDocCrypto
2+
* QDigiDoc4
53
*
64
* This library is free software; you can redistribute it and/or
75
* modify it under the terms of the GNU Lesser General Public

client/CDocSupport.h

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
#ifndef __CDOCSUPPORT_H__
2-
#define __CDOCSUPPORT_H__
3-
41
/*
5-
* QDigiDocCrypto
2+
* QDigiDoc4
63
*
74
* This library is free software; you can redistribute it and/or
85
* modify it under the terms of the GNU Lesser General Public
@@ -20,6 +17,8 @@
2017
*
2118
*/
2219

20+
#pragma once
21+
2322
#include <QtCore/QObject>
2423
#include <QtCore/QIODevice>
2524

@@ -52,27 +51,27 @@ struct DDConfiguration : public libcdoc::Configuration {
5251
// Bridges to qApp->signer()
5352
//
5453

55-
struct DDCryptoBackend : public libcdoc::CryptoBackend {
54+
struct DDCryptoBackend final : public libcdoc::CryptoBackend {
5655
static constexpr int BACKEND_ERROR = -303;
5756
static constexpr int PIN_CANCELED = -304;
5857
static constexpr int PIN_INCORRECT = -305;
5958
static constexpr int PIN_LOCKED = -306;
6059
libcdoc::result_t decryptRSA(std::vector<uint8_t> &result,
6160
const std::vector<uint8_t> &data, bool oaep,
62-
unsigned int idx) override final;
61+
unsigned int idx) final;
6362
libcdoc::result_t deriveConcatKDF(std::vector<uint8_t> &dst,
6463
const std::vector<uint8_t> &publicKey,
6564
const std::string &digest,
6665
const std::vector<uint8_t> &algorithmID,
6766
const std::vector<uint8_t> &partyUInfo,
6867
const std::vector<uint8_t> &partyVInfo,
69-
unsigned int idx) override final;
68+
unsigned int idx) final;
7069
libcdoc::result_t deriveHMACExtract(std::vector<uint8_t> &dst,
7170
const std::vector<uint8_t> &publicKey,
7271
const std::vector<uint8_t> &salt,
73-
unsigned int idx) override final;
72+
unsigned int idx) final;
7473
libcdoc::result_t getSecret(std::vector<uint8_t> &secret,
75-
unsigned int idx) override final;
74+
unsigned int idx) final;
7675
std::string getLastErrorStr(libcdoc::result_t code) const final;
7776

7877
std::vector<uint8_t> secret;
@@ -86,7 +85,7 @@ struct DDCryptoBackend : public libcdoc::CryptoBackend {
8685
// Bridges to QNetworkAccessManager
8786
//
8887

89-
struct DDNetworkBackend : public libcdoc::NetworkBackend, private QObject {
88+
struct DDNetworkBackend final : public libcdoc::NetworkBackend, private QObject {
9089
static constexpr int BACKEND_ERROR = -303;
9190

9291
std::string getLastErrorStr(libcdoc::result_t code) const final;
@@ -95,17 +94,17 @@ struct DDNetworkBackend : public libcdoc::NetworkBackend, private QObject {
9594
const std::vector<uint8_t> &rcpt_key,
9695
const std::vector<uint8_t> &key_material,
9796
const std::string &type,
98-
uint64_t expiry_ts) override final;
97+
uint64_t expiry_ts) final;
9998
libcdoc::result_t
10099
fetchKey(std::vector<uint8_t> &result, const std::string &keyserver_id,
101-
const std::string &transaction_id) override final;
100+
const std::string &transaction_id) final;
102101

103102
libcdoc::result_t
104-
getClientTLSCertificate(std::vector<uint8_t> &dst) override final {
103+
getClientTLSCertificate(std::vector<uint8_t> &dst) final {
105104
return libcdoc::NOT_IMPLEMENTED;
106105
}
107106
libcdoc::result_t getPeerTLSCertificates(
108-
std::vector<std::vector<uint8_t>> &dst) override final {
107+
std::vector<std::vector<uint8_t>> &dst) final {
109108
return libcdoc::NOT_IMPLEMENTED;
110109
}
111110

@@ -120,15 +119,15 @@ struct DDNetworkBackend : public libcdoc::NetworkBackend, private QObject {
120119
// Bridges to Qt logging system
121120
//
122121

123-
class DDCDocLogger : private libcdoc::ILogger {
122+
class DDCDocLogger final : private libcdoc::ILogger {
124123
public:
125124
static void setUpLogger();
126125

127126
private:
128127
DDCDocLogger() = default;
129128
~DDCDocLogger() = default;
130129
void LogMessage(libcdoc::ILogger::LogLevel level, std::string_view file, int line,
131-
std::string_view message) override final;
130+
std::string_view message) final;
132131
};
133132

134133
class CDocSupport {
@@ -147,7 +146,7 @@ struct IOEntry
147146
std::unique_ptr<QIODevice> data;
148147
};
149148

150-
struct TempListConsumer : public libcdoc::MultiDataConsumer {
149+
struct TempListConsumer final : public libcdoc::MultiDataConsumer {
151150
static constexpr int64_t MAX_VEC_SIZE = 500L * 1024L * 1024L;
152151

153152
explicit TempListConsumer(size_t max_memory_size = 500L * 1024L * 1024L)
@@ -158,23 +157,21 @@ struct TempListConsumer : public libcdoc::MultiDataConsumer {
158157
libcdoc::result_t close() noexcept final;
159158
bool isError() noexcept final;
160159
libcdoc::result_t open(const std::string &name,
161-
int64_t size) override final;
160+
int64_t size) final;
162161

163162
size_t _max_memory_size;
164163
std::vector<IOEntry> files;
165164
};
166165

167-
struct StreamListSource : public libcdoc::MultiDataSource {
166+
struct StreamListSource final : public libcdoc::MultiDataSource {
168167
StreamListSource(const std::vector<IOEntry> &files);
169168

170169
libcdoc::result_t read(uint8_t *dst, size_t size) noexcept final;
171170
bool isError() noexcept final;
172171
bool isEof() noexcept final;
173-
libcdoc::result_t getNumComponents() override final;
174-
libcdoc::result_t next(std::string &name, int64_t &size) override final;
172+
libcdoc::result_t getNumComponents() final;
173+
libcdoc::result_t next(std::string &name, int64_t &size) final;
175174

176175
const std::vector<IOEntry> &_files;
177176
int64_t _current = -1;
178177
};
179-
180-
#endif // __CDOCSUPPORT_H__

client/CryptoDoc.cpp

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,6 @@ auto toHex = [](const std::vector<uint8_t>& data) -> QString {
5555
struct CryptoDoc::Private
5656
{
5757
bool isEncryptedWarning(const QString &title) const;
58-
inline libcdoc::result_t decrypt(unsigned int lock_idx) {
59-
TempListConsumer cons;
60-
libcdoc::result_t result = waitFor([&]{
61-
std::vector<uint8_t> fmk;
62-
libcdoc::result_t result = reader->getFMK(fmk, lock_idx);
63-
qCDebug(CRYPTO) << "getFMK result: " << result << " " << QString::fromStdString(reader->getLastErrorStr());
64-
if (result != libcdoc::OK) return result;
65-
result = reader->decrypt(fmk, &cons);
66-
std::fill(fmk.begin(), fmk.end(), 0);
67-
qCDebug(CRYPTO) << "Decryption result: " << result << " " << QString::fromStdString(reader->getLastErrorStr());
68-
return result;
69-
});
70-
if (result == libcdoc::OK) {
71-
files = std::move(cons.files);
72-
// Success, immediately create writer from reader
73-
keys.clear();
74-
writer_last_error.clear();
75-
reader.reset();
76-
}
77-
return result;
78-
}
7958

8059
inline libcdoc::result_t encrypt() {
8160
libcdoc::result_t res = waitFor([&]{
@@ -101,8 +80,7 @@ struct CryptoDoc::Private
10180
}
10281
}
10382
if (!crypto.secret.empty()) {
104-
auto key =
105-
libcdoc::Recipient::makeSymmetric(label.toStdString(), kdf_iter);
83+
auto key = libcdoc::Recipient::makeSymmetric(label.toStdString(), 65536);
10684
enc_keys.push_back(key);
10785
}
10886
libcdoc::CDocWriter *writer = libcdoc::CDocWriter::createWriter(
@@ -133,7 +111,6 @@ struct CryptoDoc::Private
133111
QStringList tempFiles;
134112
// Encryption data
135113
QString label;
136-
uint32_t kdf_iter;
137114

138115
// libcdoc handlers
139116
DDConfiguration conf;
@@ -356,19 +333,17 @@ ContainerState CryptoDoc::state() const
356333

357334
bool CryptoDoc::decrypt(const libcdoc::Lock *lock, const QByteArray& secret)
358335
{
359-
if( d->fileName.isEmpty() )
336+
if(!d->reader)
360337
{
361338
WarningDialog::create()
362339
->withTitle(QSigner::tr("Failed to decrypt document"))
363340
->withText(tr("Container is not open"))
364341
->open();
365342
return false;
366343
}
367-
if (!d->reader)
368-
return true;
369344

370345
int lock_idx = -1;
371-
const std::vector<libcdoc::Lock> locks = d->reader->getLocks();
346+
const std::vector<libcdoc::Lock> &locks = d->reader->getLocks();
372347
if (lock == nullptr) {
373348
QByteArray der = qApp->signer()->tokenauth().cert().toDer();
374349
lock_idx = d->reader->getLockForCert(
@@ -423,7 +398,20 @@ bool CryptoDoc::decrypt(const libcdoc::Lock *lock, const QByteArray& secret)
423398

424399
d->crypto.secret.assign(secret.cbegin(), secret.cend());
425400

426-
libcdoc::result_t result = d->decrypt(lock_idx);
401+
TempListConsumer cons;
402+
libcdoc::result_t result = waitFor([&]{
403+
std::vector<uint8_t> fmk;
404+
auto scope = qScopeGuard([&] {
405+
std::fill(fmk.begin(), fmk.end(), 0);
406+
});
407+
libcdoc::result_t result = d->reader->getFMK(fmk, lock_idx);
408+
qCDebug(CRYPTO) << "getFMK result: " << result << " " << QString::fromStdString(d->reader->getLastErrorStr());
409+
if (result != libcdoc::OK)
410+
return result;
411+
result = d->reader->decrypt(fmk, &cons);
412+
qCDebug(CRYPTO) << "Decryption result: " << result << " " << QString::fromStdString(d->reader->getLastErrorStr());
413+
return result;
414+
});
427415
if (result != libcdoc::OK) {
428416
const std::string &msg = d->reader->getLastErrorStr();
429417
WarningDialog::create()
@@ -434,12 +422,17 @@ bool CryptoDoc::decrypt(const libcdoc::Lock *lock, const QByteArray& secret)
434422
return false;
435423
}
436424

425+
d->files = std::move(cons.files);
426+
// Success, immediately create writer from reader
427+
d->keys.clear();
428+
d->writer_last_error.clear();
429+
d->reader.reset();
437430
return !d->isEncrypted();
438431
}
439432

440433
DocumentModel *CryptoDoc::documentModel() const { return d->documents; }
441434

442-
bool CryptoDoc::encrypt( const QString &filename, const QString& label, const QByteArray& secret, uint32_t kdf_iter)
435+
bool CryptoDoc::encrypt( const QString &filename, const QString& label, const QByteArray& secret)
443436
{
444437
if( !filename.isEmpty() )
445438
d->fileName = filename;
@@ -457,7 +450,6 @@ bool CryptoDoc::encrypt( const QString &filename, const QString& label, const QB
457450
// Encrypt with symmetric key
458451
d->label = label;
459452
d->crypto.secret.assign(secret.cbegin(), secret.cend());
460-
d->kdf_iter = kdf_iter;
461453
}
462454
// Encrypt for address list
463455
else if(d->keys.empty())

client/CryptoDoc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class CryptoDoc final: public QObject
5959
bool canDecrypt(const QSslCertificate &cert);
6060
void clear(const QString &file = {});
6161
bool decrypt(const libcdoc::Lock *lock, const QByteArray& secret);
62-
bool encrypt(const QString &filename = {}, const QString& label = {}, const QByteArray& secret = {}, uint32_t kdf_iter = 0);
62+
bool encrypt(const QString &filename = {}, const QString& label = {}, const QByteArray& secret = {});
6363
DocumentModel* documentModel() const;
6464
QString fileName() const;
6565
const std::vector<CDKey>& keys() const;

0 commit comments

Comments
 (0)