Skip to content

Commit c628885

Browse files
committed
Add always required keys and parse empty field
Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent 1f6efc4 commit c628885

12 files changed

Lines changed: 42 additions & 81 deletions

File tree

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ jobs:
3030
- name: Install dependencies
3131
run: |
3232
brew install flatbuffers
33-
brew upgrade cmake || true
3433
curl -O -L -s https://installer.id.ee/media/github/opensc_0.26.1.pkg
3534
sudo installer -verboseR -pkg libdigidocpp-pkg/build/macos/libdigidocpp*.pkg -target /
3635
sudo installer -verboseR -pkg opensc_*.pkg -target /

client/CDocSupport.cpp

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -449,58 +449,3 @@ StreamListSource::next(std::string& name, int64_t& size)
449449
size = _files[_current].size;
450450
return libcdoc::OK;
451451
}
452-
453-
static void
454-
recode_label(libcdoc::Recipient& rcpt, std::string& label, uint64_t& expiry)
455-
{
456-
if(!label.starts_with("data:")) return;
457-
auto values = libcdoc::Lock::parseLabel(label);
458-
if (!values.contains("v") || !values.contains("type")) return;
459-
std::string v = values.at("v");
460-
values.erase("v");
461-
std::string type = values.at("type");
462-
values.erase("type");
463-
std::string expiry_str = values.at("server_exp");
464-
values.erase("server_exp");
465-
if (!expiry_str.empty()) expiry = std::stoll(expiry_str);
466-
for (const auto& [key, value] : values) {
467-
if (!value.empty())
468-
rcpt.setLabelValue(key, value);
469-
}
470-
}
471-
472-
libcdoc::Recipient
473-
makeFromLock(const libcdoc::Lock& lock, const std::string& server_id)
474-
{
475-
uint64_t expiry_ts = 0;
476-
std::string label = lock.label;
477-
switch (lock.type) {
478-
case libcdoc::Lock::CDOC1:
479-
if (!server_id.empty()) {
480-
libcdoc::Recipient rcpt = libcdoc::Recipient::makeServer(label, lock.getBytes(libcdoc::Lock::CERT), server_id);
481-
recode_label(rcpt, label, expiry_ts);
482-
return rcpt;
483-
} else {
484-
libcdoc::Recipient rcpt = libcdoc::Recipient::makeCertificate(label, lock.getBytes(libcdoc::Lock::CERT));
485-
recode_label(rcpt, label, expiry_ts);
486-
return rcpt;
487-
}
488-
case libcdoc::Lock::PUBLIC_KEY:
489-
case libcdoc::Lock::SERVER: {
490-
libcdoc::Recipient::PKType rcpt_type = (lock.pk_type == libcdoc::Lock::RSA) ? libcdoc::Recipient::RSA : libcdoc::Recipient::ECC;
491-
if (!server_id.empty()) {
492-
libcdoc::Recipient rcpt = libcdoc::Recipient::makeServer(label, lock.getBytes(libcdoc::Lock::RCPT_KEY), rcpt_type, server_id);
493-
recode_label(rcpt, label, expiry_ts);
494-
rcpt.expiry_ts = expiry_ts;
495-
return rcpt;
496-
} else {
497-
libcdoc::Recipient rcpt = libcdoc::Recipient::makePublicKey(label, lock.getBytes(libcdoc::Lock::RCPT_KEY), rcpt_type);
498-
recode_label(rcpt, label, expiry_ts);
499-
rcpt.expiry_ts = expiry_ts;
500-
return rcpt;
501-
}
502-
}
503-
default:
504-
return {};
505-
}
506-
}

client/CDocSupport.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,4 @@ struct StreamListSource final : public libcdoc::MultiDataSource {
178178

179179
const std::vector<IOEntry> &_files;
180180
int64_t _current = -1;
181-
};
182-
183-
libcdoc::Recipient makeFromLock(const libcdoc::Lock& lock, const std::string& server_id);
181+
};

client/CryptoDoc.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Q_LOGGING_CATEGORY(CRYPTO, "CRYPTO")
5353

