diff --git a/client/QPCSC.cpp b/client/QPCSC.cpp index 3f56cdbf..97830c63 100644 --- a/client/QPCSC.cpp +++ b/client/QPCSC.cpp @@ -38,7 +38,7 @@ Q_LOGGING_CATEGORY(SCard,"QPCSC.SCard") static quint16 toUInt16(const QByteArray &data, int size) { - return size >= 2 ? quint16((quint16(data[size - 2]) << 8) | quint16(data[size - 1])) : 0; + return size >= 2 ? quint16((quint16(data[size - 2]) << 8) | quint8(data[size - 1])) : 0; } static QStringList stateToString(DWORD state) @@ -58,31 +58,31 @@ static QStringList stateToString(DWORD state) return result; } -template -static auto SCCall(const char *file, int line, const char *function, Func func, Args... args) +template +static auto SCCall(const char *file, int line, const char *function, Args... args) { - auto err = func(args...); + auto err = Func(args...); if(SCard().isDebugEnabled()) QMessageLogger(file, line, function, SCard().categoryName()).debug() << function << Qt::hex << (unsigned long)err; return err; } -#define SC(API, ...) SCCall(__FILE__, __LINE__, "SCard"#API, SCard##API, __VA_ARGS__) +#define SC(API, ...) SCCall(__FILE__, __LINE__, "SCard"#API, __VA_ARGS__) QHash QPCSCReader::Private::features() { if(!featuresList.isEmpty()) return featuresList; DWORD size = 0; - std::array feature{}; - if(SC(Control, card, DWORD(CM_IOCTL_GET_FEATURE_REQUEST), nullptr, 0U, feature.data(), DWORD(feature.size()), &size)) + std::array feature{}; + if(SC(Control, card, DWORD(CM_IOCTL_GET_FEATURE_REQUEST), nullptr, 0U, feature.data(), DWORD(feature.size() * sizeof(PCSC_TLV_STRUCTURE)), &size)) return featuresList; - for(auto p = feature.cbegin(); std::distance(feature.cbegin(), p) < size; ) + if(size % sizeof(PCSC_TLV_STRUCTURE)) + return featuresList; + for(const auto &f: feature) { - unsigned int tag = *p++, len = *p++, value = 0; - for(unsigned int i = 0; i < len; ++i) - value |= *p++ << 8 * i; - featuresList[DRIVER_FEATURES(tag)] = qFromBigEndian(value); + if(f.tag) + featuresList[DRIVER_FEATURES(f.tag)] = qFromBigEndian(f.value); } return featuresList; } diff --git a/client/QSmartCard.cpp b/client/QSmartCard.cpp index 16dcec7a..83c91f3d 100644 --- a/client/QSmartCard.cpp +++ b/client/QSmartCard.cpp @@ -383,7 +383,7 @@ QSmartCard::ErrorType QSmartCard::pinChange(QSmartCardData::PinType type, QWidge else { SslCertificate cert = d->t.authCert(); - title = cert.toString(cert.showCN() ? QStringLiteral("CN, serialNumber") : QStringLiteral("GN SN, serialNumber")); + title = cert.toString(cert.showCN() ? QStringLiteral("CN, serialNumber") : QStringLiteral("GN SN, serialNumber")); textBody = tr("To change %1 on a PinPad reader the old %1 code has to be entered first and then the new %1 code twice.").arg(QSmartCardData::typeString(type)); } return change(type, parent, newPin, oldPin, title, textBody); @@ -407,7 +407,7 @@ QSmartCard::ErrorType QSmartCard::pinUnblock(QSmartCardData::PinType type, bool else { SslCertificate cert = d->t.authCert(); - title = cert.toString(cert.showCN() ? QStringLiteral("CN, serialNumber") : QStringLiteral("GN SN, serialNumber")); + title = cert.toString(cert.showCN() ? QStringLiteral("CN, serialNumber") : QStringLiteral("GN SN, serialNumber")); textBody = isForgotPin ? tr("To change %1 code with the PUK code on a PinPad reader the PUK code has to be entered first and then the %1 code twice.").arg(QSmartCardData::typeString(type)) : tr("To unblock the %1 code on a PinPad reader the PUK code has to be entered first and then the %1 code twice.").arg(QSmartCardData::typeString(type)); diff --git a/client/dialogs/MobileProgress.cpp b/client/dialogs/MobileProgress.cpp index aee2e5a3..0bfa1fe5 100644 --- a/client/dialogs/MobileProgress.cpp +++ b/client/dialogs/MobileProgress.cpp @@ -70,6 +70,7 @@ MobileProgress::MobileProgress(QWidget *parent) d->setWindowFlags(Qt::Dialog|Qt::CustomizeWindowHint); d->setupUi(d); d->code->setBuddy(d->signProgressBar); + d->code->clear(); #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) const auto styleSheet = R"(QProgressBar { background-color: #d3d3d3; diff --git a/client/dialogs/PinUnblock.cpp b/client/dialogs/PinUnblock.cpp index af978064..9fc413e8 100644 --- a/client/dialogs/PinUnblock.cpp +++ b/client/dialogs/PinUnblock.cpp @@ -45,18 +45,17 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t new Overlay(this); auto pattern = [](QSmartCardData::PinType type) { - return QStringLiteral("^\\d{%1,12}$").arg(QSmartCardData::minPinLen(type)); + return QRegularExpression(QStringLiteral("^\\d{%1,12}$").arg(QSmartCardData::minPinLen(type))); }; QRegularExpression regexpValidateCode; - QRegularExpression regexpNewCode; - regexpNewCode.setPattern(pattern(type)); + QRegularExpression regexpNewCode = pattern(type); switch(mode) { case PinUnblock::UnBlockPinWithPuk: ui->label->setText(tr("%1 unblocking").arg(QSmartCardData::typeString(type))); ui->change->setText(tr("Unblock")); - regexpValidateCode.setPattern(pattern(QSmartCardData::PukType)); + regexpValidateCode = pattern(QSmartCardData::PukType); ui->line1_text->setText(tr("To unblock the certificate you have to enter the PUK code.")); ui->line2_text->setText(tr("You can find your PUK code inside the ID-card codes envelope.")); ui->line3_text->setText(tr("If you have forgotten the PUK code for your ID card, please visit " @@ -65,7 +64,7 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t break; case PinUnblock::ChangePinWithPuk: ui->label->setText(tr("%1 code change").arg(QSmartCardData::typeString(type))); - regexpValidateCode.setPattern(pattern(QSmartCardData::PukType)); + regexpValidateCode = pattern(QSmartCardData::PukType); ui->line1_text->setText(type == QSmartCardData::Pin2Type ? tr("PIN2 code is used to digitally sign documents.") : tr("PIN1 code is used for confirming the identity of a person.")); @@ -75,7 +74,7 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t case PinUnblock::PinChange: ui->label->setText(tr("%1 code change").arg(QSmartCardData::typeString(type))); ui->labelPuk->setText(tr("Valid %1 code").arg(QSmartCardData::typeString(type))); - regexpValidateCode.setPattern(pattern(type)); + regexpValidateCode = pattern(type); if(type == QSmartCardData::PukType) { ui->line1_text->setText(tr("PUK code is used for unblocking the certificates, when PIN1 or PIN2 has been entered 3 times incorrectly.")); @@ -100,8 +99,14 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t ui->repeat->setValidator(new QRegularExpressionValidator(regexpNewCode, ui->repeat)); ui->puk->setValidator(new QRegularExpressionValidator(regexpValidateCode, ui->puk)); + auto setError = [](QLineEdit *input, QLabel *error, const QString &msg) { + input->setStyleSheet(msg.isEmpty() ? QString() : QStringLiteral("border-color: #BE7884")); + error->setFocusPolicy(msg.isEmpty() ? Qt::NoFocus : Qt::TabFocus); + error->setText(msg); + error->setHidden(msg.isEmpty()); + }; if(leftAttempts < 3) - ui->errorPuk->setText(mode == PinUnblock::PinChange ? + setError(ui->puk, ui->errorPuk, mode == PinUnblock::PinChange ? tr("Remaining attempts: %1").arg(leftAttempts) : tr("PUK remaining attempts: %1").arg(leftAttempts)); @@ -113,12 +118,6 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t if(auto *bullet = findChild(QStringLiteral("line%1_bullet").arg(i))) bullet->setHidden(isHidden); } - auto setError = [](QLineEdit *input, QLabel *error, const QString &msg) { - input->setStyleSheet(msg.isEmpty() ? QString() : QStringLiteral("border-color: #BE7884")); - error->setFocusPolicy(msg.isEmpty() ? Qt::NoFocus : Qt::TabFocus); - error->setText(msg); - error->setHidden(msg.isEmpty()); - }; connect(ui->cancel, &QPushButton::clicked, this, &PinUnblock::reject); connect(this, &PinUnblock::finished, this, &PinUnblock::close); connect(ui->pin, &QLineEdit::returnPressed, ui->change, &QPushButton::click); diff --git a/client/dialogs/SmartIDProgress.cpp b/client/dialogs/SmartIDProgress.cpp index da2070fa..c0e7dd2e 100644 --- a/client/dialogs/SmartIDProgress.cpp +++ b/client/dialogs/SmartIDProgress.cpp @@ -83,6 +83,7 @@ SmartIDProgress::SmartIDProgress(QWidget *parent) d->setupUi(d); d->signProgressBar->setMaximum(100); d->code->setBuddy(d->signProgressBar); + d->code->clear(); #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) const auto styleSheet = R"(QProgressBar { background-color: #d3d3d3;;