Skip to content

Commit 6496acc

Browse files
authored
Fix PUK message with Omnikey PinPad (#1378)
IB-8774 Signed-off-by: Raul Metsma <[email protected]>
1 parent 7b4bbdb commit 6496acc

File tree

9 files changed

+247
-323
lines changed

9 files changed

+247
-323
lines changed

client/MainWindow.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class MainWindow final : public QWidget
8282
template <typename F>
8383
void sign(F &&sign);
8484
bool validateFiles(const QString &container, const QStringList &files);
85-
void showPinBlockedWarning(const QSmartCardData &data);
8685
void updateSelector();
8786
void updateSelectorData(TokenData data);
8887
void updateMyEID(const TokenData &t);

client/MainWindow_MyEID.cpp

Lines changed: 32 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "Application.h"
2424
#include "QSigner.h"
2525
#include "SslCertificate.h"
26-
#include "effects/FadeInNotification.h"
2726
#include "widgets/WarningItem.h"
2827
#include "widgets/WarningList.h"
2928

@@ -34,89 +33,8 @@ using namespace ria::qdigidoc4;
3433

3534
void MainWindow::changePinClicked(QSmartCardData::PinType type, QSmartCard::PinAction action)
3635
{
37-
QSmartCardData::PinType src = type;
38-
QSmartCard::ErrorType err;
39-
if(action == QSmartCard::ChangeWithPin || action == QSmartCard::ActivateWithPin)
40-
err = qApp->signer()->smartcard()->pinChange(type, action, this);
41-
else
42-
{
43-
src = QSmartCardData::PukType;
44-
err = qApp->signer()->smartcard()->pinUnblock(type, action, this);
45-
}
46-
QSmartCardData data = qApp->signer()->smartcard()->data();
47-
ui->accordion->updateInfo(data);
48-
switch(err)
49-
{
50-
using enum QSmartCard::ErrorType;
51-
case NoError:
52-
switch(action)
53-
{
54-
using enum QSmartCard::PinAction;
55-
case ActivateWithPin:
56-
case ActivateWithPuk:
57-
showPinBlockedWarning(data);
58-
Q_FALLTHROUGH();
59-
case ChangeWithPin:
60-
case ChangeWithPuk:
61-
return FadeInNotification::success(ui->topBar, tr("%1 changed!").arg(QSmartCardData::typeString(type)));
62-
case UnblockWithPuk:
63-
showPinBlockedWarning(data);
64-
return FadeInNotification::success(ui->topBar, tr("%1 has been changed and the certificate has been unblocked!")
65-
.arg(QSmartCardData::typeString(type)));
66-
}
67-
case BlockedError:
68-
showPinBlockedWarning(data);
69-
return FadeInNotification::warning(ui->topBar, tr("%1 blocked").arg(QSmartCardData::typeString(src)));
70-
case ValidateError:
71-
return FadeInNotification::warning(ui->topBar, tr("Wrong %1 code. You can try %n more time(s).", nullptr,
72-
data.retryCount(src)).arg(QSmartCardData::typeString(src)));
73-
case CancelError: break;
74-
case TimeoutError:
75-
return FadeInNotification::warning(ui->topBar, tr("%1 timeout").arg(QSmartCardData::typeString(type)));
76-
case DifferentError:
77-
return FadeInNotification::warning(ui->topBar, tr("New %1 codes doesn't match").arg(QSmartCardData::typeString(type)));
78-
case LenghtError:
79-
return FadeInNotification::warning(ui->topBar, tr("%1 length has to be between %2 and 12")
80-
.arg(QSmartCardData::typeString(type)).arg(QSmartCardData::minPinLen(type)));
81-
case OldNewPinSameError:
82-
return FadeInNotification::warning(ui->topBar, tr("Old and new %1 has to be different!").arg(QSmartCardData::typeString(type)));
83-
default:
84-
return FadeInNotification::warning(ui->topBar, tr("Changing %1 failed").arg(QSmartCardData::typeString(type)));
85-
}
86-
}
87-
88-
void MainWindow::showPinBlockedWarning(const QSmartCardData &data)
89-
{
90-
if(data.isNull())
91-
return;
92-
bool pin1Blocked = data.retryCount(QSmartCardData::Pin1Type) == 0;
93-
bool pin2Blocked = data.retryCount(QSmartCardData::Pin2Type) == 0;
94-
bool pin2Locked = data.pinLocked(QSmartCardData::Pin2Type);
95-
ui->myEid->warningIcon(
96-
pin1Blocked ||
97-
pin2Blocked || pin2Locked ||
98-
data.retryCount(QSmartCardData::PukType) == 0);
99-
ui->signContainerPage->cardChanged(data.signCert(), pin2Blocked || pin2Locked);
100-
ui->cryptoContainerPage->cardChanged(data.authCert(), pin1Blocked);
101-
102-
ui->warnings->closeWarning(WarningType::UnblockPin1Warning);
103-
ui->warnings->closeWarning(WarningType::ActivatePin1WithPUKWarning);
104-
if(pin1Blocked)
105-
ui->warnings->showWarning({WarningType::UnblockPin1Warning, 0,
106-
[this]{ changePinClicked(QSmartCardData::Pin1Type, QSmartCard::UnblockWithPuk); }});
107-
108-
ui->warnings->closeWarning(WarningType::UnblockPin2Warning);
109-
ui->warnings->closeWarning(WarningType::ActivatePin2WithPUKWarning);
110-
ui->warnings->closeWarning(WarningType::ActivatePin2Warning);
111-
if(pin2Locked && pin2Blocked)
112-
ui->warnings->showWarning({WarningType::ActivatePin2WithPUKWarning, 0,
113-
[this]{ changePinClicked(QSmartCardData::Pin2Type, QSmartCard::ActivateWithPuk); }});
114-
else if(pin2Blocked)
115-
ui->warnings->showWarning({WarningType::UnblockPin2Warning, 0,
116-
[this]{ changePinClicked(QSmartCardData::Pin2Type, QSmartCard::UnblockWithPuk); }});
117-
else if(pin2Locked)
118-
ui->warnings->showWarning({WarningType::ActivatePin2Warning, 0,
119-
[this]{ changePinClicked(QSmartCardData::Pin2Type, QSmartCard::ActivateWithPin); }});
36+
if(qApp->signer()->smartcard()->pinChange(type, action, ui->topBar))
37+
updateMyEid(qApp->signer()->smartcard()->data());
12038
}
12139

12240
void MainWindow::updateMyEID(const TokenData &t)
@@ -153,18 +71,42 @@ void MainWindow::updateMyEID(const TokenData &t)
15371
}
15472
}
15573

