Skip to content

Commit

Permalink
Added menu action to export all logins as a tab-separated clear text …
Browse files Browse the repository at this point in the history
…file.
  • Loading branch information
607011 committed Jan 14, 2016
1 parent aa7e44d commit c8ce171
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 13 deletions.
84 changes: 83 additions & 1 deletion Qt-SESAM/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
#include <QLockFile>
#include <QPainter>
#include <QPixmap>
#include <QFutureWatcher>
#include <QtConcurrent>

#include "global.h"
#include "util.h"
Expand Down Expand Up @@ -323,6 +325,7 @@ MainWindow::MainWindow(bool forceStart, QWidget *parent)
QObject::connect(ui->actionAbout, SIGNAL(triggered(bool)), SLOT(about()));
QObject::connect(ui->actionAboutQt, SIGNAL(triggered(bool)), SLOT(aboutQt()));
QObject::connect(ui->actionOptions, SIGNAL(triggered(bool)), SLOT(showOptionsDialog()));
QObject::connect(ui->actionExportAllLoginDataAsClearText, SIGNAL(triggered(bool)), SLOT(onExportAllLoginDataAsClearText()));
QObject::connect(ui->actionExportCurrentSettingsAsQRCode, SIGNAL(triggered(bool)), SLOT(onExportCurrentSettingsAsQRCode()));
QObject::connect(ui->actionExportKGK, SIGNAL(triggered(bool)), SLOT(onExportKGK()));
QObject::connect(ui->actionImportKGK, SIGNAL(triggered(bool)), SLOT(onImportKGK()));
Expand Down Expand Up @@ -2392,7 +2395,86 @@ void MainWindow::onEasySelectorValuesChanged(int length, int complexity)
}


QImage MainWindow::currentDomainSettings2QRCode(void)
struct LoginToTextConverter
{
LoginToTextConverter(const SecureByteArray &kgk)
: KGK(kgk)
{ /* ... */ }
typedef SecureByteArray result_type;
SecureByteArray KGK;
SecureByteArray operator()(const DomainSettings &ds)
{
SecureString pwd = ds.legacyPassword;
if (pwd.isEmpty()) {
Password gpwd(ds);
gpwd.generate(KGK);
pwd = gpwd();
}
SecureByteArray data = pwd.isEmpty()
? SecureByteArray()
: SecureString("%1\t%2\t%3\t%4")
.arg(ds.domainName)
.arg(ds.url)
.arg(ds.userName)
.arg(pwd)
.toUtf8();
return data;
}
};


void concat(SecureByteArray &all, const SecureByteArray &intermediate)
{
if (!intermediate.isEmpty()) {
all.append(intermediate).append("\n");
}
}


static const QString LoginDataFileExtension = QObject::tr("Login data file (*.csv)");

void MainWindow::onExportAllLoginDataAsClearText(void)
{
Q_D(MainWindow);
QString filename =
QFileDialog::getSaveFileName(this,
tr("Export all login data as clear text"),
QString(),
LoginDataFileExtension);
if (!filename.isEmpty()) {
QProgressDialog progressDialog(this);
progressDialog.setLabelText(tr("Exporting logins\nin %1 thread%2 ...")
.arg(QThread::idealThreadCount())
.arg(QThread::idealThreadCount() == 1 ? "" : tr("s")));
progressDialog.setCancelButtonText(tr("Cancel"));
QFutureWatcher<SecureByteArray> futureWatcher;
QObject::connect(&futureWatcher, SIGNAL(finished()), &progressDialog, SLOT(reset()));
QObject::connect(&progressDialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel()));
QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int, int)), &progressDialog, SLOT(setRange(int, int)));
QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &progressDialog, SLOT(setValue(int)));
QFuture<SecureByteArray> future = QtConcurrent::mappedReduced(
d->domains,
LoginToTextConverter(d->KGK),
concat,
QtConcurrent::OrderedReduce);
futureWatcher.setFuture(future);
progressDialog.show();
progressDialog.exec();
futureWatcher.waitForFinished();
if (!futureWatcher.future().isCanceled()) {
QFile outFile(filename);
bool ok = outFile.open(QIODevice::Truncate | QIODevice::WriteOnly);
if (ok) {
outFile.write("Domain\tURL\tUsername\tPassword\n");
outFile.write(future.result());
outFile.close();
}
}
}
}


