Skip to content

Commit

Permalink
Update to new UI
Browse files Browse the repository at this point in the history
Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma committed Nov 29, 2024
1 parent 9a2430c commit 9217ee7
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 28 deletions.
9 changes: 5 additions & 4 deletions client/CDoc2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ bool CDoc2::save(const QString &path)
if(!cdoc20::checkConnection())
return false;
QScopedPointer<QNetworkAccessManager,QScopedPointerDeleteLater> nam(CheckConnection::setupNAM(req, Settings::CDOC2_POST_CERT));
req.setRawHeader("x-expiry-time", QDateTime::currentDateTimeUtc().addMonths(6).toString(Qt::ISODate).toLatin1());
QEventLoop e;
QNetworkReply *reply = nam->post(req, QJsonDocument({
{QLatin1String("recipient_id"), QLatin1String(recipient_id.toBase64())},
Expand Down Expand Up @@ -598,7 +599,7 @@ bool CDoc2::save(const QString &path)
toVector(key.key), toVector(encrytpedKek));
recipients.push_back(cdoc20::Header::CreateRecipientRecord(builder,
cdoc20::Recipients::Capsule::RSAPublicKeyCapsule, rsaPublicKey.Union(),
toString(key.recipient), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
toString(key.keyLabel()), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
continue;
}

Expand All @@ -610,7 +611,7 @@ bool CDoc2::save(const QString &path)
rsaKeyServer.Union(), toString(key.keyserver_id), toString(key.transaction_id));
recipients.push_back(cdoc20::Header::CreateRecipientRecord(builder,
cdoc20::Recipients::Capsule::KeyServerCapsule, keyServer.Union(),
toString(key.recipient), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
toString(key.keyLabel()), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
continue;
}

Expand Down Expand Up @@ -638,7 +639,7 @@ bool CDoc2::save(const QString &path)
cdoc20::Recipients::EllipticCurve::secp384r1, toVector(key.key), toVector(ephPublicKeyDer));
recipients.push_back(cdoc20::Header::CreateRecipientRecord(builder,
cdoc20::Recipients::Capsule::ECCPublicKeyCapsule, eccPublicKey.Union(),
toString(key.recipient), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
toString(key.keyLabel()), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
continue;
}

Expand All @@ -651,7 +652,7 @@ bool CDoc2::save(const QString &path)
eccKeyServer.Union(), toString(key.keyserver_id), toString(key.transaction_id));
recipients.push_back(cdoc20::Header::CreateRecipientRecord(builder,
cdoc20::Recipients::Capsule::KeyServerCapsule, keyServer.Union(),
toString(key.recipient), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
toString(key.keyLabel()), toVector(xor_key), cdoc20::Header::FMKEncryptionMethod::XOR));
}

auto offset = cdoc20::Header::CreateHeader(builder, builder.CreateVector(recipients),
Expand Down
20 changes: 20 additions & 0 deletions client/CryptoDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <QtCore/QRegularExpression>
#include <QtCore/QThread>
#include <QtCore/QUrl>
#include <QtCore/QUrlQuery>
#include <QtGui/QDesktopServices>
#include <QtNetwork/QSslKey>
#include <QtWidgets/QMessageBox>
Expand Down Expand Up @@ -250,6 +251,25 @@ void CKey::setCert(const QSslCertificate &c)
isRSA = k.algorithm() == QSsl::Rsa;
}

QString CKey::keyLabel() const
{
if(cert.isNull())
return recipient;
QDateTime exp = cert.expiryDate();
if(Settings::CDOC2_USE_KEYSERVER)
exp = std::min(exp, QDateTime::currentDateTimeUtc().addMonths(6));
auto escape = [](QString data) { return data.replace(',', QLatin1String("%2C")); };
QUrlQuery q;
q.setQueryItems({
{QStringLiteral("v"), QString::number(1)},
{QStringLiteral("type"), QStringLiteral("ID-card")},
{QStringLiteral("serial_number"), escape(cert.subjectInfo("serialNumber").join(','))},
{QStringLiteral("cn"), escape(cert.subjectInfo("CN").join(','))},
{QStringLiteral("server_exp"), QString::number(exp.toSecsSinceEpoch())},
});
return "data:" + q.query(QUrl::FullyEncoded);
}



CryptoDoc::CryptoDoc( QObject *parent )
Expand Down
1 change: 1 addition & 0 deletions client/CryptoDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class CKey
bool operator==(const CKey &other) const { return other.key == key; }

void setCert(const QSslCertificate &c);
QString keyLabel() const;

QByteArray key, cipher, publicKey;
QSslCertificate cert;
Expand Down
10 changes: 9 additions & 1 deletion client/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,15 @@
</message>
<message>
<source>Unsupported algorithm or recipient type</source>
<translation type="unfinished"></translation>
<translation>Unsupported algorithm or recipient type</translation>
</message>
<message>
<source>Decrypting is expired</source>
<translation>Decrypting is expired</translation>
</message>
<message>
<source>Can decrypt until:</source>
<translation>Can decrypt until:</translation>
</message>
</context>
<context>
Expand Down
8 changes: 8 additions & 0 deletions client/translations/et.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@
<source>Unsupported algorithm or recipient type</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Decrypting is expired</source>
<translation>Dekrüpteerimine on aegunud</translation>
</message>
<message>
<source>Can decrypt until:</source>
<translation>Dekrüpteerida võimalik kuni:</translation>
</message>
</context>
<context>
<name>Application</name>
Expand Down
8 changes: 8 additions & 0 deletions client/translations/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@
<source>Unsupported algorithm or recipient type</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Decrypting is expired</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Can decrypt until:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Application</name>
Expand Down
91 changes: 70 additions & 21 deletions client/widgets/AddressItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "Styles.h"
#include "dialogs/KeyDialog.h"

#include <QUrlQuery>

using namespace ria::qdigidoc4;

class AddressItem::Private: public Ui::AddressItem
Expand Down Expand Up @@ -62,11 +64,15 @@ AddressItem::AddressItem(CKey k, QWidget *parent, bool showIcon)
ui->key.cert.subjectInfo("GN").join(' ') + " " + ui->key.cert.subjectInfo("SN").join(' ') :
ui->key.cert.subjectInfo("CN").join(' ')).toHtmlEscaped();
if(ui->label.isEmpty())
ui->label = ui->key.recipient.toHtmlEscaped();
{
QUrlQuery q = parseKeyLabelDataUrl(ui->key.recipient);
if(!q.isEmpty())
ui->label = q.queryItemValue(QStringLiteral("cn"), QUrl::FullyDecoded).toHtmlEscaped();
else
ui->label = ui->key.recipient.toHtmlEscaped();
}
setIdType();
showButton(AddressItem::Remove);
if(ui->key.unsupported)
ui->idType->setText(tr("Unsupported algorithm or recipient type"));
}