156-
void MainWindow::updateMyEid(const QSmartCardData &t)
74+
void MainWindow::updateMyEid(const QSmartCardData &data)
15775
{
158-
ui->warnings->clearMyEIDWarnings();
159-
ui->infoStack->update(t);
160-
ui->accordion->updateInfo(t);
76+
ui->infoStack->update(data);
77+
ui->accordion->updateInfo(data);
16178
ui->myEid->warningIcon(false);
16279
ui->myEid->invalidIcon(false);
163-
if(t.isNull())
80+
ui->warnings->clearMyEIDWarnings();
81+
if(data.isNull())
16482
return;
83+
bool pin1Blocked = data.retryCount(QSmartCardData::Pin1Type) == 0;
84+
bool pin2Blocked = data.retryCount(QSmartCardData::Pin2Type) == 0;
85+
bool pin2Locked = data.pinLocked(QSmartCardData::Pin2Type);
86+
ui->myEid->warningIcon(
87+
pin1Blocked ||
88+
pin2Blocked || pin2Locked ||
89+
data.retryCount(QSmartCardData::PukType) == 0);
90+
ui->signContainerPage->cardChanged(data.signCert(), pin2Blocked || pin2Locked);
91+
ui->cryptoContainerPage->cardChanged(data.authCert(), pin1Blocked);
92+
93+
if(pin1Blocked)
94+
ui->warnings->showWarning({WarningType::UnblockPin1Warning, 0,
95+
[this]{ changePinClicked(QSmartCardData::Pin1Type, QSmartCard::UnblockWithPuk); }});
96+
97+
if(pin2Locked && pin2Blocked)
98+
ui->warnings->showWarning({WarningType::ActivatePin2WithPUKWarning, 0,
99+
[this]{ changePinClicked(QSmartCardData::Pin2Type, QSmartCard::ActivateWithPuk); }});
100+
else if(pin2Blocked)
101+
ui->warnings->showWarning({WarningType::UnblockPin2Warning, 0,
102+
[this]{ changePinClicked(QSmartCardData::Pin2Type, QSmartCard::UnblockWithPuk); }});
103+
else if(pin2Locked)
104+
ui->warnings->showWarning({WarningType::ActivatePin2Warning, 0,
105+
[this]{ changePinClicked(QSmartCardData::Pin2Type, QSmartCard::ActivateWithPin); }});
106+
165107
const qint64 DAY = 24 * 60 * 60;
166108
qint64 expiresIn = 106 * DAY;
167-
for(const QSslCertificate &cert: {t.authCert(), t.signCert()})
109+
for(const QSslCertificate &cert: {data.authCert(), data.signCert()})
168110
{
169111
if(!cert.isNull())
170112
expiresIn = std::min<qint64>(expiresIn, QDateTime::currentDateTime().secsTo(cert.expiryDate().toLocalTime()));
@@ -179,5 +121,4 @@ void MainWindow::updateMyEid(const QSmartCardData &t)
179121
ui->myEid->warningIcon(true);
180122
ui->warnings->showWarning({WarningType::CertExpiryWarning});
181123
}
182-
showPinBlockedWarning(t);
183124
}

client/QPCSC.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class QPCSCReader final: public QObject
5656
public:
5757
struct Result {
5858
QByteArray data;
59-
quint16 SW;
59+
quint16 SW = 0;
6060
quint32 err = 0;
6161
constexpr operator bool() const { return SW == 0x9000; }
6262
};

0 commit comments

Comments
 (0)