You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
3.6 KiB
124 lines
3.6 KiB
13 years ago
|
/*! @file
|
||
|
|
||
|
@id $Id$
|
||
|
*/
|
||
|
// 1 2 3 4 5 6 7 8
|
||
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||
|
|
||
|
#ifndef __PINDIALOG_HXX__
|
||
|
#define __PINDIALOG_HXX__
|
||
|
|
||
12 years ago
|
#include <cryptoki.hxx>
|
||
12 years ago
|
#include <qbrowserlib/log.hxx>
|
||
9 years ago
|
#include <qbrowserlib/ui_pinentry.hxx>
|
||
9 years ago
|
#include <QDialog>
|
||
13 years ago
|
#include <QtCore/QDateTime>
|
||
|
#include <QtNetwork/QSslCertificate>
|
||
|
|
||
13 years ago
|
#include <cassert>
|
||
13 years ago
|
|
||
9 years ago
|
namespace qbrowserlib {
|
||
|
|
||
13 years ago
|
class PinEntry: public QDialog, public Ui::PinEntry {
|
||
|
Q_OBJECT;
|
||
|
public:
|
||
12 years ago
|
PinEntry(const QSslCertificate& cert, QWidget *parent=0):
|
||
|
QDialog(parent),
|
||
|
_maxPinLen(-1), _minPinLen(0) {
|
||
12 years ago
|
setModal(true);
|
||
13 years ago
|
setupUi(this);
|
||
13 years ago
|
_cert->certificate(cert);
|
||
12 years ago
|
on__showDetails_toggled(false);
|
||
9 years ago
|
_name->setText(utfConv(cert.subjectInfo(QSslCertificate::CommonName)
|
||
|
#if QT_VERSION >= 0x050000
|
||
|
.join('\n')
|
||
|
#endif
|
||
|
).remove(" (Authentication)"));
|
||
|
#if QT_VERSION < 0x050000
|
||
13 years ago
|
_mail->setText(utfConv(cert.alternateSubjectNames()
|
||
|
.value(QSsl::EmailEntry)));
|
||
9 years ago
|
#else
|
||
|
_mail->setText(utfConv(cert.subjectAlternativeNames()
|
||
|
.value(QSsl::EmailEntry)));
|
||
|
#endif
|
||
13 years ago
|
if (!cert.subjectInfo(QByteArray("serialNumber")).isEmpty()) {
|
||
|
_certSerialTitle->setText(tr("SuisseID Number:"));
|
||
9 years ago
|
_certSerial->setText(cert.subjectInfo(QByteArray("serialNumber"))
|
||
|
#if QT_VERSION >= 0x050000
|
||
|
.join('\n')
|
||
|
#endif
|
||
|
);
|
||
13 years ago
|
} else {
|
||
|
_certSerialTitle->setText
|
||
|
(tr("Postzertifikat:", "title for postzertificate serial number"));
|
||
|
_certSerial->setText(cert.serialNumber());
|
||
|
}
|
||
13 years ago
|
}
|
||
10 years ago
|
PinEntry& tokeninfo(unsigned int min, unsigned int max) {
|
||
|
_maxPinLen = max;
|
||
|
_minPinLen = min;
|
||
12 years ago
|
on__pin_textChanged(_pin->text());
|
||
|
return *this;
|
||
|
}
|
||
13 years ago
|
PinEntry& retries(int num) {
|
||
|
_pinstatus->setCurrentIndex(num==-1?1:(num==-2?2:0));
|
||
|
_retries->setText(tr("there are %1 PIN attempts left").arg(num));
|
||
|
return *this;
|
||
|
}
|
||
13 years ago
|
QString pin() const {
|
||
|
return _pin->text();
|
||
|
}
|
||
13 years ago
|
int myexec() {
|
||
12 years ago
|
TRC;
|
||
12 years ago
|
_pin->clear();
|
||
13 years ago
|
show();
|
||
|
int res(_run.exec(QEventLoop::ExcludeSocketNotifiers));
|
||
|
hide();
|
||
|
return res;
|
||
|
}
|
||
|
public Q_SLOTS:
|
||
|
virtual void accept() {
|
||
12 years ago
|
TRC;
|
||
13 years ago
|
QDialog::accept();
|
||
|
}
|
||
|
virtual void done(int r) {
|
||
12 years ago
|
TRC; LOG<<r;
|
||
13 years ago
|
_run.exit(r);
|
||
|
assert(!_run.isRunning());
|
||
|
QDialog::done(r);
|
||
|
}
|
||
|
virtual void reject() {
|
||
12 years ago
|
TRC;
|
||
13 years ago
|
QDialog::reject();
|
||
|
}
|
||
13 years ago
|
protected Q_SLOTS:
|
||
|
void on__showDetails_toggled(bool s) {
|
||
12 years ago
|
_cert->setVisible(s);
|
||
|
adjustSize();
|
||
13 years ago
|
}
|
||
12 years ago
|
void on__pin_textChanged(const QString &text) {
|
||
10 years ago
|
TRC; LOG<<"pin length - min: "<<_minPinLen<<" - max: "<<_maxPinLen;
|
||
12 years ago
|
_buttonBox->button(QDialogButtonBox::Ok)
|
||
|
->setEnabled((unsigned long)text.size()>=_minPinLen &&
|
||
|
(unsigned long)text.size()<=_maxPinLen);
|
||
10 years ago
|
if ((unsigned long)text.size()<_minPinLen)
|
||
|
_pin->setToolTip(tr("minimum PIN length: %1").arg(_minPinLen));
|
||
|
if ((unsigned long)text.size()>_maxPinLen)
|
||
|
_pin->setToolTip(tr("maximum PIN length: %1").arg(_maxPinLen));
|
||
12 years ago
|
}
|
||
13 years ago
|
protected:
|
||
|
QString utfConv(const QString& txt) {
|
||
9 years ago
|
QByteArray value(txt.toUtf8());
|
||
13 years ago
|
for (int i(-1); (i=value.indexOf("\\x"))!=-1 && i+3<value.size();)
|
||
|
value.replace(i, 4, QByteArray::fromHex(value.mid(i+2, 2)));
|
||
|
return QString::fromUtf8(value.data(), value.size());
|
||
|
}
|
||
13 years ago
|
private:
|
||
|
QEventLoop _run;
|
||
12 years ago
|
unsigned long _maxPinLen;
|
||
|
unsigned long _minPinLen;
|
||
13 years ago
|
};
|
||
9 years ago
|
|
||
|
}
|
||
13 years ago
|
#endif
|