From 3a53b1e09e383b87fe4d6e710f26930051c8d645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Tue, 25 Sep 2012 13:29:41 +0000 Subject: [PATCH] works principially, but also accepts 5, because that's the length of the transport pin - card is wrongly initialized, but at least behaviour is standard conform and implementation is generic; refs #126 --- src/pinentry.hxx | 18 +++++++++++++++++- src/pinentry.ui | 10 +++++----- src/smartcardauth.hxx | 3 ++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/pinentry.hxx b/src/pinentry.hxx index b61eec0..661c18d 100644 --- a/src/pinentry.hxx +++ b/src/pinentry.hxx @@ -8,6 +8,7 @@ #ifndef __PINDIALOG_HXX__ #define __PINDIALOG_HXX__ +#include #include #include #include @@ -19,7 +20,9 @@ class PinEntry: public QDialog, public Ui::PinEntry { Q_OBJECT; public: - PinEntry(const QSslCertificate& cert, QWidget *parent=0): QDialog(parent) { + PinEntry(const QSslCertificate& cert, QWidget *parent=0): + QDialog(parent), + _maxPinLen(-1), _minPinLen(0) { setModal(true); setupUi(this); _cert->certificate(cert); @@ -37,6 +40,12 @@ class PinEntry: public QDialog, public Ui::PinEntry { _certSerial->setText(cert.serialNumber()); } } + PinEntry& tokeninfo(const cryptoki::TokenInfo& ti) { + _maxPinLen = ti.maxPinLen; + _minPinLen = ti.minPinLen; + on__pin_textChanged(_pin->text()); + return *this; + } PinEntry& retries(int num) { _pinstatus->setCurrentIndex(num==-1?1:(num==-2?2:0)); _retries->setText(tr("there are %1 PIN attempts left").arg(num)); @@ -76,6 +85,11 @@ class PinEntry: public QDialog, public Ui::PinEntry { _cert->setVisible(s); adjustSize(); } + void on__pin_textChanged(const QString &text) { + _buttonBox->button(QDialogButtonBox::Ok) + ->setEnabled((unsigned long)text.size()>=_minPinLen && + (unsigned long)text.size()<=_maxPinLen); + } protected: QString utfConv(const QString& txt) { QByteArray value(txt.toAscii()); @@ -85,6 +99,8 @@ class PinEntry: public QDialog, public Ui::PinEntry { } private: QEventLoop _run; + unsigned long _maxPinLen; + unsigned long _minPinLen; }; #endif diff --git a/src/pinentry.ui b/src/pinentry.ui index df4df21..f3d95b1 100644 --- a/src/pinentry.ui +++ b/src/pinentry.ui @@ -6,8 +6,8 @@ 0 0 - 668 - 602 + 688 + 594 @@ -179,7 +179,7 @@ - + Qt::Horizontal @@ -203,7 +203,7 @@ - buttonBox + _buttonBox accepted() PinEntry accept() @@ -219,7 +219,7 @@ - buttonBox + _buttonBox rejected() PinEntry reject() diff --git a/src/smartcardauth.hxx b/src/smartcardauth.hxx index 2a126be..a53b93e 100644 --- a/src/smartcardauth.hxx +++ b/src/smartcardauth.hxx @@ -208,7 +208,8 @@ class SmartCardAuth: public QObject { QSsl::Der), _parent); while (true) try { LOG<<"******************************************1*******"; - pinEntry.retries(retries(c.slot->slotinfo().slotDescription)); + pinEntry.tokeninfo(c.slot->tokeninfo()) + .retries(retries(c.slot->slotinfo().slotDescription)); LOG<<"******************************************2*******"; int res(pinEntry.myexec()); LOG<<"******************************************3*******";