aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorGravatar √Čtienne Deparis 2017-02-23 18:53:26 +0100
committerGravatar √Čtienne Deparis 2018-08-09 19:03:47 +0200
commit49b876c9761ea4c8b7613c14eb0acbd6a2441b68 (patch)
treefd2859a73108a7fd7c17ee133d6ed100ee32af59
parent666ee6ab40394fee37eaf243540b4b9c5a280b9e (diff)
downloadpassword-store-49b876c9761ea4c8b7613c14eb0acbd6a2441b68.tar.gz
password-store-49b876c9761ea4c8b7613c14eb0acbd6a2441b68.tar.xz
password-store-49b876c9761ea4c8b7613c14eb0acbd6a2441b68.zip
feat: Get OTP token from secret kept in the ^otp/ folder
-rwxr-xr-xcontrib/rofi/passrofi.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/contrib/rofi/passrofi.py b/contrib/rofi/passrofi.py
index 02126e8..8964173 100755
--- a/contrib/rofi/passrofi.py
+++ b/contrib/rofi/passrofi.py
@@ -45,8 +45,12 @@ class PassRofi():
for line in self.history:
f.write("{1} {0}\n".format(*line))
- if self.type_pass:
+ if selected_pass.startswith("otp/"):
+ self.copy_otp(selected_pass)
+
+ elif self.type_pass:
self.type_password(selected_pass)
+
else:
subprocess.run(
["pass", "show", "-c", selected_pass],
@@ -82,14 +86,34 @@ class PassRofi():
stdout, _ = cmd.communicate("\n".join(options).encode())
return stdout.decode().strip()
- def type_password(self, pass_name):
- password = subprocess.run(
+ def decypher_password(self, pass_name):
+ return subprocess.run(
["pass", "show", pass_name],
check=True, stdout=subprocess.PIPE
- ).stdout.decode().split("\n")
+ ).stdout.decode().split("\n")[0].strip()
+
+ def type_password(self, pass_name):
subprocess.run(
["xdotool", "type", "--clearmodifiers",
- password[0].strip()])
+ self.decypher_password(pass_name)])
+
+ def copy_otp(self, pass_name):
+ password = self.decypher_password(pass_name)
+ otp_answer = subprocess.run(
+ shlex.split(password),
+ check=True, stdout=subprocess.PIPE
+ ).stdout
+
+ if self.type_pass:
+ subprocess.run(
+ ["xdotool", "type", "--clearmodifiers",
+ otp_answer.decode().strip()])
+ else:
+ cmd = subprocess.Popen(["xclip"],
+ stdin=subprocess.PIPE,
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL)
+ cmd.communicate(otp_answer)
if __name__ == "__main__":