AddressItem::~AddressItem()
Expand Down Expand Up @@ -130,6 +136,33 @@ void AddressItem::mouseReleaseEvent(QMouseEvent * /*event*/)
(new KeyDialog(ui->key, this))->open();
}

QUrlQuery AddressItem::parseKeyLabelDataUrl(const QString &dataUrl)
{
if(!dataUrl.startsWith(QLatin1String("data:"), Qt::CaseInsensitive))
return {};
QString payload = dataUrl.mid(5);
QString mimeType;
QString encoding;
if(auto pos = payload.indexOf(','); pos != -1)
{
mimeType = payload.left(pos);
payload = payload.mid(pos + 1);
if(auto header = mimeType.split(';'); header.size() == 2)
{
mimeType = header.value(0);
encoding = header.value(1);
}
}
if(!mimeType.isEmpty() && mimeType != QLatin1String("application/x-www-form-urlencoded"))
return {};
if(encoding == QLatin1String("base64"))
payload = QByteArray::fromBase64(payload.toLatin1());
QUrlQuery query(payload);
if(!query.hasQueryItem(QStringLiteral("type")) || !query.hasQueryItem(QStringLiteral("v")))
query.clear();
return query;
}

void AddressItem::setName()
{
ui->name->setText(QStringLiteral("%1 <span style=\"font-weight:normal;\">%2</span>")
Expand All @@ -150,33 +183,49 @@ void AddressItem::stateChange(ContainerState state)

void AddressItem::setIdType()
{
ui->idType->setHidden(ui->key.cert.isNull());
if(ui->key.cert.isNull())
return;

QString str;
ui->expire->clear();
SslCertificate cert(ui->key.cert);
SslCertificate::CertType type = cert.type();
if(type & SslCertificate::DigiIDType)
str = tr("digi-ID");
if(ui->key.unsupported)
ui->idType->setText(tr("Unsupported algorithm or recipient type"));
else if(type & SslCertificate::DigiIDType)
ui->idType->setText(tr("digi-ID"));
else if(type & SslCertificate::EstEidType)
str = tr("ID-card");
ui->idType->setText(tr("ID-card"));
else if(type & SslCertificate::MobileIDType)
str = tr("mobile-ID");
ui->idType->setText(tr("mobile-ID"));
else if(type & SslCertificate::TempelType)
{
if(cert.keyUsage().contains(SslCertificate::NonRepudiation))
str = tr("e-Seal");
ui->idType->setText(tr("e-Seal"));
else if(cert.enhancedKeyUsage().contains(SslCertificate::ClientAuth))
str = tr("Authentication certificate");
ui->idType->setText(tr("Authentication certificate"));
else
str = tr("Certificate for Encryption");
ui->idType->setText(tr("Certificate for Encryption"));
}
else
{
QUrlQuery q = parseKeyLabelDataUrl(ui->key.recipient);
ui->idType->setText(q.queryItemValue(QStringLiteral("type"), QUrl::FullyDecoded).toHtmlEscaped());
if(QString server_exp = q.queryItemValue(QStringLiteral("server_exp"), QUrl::FullyDecoded); !server_exp.isEmpty())
{
auto date = QDateTime::fromSecsSinceEpoch(server_exp.toLongLong());
bool canDecrypt = QDateTime::currentDateTimeUtc() < date;
ui->expire->setProperty("label", canDecrypt ? QStringLiteral("good") : QStringLiteral("error"));
ui->expire->setText(canDecrypt ? QStringLiteral("%1 %2").arg(
tr("Can decrypt until:"), DateTime(date.toLocalTime()).formatDate(QStringLiteral("dd. MMMM yyyy"))) :
tr("Decrypting is expired"));
}
}

if(!cert.isNull())
{
ui->expire->setProperty("label", QStringLiteral("default"));
ui->expire->setText(QStringLiteral("%1 %2").arg(
cert.isValid() ? tr("Expires on") : tr("Expired on"),
DateTime(cert.expiryDate().toLocalTime()).formatDate(QStringLiteral("dd. MMMM yyyy"))));
}

if(!str.isEmpty())
str += QStringLiteral(" - ");
DateTime date(cert.expiryDate().toLocalTime());
ui->idType->setText(QStringLiteral("%1%2 %3").arg(str,
cert.isValid() ? tr("Expires on") : tr("Expired on"),
date.formatDate(QStringLiteral("dd. MMMM yyyy"))));
ui->idType->setHidden(ui->idType->text().isEmpty());
ui->expire->setHidden(ui->expire->text().isEmpty());
}
3 changes: 3 additions & 0 deletions client/widgets/AddressItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "widgets/Item.h"

class CKey;
class QUrlQuery;

class AddressItem final : public Item
{
Expand Down Expand Up @@ -53,6 +54,8 @@ class AddressItem final : public Item
void setName();
void setIdType();

static QUrlQuery parseKeyLabelDataUrl(const QString &dataUrl);

class Private;
Private *ui;
};
19 changes: 17 additions & 2 deletions client/widgets/AddressItem.ui
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,24 @@ font-weight: 700;
#idType {
color: #07142A;
}
#expire {
QLabel[label=&quot;default&quot;] {
color: #07142A;
background: #F3F5F7;
padding: 2px 8px;
border-radius: 8px;
}
QLabel[label=&quot;error&quot;] {
color: #AD2A45;
background: #F5EBED;
padding: 2px 8px;
border-radius: 8px;
}
QLabel[label=&quot;good&quot;] {
color: #1A641B;
background: #EAF8EA;
padding: 2px 8px;
border-radius: 8px;
}
QToolButton {
font-weight: 700;
border-radius: 2px;
Expand Down Expand Up @@ -120,6 +132,9 @@ color: #727679;
<property name="text">
<string notr="true">Expire</string>
</property>
<property name="label" stdset="0">
<string notr="true">default</string>
</property>
</widget>
</item>
<item row="1" column="3">
Expand Down Expand Up @@ -214,7 +229,7 @@ color: #727679;
<customwidget>
<class>QSvgWidget</class>
<extends>QWidget</extends>
<header location="global">QtSvg/QSvgWidget</header>
<header location="global">QSvgWidget</header>
<container>1</container>
</customwidget>
</customwidgets>
Expand Down

0 comments on commit 9217ee7

Please sign in to comment.