diff options
author | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2010-01-31 22:28:06 +0000 |
---|---|---|
committer | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2010-01-31 22:28:06 +0000 |
commit | 4a7b0cb82ed39a2d26ee086451991b6e0638c33c (patch) | |
tree | 8451fc0371eee428a43cf3a73e5d91b353d83e36 | |
parent | recognize secret keys for keydetailsdialog (diff) | |
download | gpg4usb-4a7b0cb82ed39a2d26ee086451991b6e0638c33c.tar.gz gpg4usb-4a7b0cb82ed39a2d26ee086451991b6e0638c33c.zip |
export private key functionality
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@258 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r-- | keydetailsdialog.cpp | 53 | ||||
-rw-r--r-- | keydetailsdialog.h | 32 | ||||
-rwxr-xr-x | keymgmt.cpp | 2 |
3 files changed, 57 insertions, 30 deletions
diff --git a/keydetailsdialog.cpp b/keydetailsdialog.cpp index 6fbcc98..3d96318 100644 --- a/keydetailsdialog.cpp +++ b/keydetailsdialog.cpp @@ -20,10 +20,12 @@ */ #include "keydetailsdialog.h" -#include "QPushButton" -#include "QDebug" +//#include "QDebug" -KeyDetailsDialog::KeyDetailsDialog(gpgme_key_t key) { +KeyDetailsDialog::KeyDetailsDialog(GpgME::Context* ctx, gpgme_key_t key) { + + mCtx = ctx; + keyid = new QString(key->subkeys->keyid); setWindowTitle(tr("Key Properties")); resize(500, 200); @@ -118,6 +120,7 @@ KeyDetailsDialog::KeyDetailsDialog(gpgme_key_t key) { QPushButton *exportButton = new QPushButton(tr("Export Private Key")); vboxPK->addWidget(exportButton); + connect(exportButton, SIGNAL(clicked()), this, SLOT(exportPrivateKey())); privKeyBox->setLayout(vboxPK); mvbox->addWidget(privKeyBox); @@ -128,27 +131,35 @@ KeyDetailsDialog::KeyDetailsDialog(gpgme_key_t key) { this->setLayout(mvbox); this->setWindowTitle(tr("Keydatails")); this->show(); -/* - qDebug() << "is secret: " << key ->secret; - qDebug() << "can encrypt: " <<key ->can_encrypt; - qDebug() << "can sign: " <<key ->can_sign; - qDebug() << "can encrypt: " <<key ->can_encrypt; - qDebug() << "expires: " << key-> expired; - qDebug() << "can authenticate: " <<key ->can_authenticate; - qDebug() << "protocol: " << gpgme_get_protocol_name(key->protocol); - qDebug() << "algo: " << gpgme_pubkey_algo_name(key->subkeys->pubkey_algo); - - if( key->subkeys->next ) { - qDebug() << "next length: " << key->subkeys->next->length; - qDebug() << "next algo: " << gpgme_pubkey_algo_name(key->subkeys->next->pubkey_algo); - qDebug() << "next secret: " << key->subkeys->next->secret; - } else { - qDebug() << "no second key"; - } -*/ + exec(); } +void KeyDetailsDialog::exportPrivateKey() { + + int ret = QMessageBox::information(this, tr("Exporting private Key"), + tr("You are about to export your private key.\n" + "This is NOT your public key, so don't give it away.\n" + "Make sure you keep it save."), + QMessageBox::Cancel | QMessageBox::Ok); + + if(ret==QMessageBox::Ok) { + + QByteArray *keyArray = new QByteArray(); + mCtx->exportSecretKey(*keyid, keyArray); + + QString fileName = QFileDialog::getSaveFileName(this, tr("Export Key To File"), "", tr("Key Files") + " (*.asc *.txt);;All Files (*)"); + QFile file(fileName); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + return; + QTextStream stream(&file); + stream << *keyArray; + file.close(); + delete keyArray; + } + +} + QString KeyDetailsDialog::beautifyFingerprint(QString fingerprint) { uint len = fingerprint.length(); if((len>0) && (len%4 == 0)) diff --git a/keydetailsdialog.h b/keydetailsdialog.h index d93fade..cb452db 100644 --- a/keydetailsdialog.h +++ b/keydetailsdialog.h @@ -19,13 +19,19 @@ * MA 02110-1301, USA. */ -#include "QDateTime" -#include "QVBoxLayout" -#include "QDialogButtonBox" -#include "QDialog" -#include "QGroupBox" -#include "QLabel" -#include "QGridLayout" +#ifndef __KEYDETAILSDIALOG_H__ +#define __KEYDETAILSDIALOG_H__ + +class QDateTime; +class QVBoxLayout; +class QDialogButtonBox; +class QDialog; +class QGroupBox; +class QLabel; +class QGridLayout; +class QPushButton; + +#include "context.h" #include <gpgme.h> @@ -34,9 +40,15 @@ class KeyDetailsDialog : public QDialog Q_OBJECT public: - KeyDetailsDialog(gpgme_key_t key); + KeyDetailsDialog(GpgME::Context* ctx, gpgme_key_t key); + +private slots: + void exportPrivateKey(); private: + QString *keyid; + GpgME::Context *mCtx; + QGroupBox *ownerBox; QGroupBox *keyBox; QGroupBox *fingerprintBox; @@ -63,5 +75,9 @@ private: QLabel *expireVarLabel; QLabel *createdVarLabel; QLabel *algorithmVarLabel; + + QString beautifyFingerprint(QString fingerprint); }; + +#endif // __KEYDETAILSDIALOG_H__ diff --git a/keymgmt.cpp b/keymgmt.cpp index 3130a4a..a5e8eac 100755 --- a/keymgmt.cpp +++ b/keymgmt.cpp @@ -176,7 +176,7 @@ void KeyMgmt::showKeyDetails() // TODO: first...? gpgme_key_t key = mCtx->getKeyDetails(mKeyList->getSelected()->first()); - new KeyDetailsDialog(key); + new KeyDetailsDialog(mCtx, key); } void KeyMgmt::exportKeyToFile() |