Skip to content

Commit 1ce87d8

Browse files
committed
Update to new UI
Signed-off-by: Raul Metsma <[email protected]>
1 parent 3570877 commit 1ce87d8

File tree

9 files changed

+190
-70
lines changed

9 files changed

+190
-70
lines changed

client/CDoc2.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,10 @@ CDoc2::CDoc2(const QString &path)
495495

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

501504
bool CDoc2::decryptPayload(const QByteArray &fmk)
@@ -558,6 +561,7 @@ bool CDoc2::save(const QString &path)
558561
if(!cdoc20::checkConnection())
559562
return false;
560563
QScopedPointer<QNetworkAccessManager,QScopedPointerDeleteLater> nam(CheckConnection::setupNAM(req, Settings::CDOC2_POST_CERT));
564+
req.setRawHeader("x-expiry-time", QDateTime::currentDateTimeUtc().addMonths(6).toString(Qt::ISODate).toLatin1());
561565
QEventLoop e;
562566
QNetworkReply *reply = nam->post(req, QJsonDocument({
563567
{QLatin1String("recipient_id"), QLatin1String(recipient_id.toBase64())},
@@ -598,7 +602,7 @@ bool CDoc2::save(const QString &path)
598602
toVector(key.key), toVector(encrytpedKek));
599603
recipients.push_back(cdoc20::Header::CreateRecipientRecord(builder,
600604
cdoc20::Recipients::Capsule::RSAPublicKeyCapsule, rsaPublicKey.Union(),
601-
toString(key.recipient), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
605+
toString(key.toKeyLabel()), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
602606
continue;
603607
}
604608

@@ -610,7 +614,7 @@ bool CDoc2::save(const QString &path)
610614
rsaKeyServer.Union(), toString(key.keyserver_id), toString(key.transaction_id));
611615
recipients.push_back(cdoc20::Header::CreateRecipientRecord(builder,
612616
cdoc20::Recipients::Capsule::KeyServerCapsule, keyServer.Union(),
613-
toString(key.recipient), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
617+
toString(key.toKeyLabel()), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
614618
continue;
615619
}
616620

@@ -638,7 +642,7 @@ bool CDoc2::save(const QString &path)
638642
cdoc20::Recipients::EllipticCurve::secp384r1, toVector(key.key), toVector(ephPublicKeyDer));
639643
recipients.push_back(cdoc20::Header::CreateRecipientRecord(builder,
640644
cdoc20::Recipients::Capsule::ECCPublicKeyCapsule, eccPublicKey.Union(),
641-
toString(key.recipient), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
645+
toString(key.toKeyLabel()), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
642646
continue;
643647
}
644648

@@ -651,7 +655,7 @@ bool CDoc2::save(const QString &path)
651655
eccKeyServer.Union(), toString(key.keyserver_id), toString(key.transaction_id));
652656
recipients.push_back(cdoc20::Header::CreateRecipientRecord(builder,
653657
cdoc20::Recipients::Capsule::KeyServerCapsule, keyServer.Union(),
654-
toString(key.recipient), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
658+
toString(key.toKeyLabel()), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
655659
}
656660

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

client/CryptoDoc.cpp

Lines changed: 52 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,57 @@ void CKey::setCert(const QSslCertificate &c)
250251
isRSA = k.algorithm() == QSsl::Rsa;
251252
}
252253

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

254306

255307
CryptoDoc::CryptoDoc( QObject *parent )

client/CryptoDoc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <memory>
2929

3030
class QSslKey;
31+
class QUrlQuery;
3132

3233
class CKey
3334
{
@@ -43,6 +44,8 @@ class CKey
4344
bool operator==(const CKey &other) const { return other.key == key; }
4445

4546
void setCert(const QSslCertificate &c);
47+
QUrlQuery fromKeyLabel() const;
48+
QString toKeyLabel() const;
4649

4750
QByteArray key, cipher, publicKey;
4851
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: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
#include "CryptoDoc.h"
2424
#include "DateTime.h"
2525
#include "SslCertificate.h"
26-
#include "Styles.h"
2726
#include "dialogs/KeyDialog.h"
2827

28+
#include <QUrlQuery>
29+
2930
using namespace ria::qdigidoc4;
3031

3132
class AddressItem::Private: public Ui::AddressItem
@@ -46,27 +47,23 @@ AddressItem::AddressItem(CKey k, QWidget *parent, bool showIcon)
4647
if(showIcon)
4748
ui->icon->load(QStringLiteral(":/images/icon_Krypto_small.svg"));
4849
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);
5350

5451
connect(ui->add, &QToolButton::clicked, this, [this]{ emit add(this);});
5552
connect(ui->remove, &QToolButton::clicked, this, [this]{ emit remove(this);});
5653

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();
54+
ui->code = SslCertificate(ui->key.cert).personalCode();
55+
ui->label = !ui->key.cert.subjectInfo("GN").isEmpty() && !ui->key.cert.subjectInfo("SN").isEmpty() ?
56+
ui->key.cert.subjectInfo("GN").join(' ') + ' ' + ui->key.cert.subjectInfo("SN").join(' ') :
57+
ui->key.cert.subjectInfo("CN").join(' ');
6458
if(ui->label.isEmpty())
65-
ui->label = ui->key.recipient.toHtmlEscaped();
59+
{
60+
if(QUrlQuery q = ui->key.fromKeyLabel(); !q.isEmpty())
61+
ui->label = q.queryItemValue(QStringLiteral("cn"), QUrl::FullyDecoded);
62+
else
63+
ui->label = ui->key.recipient;
64+
}
6665
setIdType();
6766
showButton(AddressItem::Remove);
68-
if(ui->key.unsupported)
69-
ui->idType->setText(tr("Unsupported cryptographic algorithm or recipient type"));
7067
}
7168

7269
AddressItem::~AddressItem()
@@ -85,37 +82,24 @@ void AddressItem::changeEvent(QEvent* event)
8582
QWidget::changeEvent(event);
8683
}
8784

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-
9885
const CKey& AddressItem::getKey() const
9986
{
10087
return ui->key;
10188
}
10289

