aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt6
-rw-r--r--src/gpg/CMakeLists.txt8
-rw-r--r--src/gpg/GpgContext.cpp36
-rw-r--r--src/main.cpp2
-rw-r--r--src/ui/CMakeLists.txt3
-rw-r--r--src/ui/KeygenDialog.cpp59
-rw-r--r--src/ui/KeygenThread.cpp2
7 files changed, 67 insertions, 49 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d65c791a..ada40b82 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -6,6 +6,8 @@ aux_source_directory(. BASE_SOURCE)
file(GLOB_RECURSE GPG4USB_HEADER_FILES RELACTIVE ../include/* *.h)
qt5_wrap_cpp(QT5_MOCS ${GPG4USB_HEADER_FILES} TARGET gpg4usb)
-add_executable(gpg4usb ${BASE_SOURCE} ../gpg4usb.qrc ${QT5_MOCS})
+add_executable(gpg4usb ${BASE_SOURCE} ../gpg4usb.qrc ${QT5_MOCS} ../include/gpg/GpgGenKeyInfo.h)
-target_link_libraries(gpg4usb qtui gpg Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core) \ No newline at end of file
+target_link_libraries(gpg4usb
+ qtui gpg
+ Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core) \ No newline at end of file
diff --git a/src/gpg/CMakeLists.txt b/src/gpg/CMakeLists.txt
index 881cd7d4..7e3df7de 100644
--- a/src/gpg/CMakeLists.txt
+++ b/src/gpg/CMakeLists.txt
@@ -2,6 +2,10 @@ aux_source_directory(. GPG_SOURCE)
add_library(gpg STATIC ${GPG_SOURCE})
-target_link_libraries(gpg gpg-error gpgme)
+set(UTILS_DIR ${CMAKE_SOURCE_DIR}/utils)
-qt5_use_modules(gpg Network PrintSupport Widgets Test Core) \ No newline at end of file
+set(GPGME_LIB_DIR ${UTILS_DIR}/gpgme/lib)
+
+target_link_libraries(gpg
+ ${GPGME_LIB_DIR}/libgpgme.a ${GPGME_LIB_DIR}/libgpg-error.a ${GPGME_LIB_DIR}/libassuan.a
+ Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core) \ No newline at end of file
diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp
index d0694638..a42861a6 100644
--- a/src/gpg/GpgContext.cpp
+++ b/src/gpg/GpgContext.cpp
@@ -56,8 +56,8 @@ namespace GpgME {
#endif
err = gpgme_new(&mCtx);
-
checkErr(err);
+
/** here come the qSettings, instead of /usr/bin/gpg
* a executable in the same path as app is used.
* also lin/win must be checked, for calling gpg.exe if needed
@@ -65,7 +65,7 @@ namespace GpgME {
#ifdef _WIN32
gpgBin = appPath + "/bin/gpg.exe";
#else
- gpgBin = appPath + "/bin/gpg";
+ gpgBin = "/usr/bin/gpg";
#endif
QSettings qSettings;
@@ -195,8 +195,33 @@ namespace GpgME {
/** Generate New Key with values params
*
*/
- void GpgContext::generateKey(QString *params) {
- err = gpgme_op_genkey(mCtx, params->toUtf8().data(), nullptr, nullptr);
+ void GpgContext::generateKey(GenKeyInfo *params) {
+ auto userid_utf8 = params->userid.toUtf8();
+ const char *userid = userid_utf8.constData();
+ auto algo_utf8 = (params->algo + QString::number(params->keySize)).toUtf8();
+ const char *algo = algo_utf8.constData();
+ unsigned long expires = params->expired.toTime_t();
+ unsigned int flags = 0;
+
+ if(!params->isSubKey) {
+ flags |= GPGME_CREATE_CERT;
+ flags |= GPGME_CREATE_ENCR;
+ } else {
+ if(params->allowEncryption) {
+ flags |= GPGME_CREATE_ENCR;
+ }
+ }
+
+ if(params->allowSigning) {
+ flags |= GPGME_CREATE_SIGN;
+ }
+
+ if(params->nonExpired) {
+ flags |= GPGME_CREATE_NOEXPIRE;
+ }
+
+ err = gpgme_op_createkey(mCtx, userid, algo, 0, expires, nullptr, flags);
+
checkErr(err);
emit signalKeyDBChanged();
}
@@ -547,7 +572,8 @@ namespace GpgME {
void GpgContext::checkErr(gpgme_error_t gpgmeError) {
//if (gpgmeError != GPG_ERR_NO_ERROR && gpgmeError != GPG_ERR_CANCELED) {
if (gpgmeError != GPG_ERR_NO_ERROR) {
- qDebug() << "[Error] Source: " << gpgme_strsource(gpgmeError) << " String: " << gpgErrString(gpgmeError);
+ qDebug() << "[Error "<< gpg_err_code(gpgmeError)
+ <<"] Source: " << gpgme_strsource(gpgmeError) << " Description: " << gpgErrString(gpgmeError);
}
}
diff --git a/src/main.cpp b/src/main.cpp
index 6ee3ccf5..c1826380 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -30,7 +30,7 @@ int main(int argc, char *argv[]) {
// get application path
QString appPath = qApp->applicationDirPath();
- QApplication::setApplicationVersion("0.3.3");
+ QApplication::setApplicationVersion("1.0.0");
QApplication::setApplicationName("gpg4usb");
// dont show icons in menus
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index a9782fcc..8398740b 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -2,4 +2,5 @@ aux_source_directory(. QTUI_SOURCE)
add_library(qtui STATIC ${QTUI_SOURCE})
-qt5_use_modules(qtui Network PrintSupport Widgets Test Core) \ No newline at end of file
+target_link_libraries(qtui
+ Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core) \ No newline at end of file
diff --git a/src/ui/KeygenDialog.cpp b/src/ui/KeygenDialog.cpp
index 762acd52..5f29836f 100644
--- a/src/ui/KeygenDialog.cpp
+++ b/src/ui/KeygenDialog.cpp
@@ -40,13 +40,16 @@ void KeyGenDialog::generateKeyDialog() {
keySizeSpinBox = new QSpinBox(this);
keySizeSpinBox->setRange(1024, 4096);
- keySizeSpinBox->setValue(2048);
+ keySizeSpinBox->setValue(3072);
keySizeSpinBox->setSingleStep(1024);
keyTypeComboBox = new QComboBox(this);
keyTypeComboBox->addItem("RSA");
- keyTypeComboBox->addItem("DSA/Elgamal");
+ keyTypeComboBox->addItem("DSA");
+ keyTypeComboBox->addItem("ELG");
+ keyTypeComboBox->addItem("ED25519");
+ keyTypeComboBox->addItem("CV25519");
keyTypeComboBox->setCurrentIndex(0);
dateEdit = new QDateEdit(QDate::currentDate().addYears(5), this);
dateEdit->setMinimumDate(QDate::currentDate());
@@ -73,7 +76,7 @@ void KeyGenDialog::generateKeyDialog() {
auto *vbox1 = new QGridLayout;
vbox1->addWidget(new QLabel(tr("Name:")), 0, 0);
- vbox1->addWidget(new QLabel(tr("E-Mailaddress:")), 1, 0);
+ vbox1->addWidget(new QLabel(tr("E-Mail:")), 1, 0);
vbox1->addWidget(new QLabel(tr("Comment:")), 2, 0);
vbox1->addWidget(new QLabel(tr("Expiration Date:")), 3, 0);
vbox1->addWidget(new QLabel(tr("Never Expire")), 3, 3);
@@ -114,12 +117,16 @@ void KeyGenDialog::generateKeyDialog() {
void KeyGenDialog::slotKeyGenAccept() {
QString errorString = "";
- QString keyGenParams;
+
+ GenKeyInfo genKeyInfo;
+
/**
* check for errors in keygen dialog input
*/
if ((nameEdit->text()).size() < 5) {
errorString.append(tr(" Name must contain at least five characters. \n"));
+ } if(emailEdit->text().isEmpty()) {
+ errorString.append(tr(" Please give a email address. \n"));
}
if (passwordEdit->text() != repeatpwEdit->text()) {
errorString.append(tr(" Password and Repeat don't match. "));
@@ -130,44 +137,22 @@ void KeyGenDialog::slotKeyGenAccept() {
* create the string for key generation
*/
- if (keyTypeComboBox->currentText() == "RSA") {
- keyGenParams = "<GnupgKeyParms format=\"internal\">\n"
- "Key-Type: RSA\n"
- "Key-Usage: sign\n"
- "Key-Length: " + keySizeSpinBox->cleanText() + "\n"
- "Subkey-Type: RSA\n"
- "Subkey-Length: " +
- keySizeSpinBox->cleanText() + "\n"
- "Subkey-Usage: encrypt\n";
- } else {
- keyGenParams = "<GnupgKeyParms format=\"internal\">\n"
- "Key-Type: DSA\n"
- "Key-Length: " + keySizeSpinBox->cleanText() + "\n"
- "Subkey-Type: ELG-E\n"
- "Subkey-Length: " +
- keySizeSpinBox->cleanText() + "\n";
- }
+ genKeyInfo.userid = QString("%1 <%2>").arg(nameEdit->text(), emailEdit->text());
+
+ genKeyInfo.algo = keyTypeComboBox->currentText().toLower();
+
+ genKeyInfo.keySize = keySizeSpinBox->value();
+
+ genKeyInfo.passPhrase = passwordEdit->text();
- keyGenParams += "Name-Real: " + nameEdit->text().toUtf8() + "\n";
- if (!(commentEdit->text().isEmpty())) {
- keyGenParams += "Name-Comment: " + commentEdit->text().toUtf8() + "\n";
- }
- if (!(emailEdit->text().isEmpty())) {
- keyGenParams += "Name-Email: " + emailEdit->text().toUtf8() + "\n";
- }
if (expireCheckBox->checkState()) {
- keyGenParams += "Expire-Date: 0\n";
+ genKeyInfo.nonExpired = true;
+ genKeyInfo.expired = QDateTime(QDateTime::fromTime_t(0));
} else {
- keyGenParams += "Expire-Date: " + dateEdit->sectionText(QDateTimeEdit::YearSection) + "-" +
- dateEdit->sectionText(QDateTimeEdit::MonthSection) + "-" +
- dateEdit->sectionText(QDateTimeEdit::DaySection) + "\n";
- }
- if (!(passwordEdit->text().isEmpty())) {
- keyGenParams += "Passphrase: " + passwordEdit->text() + "\n";
+ genKeyInfo.expired = dateEdit->dateTime();
}
- keyGenParams += "</GnupgKeyParms>";
- auto *kg = new KeyGenThread(keyGenParams, mCtx);
+ auto *kg = new KeyGenThread(genKeyInfo, mCtx);
kg->start();
this->accept();
diff --git a/src/ui/KeygenThread.cpp b/src/ui/KeygenThread.cpp
index 2bb21eca..cd564c42 100644
--- a/src/ui/KeygenThread.cpp
+++ b/src/ui/KeygenThread.cpp
@@ -23,7 +23,7 @@
#include <utility>
-KeyGenThread::KeyGenThread(QString keyGenParams, GpgME::GpgContext *ctx) {
+KeyGenThread::KeyGenThread(GenKeyInfo keyGenParams, GpgME::GpgContext *ctx) {
this->keyGenParams = std::move(keyGenParams);
this->mCtx = ctx;
abort = false;