Skip to content

Commit 940a4de

Browse files
committed
Update to new UI
Signed-off-by: Raul Metsma <[email protected]>
1 parent 81659cf commit 940a4de

File tree

9 files changed

+189
-76
lines changed

9 files changed

+189
-76
lines changed

client/CDoc2.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ namespace cdoc20 {
274274
io->skip(padding(f.size));
275275
if(!readHeader() || h.isNull() || !h.verify())
276276
return {};
277+
f.name = QString::fromUtf8(h.name.data(), std::min<int>(h.name.size(), int(strlen(h.name.data()))));
277278
f.size = fromOctal(h.size);
278279
for(const QByteArray &data: paxData.split('\n'))
279280
{
@@ -495,7 +496,10 @@ CDoc2::CDoc2(const QString &path)
495496

496497
CKey CDoc2::canDecrypt(const QSslCertificate &cert) const
497498
{
498-
return keys.value(keys.indexOf(CKey(cert)));
499+
auto key = keys.value(keys.indexOf(CKey(cert)));
500+
if(key.unsupported || (!key.transaction_id.isEmpty() && cert.expiryDate() <= QDateTime::currentDateTimeUtc()))
501+
return {};
502+
return key;
499503
}
500504

501505
bool CDoc2::decryptPayload(const QByteArray &fmk)
@@ -558,6 +562,7 @@ bool CDoc2::save(const QString &path)
558562
if(!cdoc20::checkConnection())
559563
return false;
560564
QScopedPointer<QNetworkAccessManager,QScopedPointerDeleteLater> nam(CheckConnection::setupNAM(req, Settings::CDOC2_POST_CERT));
565+
req.setRawHeader("x-expiry-time", QDateTime::currentDateTimeUtc().addMonths(6).toString(Qt::ISODate).toLatin1());
561566
QEventLoop e;
562567
QNetworkReply *reply = nam->post(req, QJsonDocument({
563568
{QLatin1String("recipient_id"), QLatin1String(recipient_id.toBase64())},
@@ -598,7 +603,7 @@ bool CDoc2::save(const QString &path)
598603
toVector(key.key), toVector(encrytpedKek));
599604
recipients.push_back(cdoc20::Header::CreateRecipientRecord(builder,
600605
cdoc20::Recipients::Capsule::RSAPublicKeyCapsule, rsaPublicKey.Union(),
601-
toString(key.recipient), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
606+
toString(key.toKeyLabel()), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
602607
continue;
603608
}
604609

@@ -610,7 +615,7 @@ bool CDoc2::save(const QString &path)
610615
rsaKeyServer.Union(), toString(key.keyserver_id), toString(key.transaction_id));
611616
recipients.push_back(cdoc20::Header::CreateRecipientRecord(builder,
612617
cdoc20::Recipients::Capsule::KeyServerCapsule, keyServer.Union(),
613-
toString(key.recipient), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
618+
toString(key.toKeyLabel()), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
614619
continue;
615620
}
616621

@@ -638,7 +643,7 @@ bool CDoc2::save(const QString &path)
638643
cdoc20::Recipients::EllipticCurve::secp384r1, toVector(key.key), toVector(ephPublicKeyDer));
639644
recipients.push_back(cdoc20::Header::CreateRecipientRecord(builder,
640645
cdoc20::Recipients::Capsule::ECCPublicKeyCapsule, eccPublicKey.Union(),
641-
toString(key.recipient), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
646+
toString(key.toKeyLabel()), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
642647
continue;
643648
}
644649

@@ -651,7 +656,7 @@ bool CDoc2::save(const QString &path)
651656
eccKeyServer.Union(), toString(key.keyserver_id), toString(key.transaction_id));
652657
recipients.push_back(cdoc20::Header::CreateRecipientRecord(builder,
653658
cdoc20::Recipients::Capsule::KeyServerCapsule, keyServer.Union(),
654-
toString(key.recipient), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
659+
toString(key.toKeyLabel()), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
655660
}
656661

657662
auto offset = cdoc20::Header::CreateHeader(builder, builder.CreateVector(recipients),

client/CryptoDoc.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <QtCore/QRegularExpression>
3939
#include <QtCore/QThread>
4040
#include <QtCore/QUrl>
41+
#include <QtCore/QUrlQuery>
4142
#include <QtGui/QDesktopServices>
4243
#include <QtNetwork/QSslKey>
4344
#include <QtWidgets/QMessageBox>
@@ -250,6 +251,60 @@ void CKey::setCert(const QSslCertificate &c)
250251
isRSA = k.algorithm() == QSsl::Rsa;
251252
}
252253

254+
QHash<QString, QString> CKey::fromKeyLabel() const
255+
{
256+
QHash<QString,QString> result;
257+
if(!recipient.startsWith(QLatin1String("data:"), Qt::CaseInsensitive))
258+
return result;
259+
QString payload = recipient.mid(5);
260+
QString mimeType;
261+
QString encoding;
262+
if(auto pos = payload.indexOf(','); pos != -1)
263+
{
264+
mimeType = payload.left(pos);
265+
payload = payload.mid(pos + 1);
266+
if(auto header = mimeType.split(';'); header.size() == 2)
267+
{
268+
mimeType = header.value(0);
269+
encoding = header.value(1);
270+
}
271+
}
272+
if(!mimeType.isEmpty() && mimeType != QLatin1String("application/x-www-form-urlencoded"))
273+
return result;
274+
if(encoding == QLatin1String("base64"))
275+
payload = QByteArray::fromBase64(payload.toLatin1());
276+
;
277+
for(const auto &[key,value]: QUrlQuery(payload).queryItems(QUrl::FullyDecoded))
278+
result[key.toLower()] = value;
279+
if(!result.contains(QStringLiteral("type")) || !result.contains(QStringLiteral("v")))
280+
result.clear();
281+
return result;
282+
}
283+
284+
QString CKey::toKeyLabel() const
285+
{
286+
if(cert.isNull())
287+
return recipient;
288+
QDateTime exp = cert.expiryDate();
289+
if(Settings::CDOC2_USE_KEYSERVER)
290+
exp = std::min(exp, QDateTime::currentDateTimeUtc().addMonths(6));
291+
auto escape = [](QString data) { return data.replace(',', QLatin1String("%2C")); };
292+
QString type = QStringLiteral("ID-card");
293+
if(auto t = SslCertificate(cert).type(); t & SslCertificate::EResidentSubType)
294+
type = QStringLiteral("Digi-ID E-RESIDENT");
295+
else if(t & SslCertificate::DigiIDType)
296+
type = QStringLiteral("Digi-ID");
297+
QUrlQuery q;
298+
q.setQueryItems({
299+
{QStringLiteral("v"), QString::number(1)},
300+
{QStringLiteral("type"), type},
301+
{QStringLiteral("serial_number"), escape(cert.subjectInfo("serialNumber").join(','))},
302+
{QStringLiteral("cn"), escape(cert.subjectInfo("CN").join(','))},
303+
{QStringLiteral("server_exp"), QString::number(exp.toSecsSinceEpoch())},
304+
});
305+
return "data:" + q.query(QUrl::FullyEncoded);
306+
}
307+
253308

254309

255310
CryptoDoc::CryptoDoc( QObject *parent )

client/CryptoDoc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class CKey
4343
bool operator==(const CKey &other) const { return other.key == key; }
4444

4545
void setCert(const QSslCertificate &c);
46+
QHash<QString, QString> fromKeyLabel() const;
47+
QString toKeyLabel() const;
4648

4749
QByteArray key, cipher, publicKey;
4850
QSslCertificate cert;

client/translations/en.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@
151151
<source>Unsupported cryptographic algorithm or recipient type</source>
152152
<translation>Unsupported cryptographic algorithm or recipient type</translation>
153153
</message>
154+
<message>
155+
<source>Decryption is possible until:</source>
156+
<translation>Decryption is possible until:</translation>
157+
</message>
158+
<message>
159+
<source>Decryption has expired</source>
160+
<translation>Decryption has expired</translation>
161+
</message>
162+
<message>
163+
<source>ID-CARD</source>
164+
<translation>ID-CARD</translation>
165+
</message>
154166
</context>
155167
<context>
156168
<name>Application</name>

client/translations/et.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@
151151
<source>Unsupported cryptographic algorithm or recipient type</source>
152152
<translation>Mittetoetatud krüptograafiline algoritm või adressaadi tüüp</translation>
153153
</message>
154+
<message>
155+
<source>Decryption is possible until:</source>
156+
<translation>Dekrüpteerimine on võimalik kuni:</translation>
157+
</message>
158+
<message>
159+
<source>Decryption has expired</source>
160+
<translation>Dekrüpteerimine on aegunud</translation>
161+
</message>
162+
<message>
163+
<source>ID-CARD</source>
164+
<translation>ID-KAART</translation>
165+
</message>
154166
</context>
155167
<context>
156168
<name>Application</name>

client/translations/ru.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@
151151
<source>Unsupported cryptographic algorithm or recipient type</source>
152152
<translation>Неподдерживаемый криптографический алгоритм или тип получателя</translation>
153153
</message>
154+
<message>
155+
<source>Decryption is possible until:</source>
156+
<translation>Расшифровка возможна до:</translation>
157+
</message>
158+
<message>
159+
<source>Decryption has expired</source>
160+
<translation>Срок расшифровки истек</translation>
161+
</message>
162+
<message>
163+
<source>ID-CARD</source>
164+
<translation>ID-КАРТА</translation>
165+
</message>
154166
</context>
155167
<context>
156168
<name>Application</name>

client/widgets/AddressItem.cpp

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
#include "ui_AddressItem.h"
2222

2323
#include "CryptoDoc.h"
24-
#include "DateTime.h"
2524
#include "SslCertificate.h"
26-
#include "Styles.h"
2725
#include "dialogs/KeyDialog.h"
2826

2927
using namespace ria::qdigidoc4;
@@ -46,27 +44,23 @@ AddressItem::AddressItem(CKey k, QWidget *parent, bool showIcon)
4644
if(showIcon)
4745
ui->icon->load(QStringLiteral(":/images/icon_Krypto_small.svg"));
4846
ui->icon->setVisible(showIcon);
49-
ui->name->setFont(Styles::font(Styles::Regular, 14, QFont::DemiBold));
50-
ui->name->installEventFilter(this);
51-
ui->idType->setFont(Styles::font(Styles::Regular, 11));
52-
ui->idType->installEventFilter(this);
47+
ui->name->setAttribute(Qt::WA_TransparentForMouseEvents, true);
48+
ui->expire->setAttribute(Qt::WA_TransparentForMouseEvents, true);
49+
ui->idType->setAttribute(Qt::WA_TransparentForMouseEvents, true);
50+
if(!ui->key.unsupported)
51+
setCursor(Qt::PointingHandCursor);
5352

5453
connect(ui->add, &QToolButton::clicked, this, [this]{ emit add(this);});
5554
connect(ui->remove, &QToolButton::clicked, this, [this]{ emit remove(this);});
5655

57-
ui->add->setFont(Styles::font(Styles::Condensed, 12));
58-
ui->added->setFont(ui->add->font());
59-
60-
ui->code = SslCertificate(ui->key.cert).personalCode().toHtmlEscaped();
61-
ui->label = (!ui->key.cert.subjectInfo("GN").isEmpty() && !ui->key.cert.subjectInfo("SN").isEmpty() ?
62-
ui->key.cert.subjectInfo("GN").join(' ') + " " + ui->key.cert.subjectInfo("SN").join(' ') :
63-
ui->key.cert.subjectInfo("CN").join(' ')).toHtmlEscaped();
56+
ui->code = SslCertificate(ui->key.cert).personalCode();
57+
ui->label = !ui->key.cert.subjectInfo("GN").isEmpty() && !ui->key.cert.subjectInfo("SN").isEmpty() ?
58+
ui->key.cert.subjectInfo("GN").join(' ') + ' ' + ui->key.cert.subjectInfo("SN").join(' ') :
59+
ui->key.cert.subjectInfo("CN").join(' ');
6460
if(ui->label.isEmpty())
65-
ui->label = ui->key.recipient.toHtmlEscaped();
61+
ui->label = ui->key.fromKeyLabel().value(QStringLiteral("cn"), ui->key.recipient);
6662
setIdType();
6763
showButton(AddressItem::Remove);
68-
if(ui->key.unsupported)
69-
ui->idType->setText(tr("Unsupported cryptographic algorithm or recipient type"));
7064
}
7165

7266
AddressItem::~AddressItem()
@@ -85,37 +79,24 @@ void AddressItem::changeEvent(QEvent* event)
8579
QWidget::changeEvent(event);
8680
}
8781

88-
bool AddressItem::eventFilter(QObject *o, QEvent *e)
89-
{
90-
if((o == ui->name || o == ui->idType) && e->type() == QEvent::MouseButtonRelease)
91-
{
92-
(new KeyDialog(ui->key, this))->open();
93-
return true;
94-
}
95-
return Item::eventFilter(o, e);
96-
}
97-
9882
const CKey& AddressItem::getKey() const
9983
{
10084
return ui->key;
10185
}
10286

103-
void AddressItem::idChanged(const CKey &key)
87+
void AddressItem::idChanged(const SslCertificate &cert)
10488
{
89+
CKey key(cert);
10590
ui->yourself = !key.key.isNull() && ui->key == key;
10691
setName();
10792
}
10893

109-
void AddressItem::idChanged(const SslCertificate &cert)
110-
{
111-
idChanged(CKey(cert));
112-
}
113-
11494
void AddressItem::initTabOrder(QWidget *item)
11595
{
11696
setTabOrder(item, ui->name);
11797
setTabOrder(ui->name, ui->idType);
118-
setTabOrder(ui->idType, ui->remove);
98+
setTabOrder(ui->idType, ui->expire);
99+
setTabOrder(ui->expire, ui->remove);
119100
setTabOrder(ui->remove, ui->added);
120101
setTabOrder(ui->added, lastTabWidget());
121102
}
@@ -127,13 +108,14 @@ QWidget* AddressItem::lastTabWidget()
127108

128109
void AddressItem::mouseReleaseEvent(QMouseEvent * /*event*/)
129110
{
130-
(new KeyDialog(ui->key, this))->open();
111+
if(!ui->key.unsupported)
112+
(new KeyDialog(ui->key, this))->open();
131113
}
132114

133115
void AddressItem::setName()
134116
{
135117
ui->name->setText(QStringLiteral("%1 <span style=\"font-weight:normal;\">%2</span>")
136-
.arg(ui->label, ui->yourself ? ui->code + tr(" (Yourself)") : ui->code));
118+
.arg(ui->label.toHtmlEscaped(), (ui->yourself ? ui->code + tr(" (Yourself)") : ui->code).toHtmlEscaped()));
137119
if(ui->name->text().isEmpty())
138120
ui->name->hide();
139121
}
@@ -152,33 +134,53 @@ void AddressItem::stateChange(ContainerState state)
152134

153135
void AddressItem::setIdType()
154136
{
155-
ui->idType->setHidden(ui->key.cert.isNull());
156-
if(ui->key.cert.isNull())
157-
return;
158-
159-
QString str;
137+
ui->expire->clear();
160138
SslCertificate cert(ui->key.cert);
161139
SslCertificate::CertType type = cert.type();
162-
if(type & SslCertificate::DigiIDType)
163-
str = tr("digi-ID");
140+
if(ui->key.unsupported)
141+
{
142+
ui->label = tr("Unsupported cryptographic algorithm or recipient type");
143+
ui->idType->clear();
144+
}
145+
else if(type & SslCertificate::DigiIDType)
146+
ui->idType->setText(tr("digi-ID"));
164147
else if(type & SslCertificate::EstEidType)
165-
str = tr("ID-card");
148+
ui->idType->setText(tr("ID-card"));
166149
else if(type & SslCertificate::MobileIDType)
167-
str = tr("mobile-ID");
150+
ui->idType->setText(tr("mobile-ID"));
168151
else if(type & SslCertificate::TempelType)
169152
{
170153
if(cert.keyUsage().contains(SslCertificate::NonRepudiation))
171-
str = tr("e-Seal");
154+
ui->idType->setText(tr("e-Seal"));
172155
else if(cert.enhancedKeyUsage().contains(SslCertificate::ClientAuth))
173-
str = tr("Authentication certificate");
156+
ui->idType->setText(tr("Authentication certificate"));
174157
else
175-
str = tr("Certificate for Encryption");
158+
ui->idType->setText(tr("Certificate for Encryption"));
159+
}
160+
else
161+
{
162+
auto items = ui->key.fromKeyLabel();
163+
void(QT_TR_NOOP("ID-CARD"));
164+
ui->idType->setText(tr(items[QStringLiteral("type")].toUtf8().data()));
165+
if(QString server_exp = items[QStringLiteral("server_exp")]; !server_exp.isEmpty())
166+
{
167+
auto date = QDateTime::fromSecsSinceEpoch(server_exp.toLongLong(), Qt::UTC);
168+
bool canDecrypt = QDateTime::currentDateTimeUtc() < date;
169+
ui->expire->setProperty("label", canDecrypt ? QStringLiteral("good") : QStringLiteral("error"));
170+
ui->expire->setText(canDecrypt ? QStringLiteral("%1 %2").arg(
171+
tr("Decryption is possible until:"), date.toLocalTime().toString(QStringLiteral("dd.MM.yyyy"))) :
172+
tr("Decryption has expired"));
173+
}
174+
}
175+
176+
if(!cert.isNull())
177+
{
178+
ui->expire->setProperty("label", QStringLiteral("default"));
179+
ui->expire->setText(QStringLiteral("%1 %2").arg(
180+
cert.isValid() ? tr("Expires on") : tr("Expired on"),
181+
cert.expiryDate().toLocalTime().toString(QStringLiteral("dd.MM.yyyy"))));
176182
}
177183

178-
if(!str.isEmpty())
179-
str += QStringLiteral(" - ");
180-
DateTime date(cert.expiryDate().toLocalTime());
181-
ui->idType->setText(QStringLiteral("%1%2 %3").arg(str,
182-
cert.isValid() ? tr("Expires on") : tr("Expired on"),
183-
date.formatDate(QStringLiteral("dd. MMMM yyyy"))));
184+
ui->idType->setHidden(ui->idType->text().isEmpty());
185+
ui->expire->setHidden(ui->expire->text().isEmpty());
184186
}

client/widgets/AddressItem.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class AddressItem final : public Item
3939
~AddressItem() final;
4040

4141
const CKey& getKey() const;
42-
void idChanged(const CKey &cert);
4342
void idChanged(const SslCertificate &cert) final;
4443
void initTabOrder(QWidget *item) final;
4544
QWidget* lastTabWidget() final;
@@ -48,7 +47,6 @@ class AddressItem final : public Item
4847

4948
private:
5049
void changeEvent(QEvent *event) final;
51-
bool eventFilter(QObject *o, QEvent *e) final;
5250
void mouseReleaseEvent(QMouseEvent *event) final;
5351
void setName();
5452
void setIdType();

0 commit comments

Comments
 (0)