@@ -47,6 +47,21 @@ class Signer: public QDialog {
4747public:
4848 static QVariantMap sign (const QString &hash, const QString &cert) {
4949 std::vector<unsigned char > data = fromHex (cert);
50+ QSslCertificate c (QByteArray::fromRawData ((const char *)data.data (), int (data.size ())), QSsl::Der);
51+ bool isNonRepudiation = false ;
52+ for (const QSslCertificateExtension &ex: c.extensions ())
53+ {
54+ if (ex.name () == QStringLiteral (" keyUsage" ))
55+ {
56+ for (const QVariant &item: ex.value ().toList ())
57+ if (item.toString () == QStringLiteral (" Non Repudiation" ))
58+ isNonRepudiation = true ;
59+ }
60+ }
61+ if (!isNonRepudiation) {
62+ return {{" result" , " invalid_argument" }};
63+ }
64+
5065 PKCS11CardManager::Token selected;
5166 PKCS11Path::Params p11 = PKCS11Path::getPkcs11ModulePath ();
5267 PKCS11CardManager pkcs11 (p11.path );
@@ -65,26 +80,8 @@ class Signer: public QDialog {
6580 if (selected.cert .empty ())
6681 return {{" result" , " invalid_argument" }};
6782
68- QSslCertificate c (QByteArray::fromRawData ((const char *)data.data (), int (data.size ())), QSsl::Der);
69- bool isNonRepudiation = false ;
70- for (const QSslCertificateExtension &ex: c.extensions ())
71- {
72- if (ex.name () == QStringLiteral (" keyUsage" ))
73- {
74- for (const QVariant &item: ex.value ().toList ())
75- if (item.toString () == QStringLiteral (" Non Repudiation" ))
76- isNonRepudiation = true ;
77- }
78- }
79- QString label;
80- if (isNonRepudiation) {
81- label = Labels::l10n.get (selected.pinpad ? " sign PIN pinpad" : " sign PIN" ).c_str ();
82- label.replace (" @PIN@" , p11.signPINLabel .c_str ());
83- }
84- else {
85- label = Labels::l10n.get (selected.pinpad ? " auth PIN pinpad" : " auth PIN" ).c_str ();
86- label.replace (" @PIN@" , p11.authPINLabel .c_str ());
87- }
83+ QString label = Labels::l10n.get (selected.pinpad ? " sign PIN pinpad" : " sign PIN" ).c_str ();
84+ label.replace (" @PIN@" , p11.signPINLabel .c_str ());
8885
8986 bool isInitialCheck = true ;
9087 for (int retriesLeft = selected.retry ; retriesLeft > 0 ; ) {
@@ -172,48 +169,46 @@ class Signer: public QDialog {
172169
173170 Signer (const QString &label, unsigned long minPinLen, bool isPinpad)
174171 : nameLabel(new QLabel(this ))
175- , pinLabel(new QLabel(this ))
176172 , errorLabel(new QLabel(this ))
177173 {
178174 QVBoxLayout *layout = new QVBoxLayout (this );
179175 layout->addWidget (errorLabel);
180176 layout->addWidget (nameLabel);
181- layout->addWidget (pinLabel );
177+ layout->addWidget (new QLabel (label, this ) );
182178
183179 setMinimumWidth (400 );
184180 setWindowFlags (Qt::WindowStaysOnTopHint);
185- pinLabel->setText (label);
186181 errorLabel->setTextFormat (Qt::RichText);
187182 errorLabel->hide ();
188183
189184 if (isPinpad) {
190185 setWindowFlags ((windowFlags ()|Qt::CustomizeWindowHint) & ~Qt::WindowCloseButtonHint);
191- progress = new QProgressBar (this );
186+ QProgressBar * progress = new QProgressBar (this );
192187 progress->setRange (0 , 30 );
193188 progress->setValue (progress->maximum ());
194189 progress->setTextVisible (false );
195190
196- statusTimer = new QTimeLine (progress->maximum () * 1000 , this );
191+ QTimeLine * statusTimer = new QTimeLine (progress->maximum () * 1000 , this );
197192 statusTimer->setCurveShape (QTimeLine::LinearCurve);
198193 statusTimer->setFrameRange (progress->maximum (), progress->minimum ());
199194 connect (statusTimer, &QTimeLine::frameChanged, progress, &QProgressBar::setValue);
200195 statusTimer->start ();
201196
202197 layout->addWidget (progress);
203198 } else {
204- buttons = new QDialogButtonBox (this );
199+ QDialogButtonBox * buttons = new QDialogButtonBox (this );
205200 connect (buttons, &QDialogButtonBox::accepted, this , &QDialog::accept);
206201 connect (buttons, &QDialogButtonBox::rejected, this , &QDialog::reject);
207- cancel = buttons->addButton (Labels::l10n.get (" cancel" ).c_str (), QDialogButtonBox::RejectRole);
208- ok = buttons->addButton (" OK" , QDialogButtonBox::AcceptRole);
202+ buttons->addButton (Labels::l10n.get (" cancel" ).c_str (), QDialogButtonBox::RejectRole);
203+ QPushButton * ok = buttons->addButton (" OK" , QDialogButtonBox::AcceptRole);
209204 ok->setEnabled (false );
210205
211206 pin = new QLineEdit (this );
212207 pin->setEchoMode (QLineEdit::Password);
213208 pin->setFocus ();
214209 pin->setValidator (new QRegExpValidator (QRegExp (QString (" \\ d{%1,12}" ).arg (minPinLen)), pin));
215210 pin->setMaxLength (12 );
216- connect (pin, &QLineEdit::textEdited, [=](const QString &text){
211+ connect (pin, &QLineEdit::textEdited, ok, [=](const QString &text) {
217212 ok->setEnabled (text.size () >= int (minPinLen));
218213 });
219214
@@ -223,10 +218,6 @@ class Signer: public QDialog {
223218 show ();
224219 }
225220
226- QLabel *nameLabel, *pinLabel, *errorLabel;
227- QDialogButtonBox *buttons = nullptr ;
228- QPushButton *ok = nullptr , *cancel = nullptr ;
221+ QLabel *nameLabel, *errorLabel;
229222 QLineEdit *pin = nullptr ;
230- QProgressBar *progress = nullptr ;
231- QTimeLine *statusTimer = nullptr ;
232223};
0 commit comments