diff options
Diffstat (limited to 'pica-client/dialogs')
| -rw-r--r-- | pica-client/dialogs/addaccountdialog.cpp | 114 | ||||
| -rw-r--r-- | pica-client/dialogs/addaccountdialog.h | 41 | ||||
| -rw-r--r-- | pica-client/dialogs/forgedcertdialog.cpp | 53 | ||||
| -rw-r--r-- | pica-client/dialogs/forgedcertdialog.h | 34 | ||||
| -rw-r--r-- | pica-client/dialogs/viewcertdialog.cpp | 68 | ||||
| -rw-r--r-- | pica-client/dialogs/viewcertdialog.h | 28 |
6 files changed, 338 insertions, 0 deletions
diff --git a/pica-client/dialogs/addaccountdialog.cpp b/pica-client/dialogs/addaccountdialog.cpp new file mode 100644 index 0000000..86849d4 --- /dev/null +++ b/pica-client/dialogs/addaccountdialog.cpp @@ -0,0 +1,114 @@ +#include "addaccountdialog.h" +#include <QGridLayout> +#include <QLabel> +#include <QFile> +#include <QFileDialog> +#include <QMessageBox> +#include <QProcess> +#include "../PICA_client.h" + +AddAccountDialog::AddAccountDialog(QWidget *parent) : + QDialog(parent) +{ + QGridLayout *grid = new QGridLayout(this); + + QLabel *lb_cert_file = new QLabel(tr("Pica Pica Certificate File:")); + QLabel *lb_pkey_file = new QLabel(tr("Private Key File:")); + + btOK = new QPushButton(tr("OK")); + btCancel = new QPushButton(tr("Cancel")); + + cert_filename = new QLineEdit(); + pkey_filename = new QLineEdit(); + + bt_browse_cert = new QPushButton("..."); + bt_browse_pkey = new QPushButton("..."); + + rb_copyfiles = new QRadioButton(tr("Copy files to config directory")); + rb_readinplace = new QRadioButton(tr("Read files from selected place")); + + grid->addWidget(lb_cert_file,0,0,1,1); + + grid->addWidget(cert_filename,1,0,1,1); + grid->addWidget(bt_browse_cert,1,1,1,1); + + grid->addWidget(lb_pkey_file,2,0,1,1); + + grid->addWidget(pkey_filename,3,0,1,1); + grid->addWidget(bt_browse_pkey,3,1,1,1); + + grid->addWidget(rb_copyfiles,4,0,1,1); + grid->addWidget(rb_readinplace,5,0,1,1); + + grid->addWidget(btOK,6,0,1,1,Qt::AlignRight); + grid->addWidget(btCancel,6,1,1,1,Qt::AlignLeft); + //=========== + rb_copyfiles->setChecked(true); + + btOK->setMaximumWidth(90); + btCancel->setMaximumWidth(90); + + connect(btOK,SIGNAL(clicked()),this,SLOT(OK())); + connect(btCancel,SIGNAL(clicked()),this,SLOT(Cancel())); + connect(bt_browse_cert,SIGNAL(clicked()),this,SLOT(browse_cert())); + connect(bt_browse_pkey,SIGNAL(clicked()),this,SLOT(browse_pkey())); + + +} + +void AddAccountDialog::OK() +{ + { + QString s; + if (!QFile::exists(s=cert_filename->text()) || !QFile::exists(s=pkey_filename->text()) ) + { + QMessageBox mbx; + mbx.setText(tr("File %1 does not exist").arg(s)); + mbx.exec(); + return; + } + + quint32 id; + + if (!PICA_get_id_from_cert(cert_filename->text().toUtf8().constData(),&id)) + { + QMessageBox mbx; + mbx.setText(tr("Invalid certificate file")); + mbx.exec(); + return; + } + } + + done(1); + +} + +void AddAccountDialog::Cancel() +{ + done(0); +} + +void AddAccountDialog::browse_cert() +{ + cert_filename->setText(QFileDialog::getOpenFileName(this,tr("Select Pica Pica Certificate"),"","PEM file (*.pem)")); +} + +void AddAccountDialog::browse_pkey() +{ + pkey_filename->setText(QFileDialog::getOpenFileName(this,tr("Select Private Key"),"","PEM file (*.pem)")); +} + +QString AddAccountDialog::GetCertFilename() +{ + return cert_filename->text(); +} + +QString AddAccountDialog::GetPkeyFilename() +{ + return pkey_filename->text(); +} + +bool AddAccountDialog::isCopyFilesChecked() +{ + return rb_copyfiles->isChecked(); +} diff --git a/pica-client/dialogs/addaccountdialog.h b/pica-client/dialogs/addaccountdialog.h new file mode 100644 index 0000000..976d020 --- /dev/null +++ b/pica-client/dialogs/addaccountdialog.h @@ -0,0 +1,41 @@ +#ifndef ADDACCOUNTDIALOG_H +#define ADDACCOUNTDIALOG_H + +#include <QDialog> +#include <QPushButton> +#include <QLineEdit> +#include <QRadioButton> + +class AddAccountDialog : public QDialog +{ + Q_OBJECT +public: + explicit AddAccountDialog(QWidget *parent = 0); + QString GetCertFilename(); + QString GetPkeyFilename(); + bool isCopyFilesChecked(); + +private: + QPushButton *btOK; + QPushButton *btCancel; + + QLineEdit *cert_filename; + QLineEdit *pkey_filename; + + QPushButton *bt_browse_cert; + QPushButton *bt_browse_pkey; + + QRadioButton *rb_copyfiles; + QRadioButton *rb_readinplace; +signals: + +public slots: +private slots: + void OK(); + void Cancel(); + void browse_cert(); + void browse_pkey(); + +}; + +#endif // ADDACCOUNTDIALOG_H diff --git a/pica-client/dialogs/forgedcertdialog.cpp b/pica-client/dialogs/forgedcertdialog.cpp new file mode 100644 index 0000000..5ca7f23 --- /dev/null +++ b/pica-client/dialogs/forgedcertdialog.cpp @@ -0,0 +1,53 @@ +#include "forgedcertdialog.h" +#include "viewcertdialog.h" +#include <QGridLayout> +#include <QLabel> + +ForgedCertDialog::ForgedCertDialog(quint32 peer_id, QString received_cert, QString stored_cert, QWidget *parent) : + QDialog(parent), + received_cert_(received_cert), + stored_cert_(stored_cert) +{ + QGridLayout *grid = new QGridLayout(this); + + QLabel *scary_text = new QLabel(tr( +"Previously stored and currently present certificates for user %1 do not match.\n\ +This means that probably someone is trying to eavesdrop your communication\n\ +using man-in-the-middle attack or impersonate the user.\n\ +Connection aborted.").arg(peer_id)); + + btOK = new QPushButton(tr("OK")); + btShow_stored_cert = new QPushButton(tr("View Stored Certificate...")); + btShow_received_cert = new QPushButton(tr("View Received Certificate...")); + + grid->addWidget(scary_text, 0,0, 1, 3, Qt::AlignCenter); + grid->addWidget(btShow_stored_cert, 1, 0, Qt::AlignCenter); + grid->addWidget(btShow_received_cert, 1, 2, Qt::AlignCenter); + grid->addWidget(btOK, 2, 1, Qt::AlignCenter); + + + setLayout(grid); + + connect(btOK, SIGNAL(clicked()), this, SLOT(OK())); + connect(btShow_stored_cert, SIGNAL(clicked()), this, SLOT(StoredCert())); + connect(btShow_received_cert, SIGNAL(clicked()), this, SLOT(ReceivedCert())); +} + +void ForgedCertDialog::OK() +{ + done(0); +} + +void ForgedCertDialog::ReceivedCert() +{ + ViewCertDialog vcd; + vcd.SetCert(received_cert_); + vcd.exec(); +} + +void ForgedCertDialog::StoredCert() +{ + ViewCertDialog vcd; + vcd.SetCert(stored_cert_); + vcd.exec(); +} diff --git a/pica-client/dialogs/forgedcertdialog.h b/pica-client/dialogs/forgedcertdialog.h new file mode 100644 index 0000000..bc259d4 --- /dev/null +++ b/pica-client/dialogs/forgedcertdialog.h @@ -0,0 +1,34 @@ +#ifndef FORGEDCERTDIALOG_H +#define FORGEDCERTDIALOG_H + +#include <QDialog> +#include <QPushButton> +#include "viewcertdialog.h" + +class ForgedCertDialog : public QDialog +{ + Q_OBJECT +public: + explicit ForgedCertDialog(quint32 peer_id, QString received_cert, QString stored_cert, QWidget *parent = 0); + +private: + QString received_cert_; + QString stored_cert_; + + QPushButton *btOK; + QPushButton *btShow_stored_cert; + QPushButton *btShow_received_cert; + + +signals: + +public slots: + +private slots: + void OK(); + void StoredCert(); + void ReceivedCert(); + +}; + +#endif // FORGEDCERTDIALOG_H diff --git a/pica-client/dialogs/viewcertdialog.cpp b/pica-client/dialogs/viewcertdialog.cpp new file mode 100644 index 0000000..8b096c2 --- /dev/null +++ b/pica-client/dialogs/viewcertdialog.cpp @@ -0,0 +1,68 @@ +#include "viewcertdialog.h" +#include <QVBoxLayout> +#include <QProcess> + +#include <QMessageBox> + +#include <unistd.h> +#include <stdio.h> +#include <sys/wait.h> +#include <QFile> + +ViewCertDialog::ViewCertDialog(QWidget *parent) : + QDialog(parent) +{ + QVBoxLayout *layout; + + layout = new QVBoxLayout; + cert_text = new QTextEdit(this); + btOK = new QPushButton(tr("OK")); + btOK->setMaximumWidth(45); + this->setMinimumWidth(640); + this->setMinimumHeight(480); + + QTextCharFormat fmt; + + fmt = cert_text->currentCharFormat(); + fmt.setFontFixedPitch(true); + fmt.setFontStyleHint(QFont::Monospace); + fmt.setFontFamily("Liberation Mono"); + cert_text->setCurrentCharFormat(fmt); + + cert_text->setReadOnly(true); + + layout->addWidget(cert_text); + layout->addWidget(btOK, 0, Qt::AlignCenter); + + setLayout(layout); + + connect(btOK, SIGNAL(clicked()), this, SLOT(OK())); + +} + +void ViewCertDialog::SetCert(QString cert_pem) +{ + QProcess openssl(this); + qint64 ret; + char *data; + QByteArray ba; + + openssl.start("openssl", QStringList()<<"x509"<<"-noout"<<"-text"<<"-nameopt"<<"multiline,-esc_msb,utf8"); + + if (!openssl.waitForStarted()) + return; + + ba = cert_pem.toAscii(); + ret = openssl.write(data = (char*)ba.constData()); + openssl.closeWriteChannel(); + + if (!openssl.waitForFinished()) + return; + + cert_text->setPlainText(QString::fromUtf8(openssl.readAllStandardOutput().constData())); +} + +void ViewCertDialog::OK() +{ + done(0); +} diff --git a/pica-client/dialogs/viewcertdialog.h b/pica-client/dialogs/viewcertdialog.h new file mode 100644 index 0000000..013815c --- /dev/null +++ b/pica-client/dialogs/viewcertdialog.h @@ -0,0 +1,28 @@ +#ifndef VIEWCERTDIALOG_H +#define VIEWCERTDIALOG_H + +#include <QDialog> +#include <QTextEdit> +#include <QPushButton> + +class ViewCertDialog : public QDialog +{ + Q_OBJECT +public: + explicit ViewCertDialog(QWidget *parent = 0); + void SetCert(QString cert_pem); + +private: + QTextEdit *cert_text; + QPushButton *btOK; + +signals: + +public slots: + +private slots: + void OK(); + +}; + +#endif // VIEWCERTDIALOG_H |
