summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnne Jan Brouwer <brouwer@annejan.com>2015-05-22 04:25:31 +0200
committerAnne Jan Brouwer <brouwer@annejan.com>2015-05-22 04:25:31 +0200
commit3e969e00c4c33adc577cca342a1287cb1e7ef2c7 (patch)
tree9745266c7744f2cb474ecc98213ac8609c4f9fff
parent166a24ea0a495d3f4e69b8ea8c1729b01d9f168a (diff)
keygen start, dialog ideas
-rw-r--r--dialog.cpp11
-rw-r--r--keygendialog.cpp66
-rw-r--r--keygendialog.h34
-rw-r--r--keygendialog.ui173
-rw-r--r--qtpass.pro9
5 files changed, 286 insertions, 7 deletions
diff --git a/dialog.cpp b/dialog.cpp
index 2078f5cf..558e5e33 100644
--- a/dialog.cpp
+++ b/dialog.cpp
@@ -1,6 +1,7 @@
#include "dialog.h"
#include "ui_dialog.h"
#include "mainwindow.h"
+#include "keygendialog.h"
#include <QDebug>
#include <QMessageBox>
@@ -358,10 +359,10 @@ void Dialog::addGPGId(bool addGPGId)
void Dialog::wizard()
{
- mainWindow->checkConfig();
+ //mainWindow->checkConfig();
-// QString gpg = ui->gpgPath->text();
- QString gpg = mainWindow->getGpgExecutable();
+ QString gpg = ui->gpgPath->text();
+ //QString gpg = mainWindow->getGpgExecutable();
if(!QFile(gpg).exists()){
QMessageBox::critical(this, tr("GnuPG not found"),
tr("Please install GnuPG on your system.<br>Install <strong>gpg</strong> using your favorite package manager<br>or <a href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it from GnuPG.org"));
@@ -375,6 +376,8 @@ void Dialog::wizard()
QMessageBox::critical(this, tr("Secret key not found"),
tr("You can not encrypt :("));
// TODO have usable gpg id wizrd :P
+ KeygenDialog d(this);
+ d.exec();
}
QString passStore = ui->storePath->text();
@@ -387,5 +390,5 @@ void Dialog::wizard()
// Can you use the store?
- ui->gpgPath->setText(gpg);
+ //ui->gpgPath->setText(gpg);
}
diff --git a/keygendialog.cpp b/keygendialog.cpp
new file mode 100644
index 00000000..5788cafa
--- /dev/null
+++ b/keygendialog.cpp
@@ -0,0 +1,66 @@
+#include "keygendialog.h"
+#include "ui_keygendialog.h"
+#include <QDebug>
+
+KeygenDialog::KeygenDialog(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::KeygenDialog)
+{
+ ui->setupUi(this);
+}
+
+KeygenDialog::~KeygenDialog()
+{
+ delete ui;
+}
+
+void KeygenDialog::on_passphrase1_textChanged(const QString &arg1)
+{
+ if (ui->passphrase1->text() == ui->passphrase2->text()) {
+ ui->buttonBox->setEnabled(true);
+ replace("Passphrase", arg1);
+ } else {
+ ui->buttonBox->setEnabled(false);
+ }
+}
+
+void KeygenDialog::on_passphrase2_textChanged(const QString &arg1)
+{
+ on_passphrase1_textChanged(arg1);
+}
+
+void KeygenDialog::on_checkBox_stateChanged(int arg1)
+{
+ if (arg1) {
+ ui->plainTextEdit->setReadOnly(false);
+ } else {
+ ui->plainTextEdit->setReadOnly(true);
+ }
+}
+
+void KeygenDialog::on_email_textChanged(const QString &arg1)
+{
+ replace("Name-Email", arg1);
+}
+
+void KeygenDialog::on_name_textChanged(const QString &arg1)
+{
+ replace("Name-Real", arg1);
+}
+
+/**
+ * @brief KeygenDialog::replace
+ * @param key
+ * @param value
+ */
+void KeygenDialog::replace(QString key, QString value)
+{
+ QStringList clear;
+ QString expert = ui->plainTextEdit->toPlainText();
+ QStringList lines = expert.split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
+ foreach (QString line, lines) {
+ line.replace(QRegExp(key+":.*"), key + ": " + value);
+ clear.append(line);
+ }
+ ui->plainTextEdit->setPlainText(clear.join("\n"));
+}
diff --git a/keygendialog.h b/keygendialog.h
new file mode 100644
index 00000000..634bcbe3
--- /dev/null
+++ b/keygendialog.h
@@ -0,0 +1,34 @@
+#ifndef KEYGENDIALOG_H
+#define KEYGENDIALOG_H
+
+#include <QDialog>
+
+namespace Ui {
+class KeygenDialog;
+}
+
+class KeygenDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit KeygenDialog(QWidget *parent = 0);
+ ~KeygenDialog();
+
+private slots:
+ void on_passphrase1_textChanged(const QString &arg1);
+
+ void on_passphrase2_textChanged(const QString &arg1);
+
+ void on_checkBox_stateChanged(int arg1);
+
+ void on_email_textChanged(const QString &arg1);
+
+ void on_name_textChanged(const QString &arg1);
+
+private:
+ Ui::KeygenDialog *ui;
+ void replace(QString, QString);
+};
+
+#endif // KEYGENDIALOG_H
diff --git a/keygendialog.ui b/keygendialog.ui
new file mode 100644
index 00000000..6ec8765e
--- /dev/null
+++ b/keygendialog.ui
@@ -0,0 +1,173 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>KeygenDialog</class>
+ <widget class="QDialog" name="KeygenDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>606</width>
+ <height>457</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Generate GnuPG keypair</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Generate a new key pair</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QWidget" name="widget" native="true">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="1" column="0" colspan="2">
+ <widget class="QLabel" name="labelPassphrase">
+ <property name="text">
+ <string>Passphrase</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="labelEmail">
+ <property name="text">
+ <string>Email</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2" colspan="3">
+ <widget class="QLineEdit" name="passphrase2">
+ <property name="echoMode">
+ <enum>QLineEdit::Password</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" colspan="2">
+ <widget class="QLineEdit" name="email"/>
+ </item>
+ <item row="0" column="3">
+ <widget class="QLabel" name="labelName">
+ <property name="text">
+ <string>Name</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2" colspan="3">
+ <widget class="QLineEdit" name="passphrase1">
+ <property name="echoMode">
+ <enum>QLineEdit::Password</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="4">
+ <widget class="QLineEdit" name="name"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="labelPassphraseInfo">
+ <property name="text">
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;There is no limit on the length of a passphrase, and it should be carefully chosen. From the perspective of security, the passphrase to unlock the private key is one of the weakest points in GnuPG (and other public-key encryption systems as well) since it is the only protection you have if another individual gets your private key. &lt;br/&gt;Ideally, the passphrase should not use words from a dictionary and should mix the case of alphabetic characters as well as use non-alphabetic characters.&lt;br/&gt;A good passphrase is crucial to the secure use of GnuPG.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="checkBox">
+ <property name="text">
+ <string>Expert</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPlainTextEdit" name="plainTextEdit">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ <property name="plainText">
+ <string># QtPass GPG key generator
+#
+# first test version please comment
+# or email to qtpass@ijhack.org
+%echo Generating a default key
+Key-Type: default
+Subkey-Type: default
+Name-Real:
+Name-Comment: QtPass
+Name-Email:
+Expire-Date: 0
+Passphrase:
+%pubring foo.pub
+%secring foo.sec
+# Do a commit here, so that we can later print &quot;done&quot; :-)
+%commit
+%echo done</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <tabstops>
+ <tabstop>name</tabstop>
+ <tabstop>email</tabstop>
+ <tabstop>passphrase1</tabstop>
+ <tabstop>passphrase2</tabstop>
+ </tabstops>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>KeygenDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>KeygenDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/qtpass.pro b/qtpass.pro
index 7d05eab8..0d475cf9 100644
--- a/qtpass.pro
+++ b/qtpass.pro
@@ -27,18 +27,21 @@ SOURCES += main.cpp\
dialog.cpp \
storemodel.cpp \
util.cpp \
- usersdialog.cpp
+ usersdialog.cpp \
+ keygendialog.cpp
HEADERS += mainwindow.h \
dialog.h \
storemodel.h \
util.h \
usersdialog.h \
- wizarddialog.h
+ wizarddialog.h \
+ keygendialog.h
FORMS += mainwindow.ui \
dialog.ui \
- usersdialog.ui
+ usersdialog.ui \
+ keygendialog.ui
*-g++* {
QMAKE_CXXFLAGS += -std=c++11