Skip to content

Commit

Permalink
prevent klipper from storing password in clipboard history
Browse files Browse the repository at this point in the history
  • Loading branch information
TheZ3ro committed May 16, 2018
1 parent e5e6e8c commit 9f244eb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
31 changes: 26 additions & 5 deletions src/gui/Clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <QApplication>
#include <QClipboard>
#include <QMimeData>
#include <QTimer>

#include "core/Config.h"
Expand All @@ -42,19 +43,34 @@ Clipboard::Clipboard(QObject* parent)
connect(qApp, SIGNAL(aboutToQuit()), SLOT(clearCopiedText()));
}

void Clipboard::setText(const QString& text)
void Clipboard::setText(const QString& text, bool secret)
{
QClipboard* clipboard = QApplication::clipboard();

#ifdef Q_OS_MAC
QMimeData* mime = new QMimeData;
#ifdef Q_OS_MAC
mime->setText(text);
mime->setData("application/x-nspasteboard-concealed-type", text.toUtf8());
clipboard->setMimeData(mime, QClipboard::Clipboard);
#else
clipboard->setText(text, QClipboard::Clipboard);
if (clipboard->supportsSelection()) {
clipboard->setText(text, QClipboard::Selection);
if (secret) {
const QString secretStr = "secret";
QByteArray secretBa = secretStr.toUtf8();
mime->setText(text);
mime->setData("x-kde-passwordManagerHint", secretBa);
clipboard->setMimeData(mime, QClipboard::Clipboard);

if (clipboard->supportsSelection()) {
QMimeData* mimeSelection = new QMimeData();
mimeSelection->setText(text);
mimeSelection->setData("x-kde-passwordManagerHint", secretBa);
clipboard->setMimeData(mimeSelection, QClipboard::Selection);
}
} else {
clipboard->setText(text, QClipboard::Clipboard);
if (clipboard->supportsSelection()) {
clipboard->setText(text, QClipboard::Selection);
}
}
#endif

Expand All @@ -67,6 +83,11 @@ void Clipboard::setText(const QString& text)
}
}

void Clipboard::setSecretText(const QString& text)
{
setText(text, true);
}

void Clipboard::clearCopiedText()
{
if (m_timer->isActive()) {
Expand Down
3 changes: 2 additions & 1 deletion src/gui/Clipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class Clipboard : public QObject
Q_OBJECT

public:
void setText(const QString& text);
void setText(const QString& text, bool secret = false);
void setSecretText(const QString& text);

static Clipboard* instance();

Expand Down
12 changes: 10 additions & 2 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ void DatabaseWidget::copyPassword()
return;
}

setClipboardTextAndMinimize(currentEntry->resolveMultiplePlaceholders(currentEntry->password()));
setClipboardSecretTextAndMinimize(currentEntry->resolveMultiplePlaceholders(currentEntry->password()));
}

void DatabaseWidget::copyURL()
Expand Down Expand Up @@ -593,6 +593,14 @@ void DatabaseWidget::setClipboardTextAndMinimize(const QString& text)
}
}

void DatabaseWidget::setClipboardSecretTextAndMinimize(const QString& text)
{
clipboard()->setSecretText(text);
if (config()->get("MinimizeOnCopy").toBool()) {
window()->showMinimized();
}
}

void DatabaseWidget::performAutoType()
{
Entry* currentEntry = m_entryView->currentEntry();
Expand Down Expand Up @@ -933,7 +941,7 @@ void DatabaseWidget::entryActivationSignalReceived(Entry* entry, EntryModel::Mod
setClipboardTextAndMinimize(entry->resolveMultiplePlaceholders(entry->username()));
break;
case EntryModel::Password:
setClipboardTextAndMinimize(entry->resolveMultiplePlaceholders(entry->password()));
setClipboardSecretTextAndMinimize(entry->resolveMultiplePlaceholders(entry->password()));
break;
case EntryModel::Url:
if (!entry->url().isEmpty()) {
Expand Down
1 change: 1 addition & 0 deletions src/gui/DatabaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ private slots:

private:
void setClipboardTextAndMinimize(const QString& text);
void setClipboardSecretTextAndMinimize(const QString& text);
void setIconFromParent();
void replaceDatabase(Database* db);

Expand Down

0 comments on commit 9f244eb

Please sign in to comment.