QImage MainWindow::currentDomainSettings2QRCode(void) const
{
static const int ModuleSize = 10;
static const int Margin = ModuleSize;
Expand Down
5 changes: 4 additions & 1 deletion Qt-SESAM/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@
#include <QLabel>
#include <QJsonDocument>
#include <QImage>
#include <QProgressDialog>

#include "global.h"
#include "domainsettings.h"
#include "domainsettingslist.h"
#include "pbkdf2.h"
#include "securebytearray.h"

namespace Ui {
class MainWindow;
Expand Down Expand Up @@ -101,6 +103,7 @@ private slots:
void onDomainTextChanged(const QString &);
void onDomainSelected(QString);
void onEasySelectorValuesChanged(int, int);
void onExportAllLoginDataAsClearText(void);
void onExportCurrentSettingsAsQRCode(void);
void onPasswordTemplateChanged(const QString &);
void masterPasswordInvalidationTimeMinsChanged(int);
Expand Down Expand Up @@ -213,7 +216,7 @@ private slots:
void cleanupAfterMasterPasswordChanged(void);
void prepareExit(void);
void removeOutdatedBackupFilesThread(void);
QImage currentDomainSettings2QRCode(void);
QImage currentDomainSettings2QRCode(void) const;
};

#endif // __MAINWINDOW_H_
30 changes: 24 additions & 6 deletions Qt-SESAM/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -868,15 +868,28 @@
<property name="title">
<string>Expert actions</string>
</property>
<widget class="QMenu" name="menuExport">
<property name="title">
<string>Export</string>
</property>
<addaction name="actionExportKGK"/>
<addaction name="actionExportCurrentSettingsAsQRCode"/>
<addaction name="actionExportAllLoginDataAsClearText"/>
</widget>
<widget class="QMenu" name="menuImport_2">
<property name="title">
<string>Import</string>
</property>
<addaction name="actionImportKGK"/>
</widget>
<addaction name="actionHackLegacyPassword"/>
<addaction name="actionRegenerateSaltKeyIV"/>
<addaction name="actionClearAllSettings"/>
<addaction name="actionForcedPush"/>
<addaction name="actionMigrateDomainToV3"/>
<addaction name="separator"/>
<addaction name="actionExportCurrentSettingsAsQRCode"/>
<addaction name="actionExportKGK"/>
<addaction name="actionImportKGK"/>
<addaction name="menuImport_2"/>
<addaction name="menuExport"/>
<addaction name="separator"/>
<addaction name="actionDeleteOldBackupFiles"/>
</widget>
Expand Down Expand Up @@ -1024,12 +1037,12 @@
</action>
<action name="actionExportKGK">
<property name="text">
<string>Export KGK ...</string>
<string>KGK ...</string>
</property>
</action>
<action name="actionImportKGK">
<property name="text">
<string>Import KGK ...</string>
<string>KGK ...</string>
</property>
</action>
<action name="actionKeePassXmlFile">
Expand All @@ -1053,7 +1066,12 @@
</action>
<action name="actionExportCurrentSettingsAsQRCode">
<property name="text">
<string>Export current settings as QR code ...</string>
<string>Current domain settings as QR code ...</string>
</property>
</action>
<action name="actionExportAllLoginDataAsClearText">
<property name="text">
<string>All login data as clear text ...</string>
</property>
</action>
</widget>
Expand Down
44 changes: 39 additions & 5 deletions Qt-SESAM/translations/QtSESAM_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ auf deinem Computer: %3</translation>
</message>
<message>
<source>Cancel</source>
<translation type="vanished">Abbrechen</translation>
<translation>Abbrechen</translation>
</message>
<message>
<source>SHA512 hash (hex)</source>
Expand Down Expand Up @@ -726,15 +726,15 @@ auf deinem Computer: %3</translation>
</message>
<message>
<source>Export KGK ...</source>
<translation>KGK exportieren ...</translation>
<translation type="vanished">KGK exportieren ...</translation>
</message>
<message>
<source>Security hint</source>
<translation>Sicherheitshinweis</translation>
</message>
<message>
<source>Import KGK ...</source>
<translation>KGK importieren ...</translation>
<translation type="vanished">KGK importieren ...</translation>
</message>
<message>
<source>Export KGK to ...</source>
Expand Down Expand Up @@ -1090,7 +1090,7 @@ auf deinem Computer: %3</translation>
</message>
<message>
<source>Export</source>
<translation type="vanished">Exportieren</translation>
<translation>Exportieren</translation>
</message>
<message>
<source>Current settings as QR code ...</source>
Expand Down Expand Up @@ -1120,7 +1120,33 @@ auf deinem Computer: %3</translation>
</message>
<message>
<source>Export current settings as QR code ...</source>
<translation>Aktuelle Domain-Einstellungen als QR-Code exportieren ...</translation>
<translation type="vanished">Aktuelle Domain-Einstellungen als QR-Code exportieren ...</translation>
</message>
<message>
<source>KGK ...</source>
<translation>KGK ...</translation>
</message>
<message>
<source>Current domain settings as QR code ...</source>
<translation>Aktuelle Domain-Daten als QR-Code ...</translation>
</message>
<message>
<source>All login data as clear text ...</source>
<translation>All Logins im Klartext ...</translation>
</message>
<message>
<source>Export all login data as clear text</source>
<translation>All Login-Daten im Klartext exportieren</translation>
</message>
<message>
<source>Exporting logins
in %1 thread%2 ...</source>
<translation>Exportieren der Logins
in %1 Thread%2 ...</translation>
</message>
<message>
<source>s</source>
<translation>s</translation>
</message>
</context>
<context>
Expand Down Expand Up @@ -1758,6 +1784,14 @@ auf deinem Computer: %3</translation>
<source>QR code file (*.png)</source>
<translation>QR-Code-Datei (*.png)</translation>
</message>
<message>
<source>Login data file (*.csv *.sesam)</source>
<translation type="vanished">Login-Daten (*.csv *.sesam)</translation>
</message>
<message>
<source>Login data file (*.csv)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ServerCertificateWidget</name>
Expand Down

0 comments on commit c8ce171

Please sign in to comment.