From 76a26e010b1ee7297a3f0b9548682780830e567d Mon Sep 17 00:00:00 2001 From: msmol Date: Sun, 4 Jun 2017 20:43:21 -0400 Subject: [PATCH 1/7] Added support for pass-otp Convention: otp passwords must have the string "totp-" either in the filename or the file path. If the convention is followed, "pass otp" is called instead of "pass", so that the totp token is copied to clipboard rather than the raw otpauth:// URI. --- pass.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pass.cpp b/pass.cpp index b1fb357..c597853 100644 --- a/pass.cpp +++ b/pass.cpp @@ -125,7 +125,9 @@ void Pass::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &m { Q_UNUSED(context); - auto ret = QProcess::execute(QString("pass -c ") + match.text()); + auto ret = match.text().contains("totp-", Qt::CaseInsensitive) ? + QProcess::execute(QString("pass otp -c ") + match.text()) : + QProcess::execute(QString("pass -c ") + match.text()); if (ret == 0) { QString msg = i18n("Password %1 copied to clipboard for %2 seconds", match.text(), timeout); KNotification::event("password-unlocked", "Pass", msg, From a468f0bebce650a21bc07bbe882b2ca7a158d7b9 Mon Sep 17 00:00:00 2001 From: msmol Date: Mon, 5 Jun 2017 10:16:27 -0400 Subject: [PATCH 2/7] Make the pass otp identifier an environment variable --- pass.cpp | 8 +++++++- pass.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pass.cpp b/pass.cpp index c597853..f1d33a9 100644 --- a/pass.cpp +++ b/pass.cpp @@ -125,7 +125,13 @@ void Pass::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &m { Q_UNUSED(context); - auto ret = match.text().contains("totp-", Qt::CaseInsensitive) ? + this->passOtpIdentifier = "totp::"; + auto passOtpIdentifier = getenv("PASSWORD_STORE_OTP_IDENTIFIER"); + if (passOtpIdentifier != nullptr) { + this->passOtpIdentifier = passOtpIdentifier; + } + + auto ret = match.text().contains(this->passOtpIdentifier, Qt::CaseInsensitive) ? QProcess::execute(QString("pass otp -c ") + match.text()) : QProcess::execute(QString("pass -c ") + match.text()); if (ret == 0) { diff --git a/pass.h b/pass.h index ea641eb..34d58b5 100644 --- a/pass.h +++ b/pass.h @@ -44,6 +44,7 @@ protected: private: QDir baseDir; + QString passOtpIdentifier; int timeout; QReadWriteLock lock; QList passwords; From 455411e96250661b441628d2b9925924bf1454fd Mon Sep 17 00:00:00 2001 From: msmol Date: Mon, 5 Jun 2017 10:23:58 -0400 Subject: [PATCH 3/7] Update README with instructions on how to use with pass-otp --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index bfdbda7..20740a2 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,12 @@ Krunner pass Integrates [krunner](https://userbase.kde.org/Plasma/Krunner) with [pass](https://www.passwordstore.org). +## Use with [pass-otp](https://github.com/tadfisher/pass-otp) + +To use with pass-otp, use the identifier "totp::" in the filename or file path of the otp password file. + +Alternatively, set $PASSWORD_STORE_OTP_IDENTIFIER to overwrite the identifier string. + Build and Installation ====================== From 747b0089697c5f16f66be87894b016573f08f54d Mon Sep 17 00:00:00 2001 From: msmol Date: Mon, 5 Jun 2017 11:39:24 -0400 Subject: [PATCH 4/7] Only match as totp if any part of the path or filename BEGINS with the otp identifier --- pass.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pass.cpp b/pass.cpp index f1d33a9..73c7bac 100644 --- a/pass.cpp +++ b/pass.cpp @@ -130,8 +130,9 @@ void Pass::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &m if (passOtpIdentifier != nullptr) { this->passOtpIdentifier = passOtpIdentifier; } + auto isOtp = match.text().split('/').filter(QRegularExpression("^" + QRegularExpression::escape(this->passOtpIdentifier) + ".*")).size() > 0; - auto ret = match.text().contains(this->passOtpIdentifier, Qt::CaseInsensitive) ? + auto ret = isOtp ? QProcess::execute(QString("pass otp -c ") + match.text()) : QProcess::execute(QString("pass -c ") + match.text()); if (ret == 0) { From 188b517fdc4d99ba9f01c83fe89b0d33650bbd8f Mon Sep 17 00:00:00 2001 From: msmol Date: Mon, 5 Jun 2017 11:45:51 -0400 Subject: [PATCH 5/7] Move initializtion of totp env vars to init function Also update README with more info --- README.md | 5 +++-- pass.cpp | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 20740a2..8d3e081 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,10 @@ Integrates [krunner](https://userbase.kde.org/Plasma/Krunner) with [pass](https: ## Use with [pass-otp](https://github.com/tadfisher/pass-otp) -To use with pass-otp, use the identifier "totp::" in the filename or file path of the otp password file. +To use with pass-otp, use the identifier "totp::" as a prefix in the filename or file path of the otp password file. -Alternatively, set $PASSWORD_STORE_OTP_IDENTIFIER to overwrite the identifier string. +Alternatively, set $PASSWORD_STORE_OTP_IDENTIFIER to overwrite the identifier string. This must be set in `.xprofile` +or similar file. Build and Installation ====================== diff --git a/pass.cpp b/pass.cpp index 73c7bac..3b7013d 100644 --- a/pass.cpp +++ b/pass.cpp @@ -61,6 +61,12 @@ void Pass::init() { } } + this->passOtpIdentifier = "totp::"; + auto passOtpIdentifier = getenv("PASSWORD_STORE_OTP_IDENTIFIER"); + if (passOtpIdentifier != nullptr) { + this->passOtpIdentifier = passOtpIdentifier; + } + initPasswords(); connect(&watcher, SIGNAL(directoryChanged(QString)), this, SLOT(reinitPasswords(QString))); @@ -125,11 +131,6 @@ void Pass::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &m { Q_UNUSED(context); - this->passOtpIdentifier = "totp::"; - auto passOtpIdentifier = getenv("PASSWORD_STORE_OTP_IDENTIFIER"); - if (passOtpIdentifier != nullptr) { - this->passOtpIdentifier = passOtpIdentifier; - } auto isOtp = match.text().split('/').filter(QRegularExpression("^" + QRegularExpression::escape(this->passOtpIdentifier) + ".*")).size() > 0; auto ret = isOtp ? From 769e8afea08180625c0da5a8375b110f735ebc8e Mon Sep 17 00:00:00 2001 From: akermu Date: Mon, 5 Jun 2017 22:57:26 +0700 Subject: [PATCH 6/7] Extract regexp for pass-otp --- pass.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pass.cpp b/pass.cpp index 3b7013d..6d5d70c 100644 --- a/pass.cpp +++ b/pass.cpp @@ -131,7 +131,8 @@ void Pass::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &m { Q_UNUSED(context); - auto isOtp = match.text().split('/').filter(QRegularExpression("^" + QRegularExpression::escape(this->passOtpIdentifier) + ".*")).size() > 0; + auto regexp = QRegularExpression("^" + QRegularExpression::escape(this->passOtpIdentifier) + ".*"); + auto isOtp = match.text().split('/').filter(regexp).size() > 0; auto ret = isOtp ? QProcess::execute(QString("pass otp -c ") + match.text()) : From 6db1147a9d10b6cb2ed4e743f0e0178d8343c1e1 Mon Sep 17 00:00:00 2001 From: akermu Date: Mon, 5 Jun 2017 22:59:17 +0700 Subject: [PATCH 7/7] Clarify warning --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d3e081..1556459 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Integrates [krunner](https://userbase.kde.org/Plasma/Krunner) with [pass](https: To use with pass-otp, use the identifier "totp::" as a prefix in the filename or file path of the otp password file. Alternatively, set $PASSWORD_STORE_OTP_IDENTIFIER to overwrite the identifier string. This must be set in `.xprofile` -or similar file. +or similar file, before the initalization of krunner. Build and Installation ======================