103-
void AddressItem::idChanged(const CKey &key)
90+
void AddressItem::idChanged(const SslCertificate &cert)
10491
{
92+
CKey key(cert);
10593
ui->yourself = !key.key.isNull() && ui->key == key;
10694
setName();
10795
}
10896

109-
void AddressItem::idChanged(const SslCertificate &cert)
110-
{
111-
idChanged(CKey(cert));
112-
}
113-
11497
void AddressItem::initTabOrder(QWidget *item)
11598
{
11699
setTabOrder(item, ui->name);
117100
setTabOrder(ui->name, ui->idType);
118-
setTabOrder(ui->idType, ui->remove);
101+
setTabOrder(ui->idType, ui->expire);
102+
setTabOrder(ui->expire, ui->remove);
119103
setTabOrder(ui->remove, ui->added);
120104
setTabOrder(ui->added, lastTabWidget());
121105
}
@@ -127,13 +111,14 @@ QWidget* AddressItem::lastTabWidget()
127111

128112
void AddressItem::mouseReleaseEvent(QMouseEvent * /*event*/)
129113
{
130-
(new KeyDialog(ui->key, this))->open();
114+
if(!ui->key.unsupported)
115+
(new KeyDialog(ui->key, this))->open();
131116
}
132117

133118
void AddressItem::setName()
134119
{
135120
ui->name->setText(QStringLiteral("%1 <span style=\"font-weight:normal;\">%2</span>")
136-
.arg(ui->label, ui->yourself ? ui->code + tr(" (Yourself)") : ui->code));
121+
.arg(ui->label.toHtmlEscaped(), (ui->yourself ? ui->code + tr(" (Yourself)") : ui->code).toHtmlEscaped()));
137122
if(ui->name->text().isEmpty())
138123
ui->name->hide();
139124
}
@@ -152,33 +137,53 @@ void AddressItem::stateChange(ContainerState state)
152137

153138
void AddressItem::setIdType()
154139
{
155-
ui->idType->setHidden(ui->key.cert.isNull());
156-
if(ui->key.cert.isNull())
157-
return;
158-
159-
QString str;
140+
ui->expire->clear();
160141
SslCertificate cert(ui->key.cert);
161142
SslCertificate::CertType type = cert.type();
162-
if(type & SslCertificate::DigiIDType)
163-
str = tr("digi-ID");
143+
if(ui->key.unsupported)
144+
{
145+
ui->label = tr("Unsupported cryptographic algorithm or recipient type");
146+
ui->idType->clear();
147+
}
148+
else if(type & SslCertificate::DigiIDType)
149+
ui->idType->setText(tr("digi-ID"));
164150
else if(type & SslCertificate::EstEidType)
165-
str = tr("ID-card");
151+
ui->idType->setText(tr("ID-card"));
166152
else if(type & SslCertificate::MobileIDType)
167-
str = tr("mobile-ID");
153+
ui->idType->setText(tr("mobile-ID"));
168154
else if(type & SslCertificate::TempelType)
169155
{
170156
if(cert.keyUsage().contains(SslCertificate::NonRepudiation))
171-
str = tr("e-Seal");
157+
ui->idType->setText(tr("e-Seal"));
172158
else if(cert.enhancedKeyUsage().contains(SslCertificate::ClientAuth))
173-
str = tr("Authentication certificate");
159+
ui->idType->setText(tr("Authentication certificate"));
174160
else
175-
str = tr("Certificate for Encryption");
161+
ui->idType->setText(tr("Certificate for Encryption"));
162+
}
163+
else
164+
{
165+
QUrlQuery q = ui->key.fromKeyLabel();
166+
void(QT_TR_NOOP("ID-CARD"));
167+
ui->idType->setText(tr(q.queryItemValue(QStringLiteral("type"), QUrl::FullyDecoded).toUtf8().data()));
168+
if(QString server_exp = q.queryItemValue(QStringLiteral("server_exp"), QUrl::FullyDecoded); !server_exp.isEmpty())
169+
{
170+
auto date = QDateTime::fromSecsSinceEpoch(server_exp.toLongLong());
171+
bool canDecrypt = QDateTime::currentDateTimeUtc() < date;
172+
ui->expire->setProperty("label", canDecrypt ? QStringLiteral("good") : QStringLiteral("error"));
173+
ui->expire->setText(canDecrypt ? QStringLiteral("%1 %2").arg(
174+
tr("Decryption is possible until:"), DateTime(date.toLocalTime()).formatDate(QStringLiteral("dd. MMMM yyyy"))) :
175+
tr("Decryption has expired"));
176+
}
177+
}
178+
179+
if(!cert.isNull())
180+
{
181+
ui->expire->setProperty("label", QStringLiteral("default"));
182+
ui->expire->setText(QStringLiteral("%1 %2").arg(
183+
cert.isValid() ? tr("Expires on") : tr("Expired on"),
184+
DateTime(cert.expiryDate().toLocalTime()).formatDate(QStringLiteral("dd. MMMM yyyy"))));
176185
}
177186

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"))));
187+
ui->idType->setHidden(ui->idType->text().isEmpty());
188+
ui->expire->setHidden(ui->expire->text().isEmpty());
184189
}

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)