5454
CDKey::CDKey(QSslCertificate _rcpt_cert) : lock(libcdoc::Lock::PUBLIC_KEY), rcpt_cert(_rcpt_cert) {
5555
SslCertificate ssl(rcpt_cert);
56-
lock.pk_type = (rcpt_cert.publicKey().algorithm() == QSsl::Ec) ? libcdoc::Lock::ECC : libcdoc::Lock::RSA;
56+
lock.pk_type = (rcpt_cert.publicKey().algorithm() == QSsl::Ec) ? libcdoc::PKType::ECC : libcdoc::PKType::RSA;
5757
QByteArray der = ssl.publicKeyDer();
5858
lock.setBytes(libcdoc::Lock::RCPT_KEY, std::vector<uint8_t>(der.cbegin(), der.cend()));
5959
der = rcpt_cert.toDer();
@@ -462,9 +462,20 @@ bool CryptoDoc::encrypt(const QString &filename, const QString& label, const QBy
462462
libcdoc::Recipient::makeCertificate({}, {ba.cbegin(), ba.cend()}) :
463463
libcdoc::Recipient::makeServer({}, {ba.cbegin(), ba.cend()}, keyserver_id));
464464
} else {
465-
libcdoc::Recipient rcpt = makeFromLock(key.lock, keyserver_id);
466-
if (!rcpt.isEmpty()) {
467-
enc_keys.push_back(rcpt);
465+
switch (key.lock.type) {
466+
case libcdoc::Lock::CDOC1:
467+
enc_keys.push_back(libcdoc::Recipient::makePublicKey(key.lock));
468+
break;
469+
case libcdoc::Lock::PUBLIC_KEY:
470+
case libcdoc::Lock::SERVER:
471+
if (keyserver_id.empty()) {
472+
enc_keys.push_back(libcdoc::Recipient::makePublicKey(key.lock));
473+
} else {
474+
enc_keys.push_back(libcdoc::Recipient::makeServer(key.lock, keyserver_id));
475+
}
476+
break;
477+
default:
478+
break;
468479
}
469480
}
470481
}

client/MainWindow.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "effects/Overlay.h"
3434
#include "dialogs/FileDialog.h"
3535
#include "dialogs/MobileProgress.h"
36-
#include "dialogs/PasswordDialog.h"
3736
#include "dialogs/RoleAddressDialog.h"
3837
#include "dialogs/SettingsDialog.h"
3938
#include "dialogs/SmartIDProgress.h"

client/translations/en.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,10 +1342,6 @@ E-Seal</translation>
13421342
<source>Encrypt</source>
13431343
<translation>Encrypt</translation>
13441344
</message>
1345-
<message>
1346-
<source>Encrypt long-term</source>
1347-
<translation>Encrypt long-term</translation>
1348-
</message>
13491345
<message>
13501346
<source>Decrypt</source>
13511347
<translation>Decrypt</translation>
@@ -1355,6 +1351,12 @@ E-Seal</translation>
13551351
ID-Card</source>
13561352
<translation>Decrypt with
13571353
ID-Card</translation>
1354+
</message>
1355+
<message>
1356+
<source>Encrypt
1357+
long-term</source>
1358+
<translation>Encrypt
1359+
long-term</translation>
13581360
</message>
13591361
<message>
13601362
<source>Sign with

client/translations/et.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,10 +1342,6 @@ E-templiga</translation>
13421342
<source>Encrypt</source>
13431343
<translation>Krüpteeri</translation>
13441344
</message>
1345-
<message>
1346-
<source>Encrypt long-term</source>
1347-
<translation>Krüpteeri säilitamiseks</translation>
1348-
</message>
13491345
<message>
13501346
<source>Decrypt</source>
13511347
<translation>Dekrüpteeri</translation>
@@ -1355,6 +1351,12 @@ E-templiga</translation>
13551351
ID-Card</source>
13561352
<translation>Dekrüpteeri
13571353
ID-kaardiga</translation>
1354+
</message>
1355+
<message>
1356+
<source>Encrypt
1357+
long-term</source>
1358+
<translation>Krüpteeri
1359+
säilitamiseks</translation>
13581360
</message>
13591361
<message>
13601362
<source>Sign with

client/translations/ru.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,10 +1342,6 @@ E-Seal</source>
13421342
<source>Encrypt</source>
13431343
<translation>Зашифровать</translation>
13441344
</message>
1345-
<message>
1346-
<source>Encrypt long-term</source>
1347-
<translation>Зашифровать долгосрочно</translation>
1348-
</message>
13491345
<message>
13501346
<source>Decrypt</source>
13511347
<translation>Расшифровать</translation>
@@ -1355,6 +1351,12 @@ E-Seal</source>
13551351
ID-Card</source>
13561352
<translation>Расшифровать
13571353
с ID-картой</translation>
1354+
</message>
1355+
<message>
1356+
<source>Encrypt
1357+
long-term</source>
1358+
<translation>Зашифровать
1359+
долгосрочно</translation>
13581360
</message>
13591361
<message>
13601362
<source>Sign with

client/widgets/AddressItem.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ AddressItem::AddressItem(const CDKey &key, Type type, QWidget *parent)
6969
auto map = libcdoc::Lock::parseLabel(ui->key.lock.label);
7070
if (map.contains("cn")) {
7171
ui->label = QString::fromStdString(map["cn"]);
72+
} else if (map.contains("label")) {
73+
ui->label = QString::fromStdString(map["label"]);
7274
} else {
7375
ui->label = QString::fromStdString(ui->key.lock.label);
7476
}

0 commit comments

Comments
 (0)