summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2022-03-31 21:14:40 +0200
committerFlorian Bruhin <me@the-compiler.org>2022-03-31 21:14:40 +0200
commit3f58605ad19e2c7a2afa7134fcda1a9ee9a2ce7e (patch)
treedbdfb4957e0d67283a1141dd1e7da3f942550ead
parent8a6922691211b8c0b60dc894aed8fd69336aef21 (diff)
parent7f73b20e34119bcc0d6a9cf6df6748133bf963e1 (diff)
downloadqutebrowser-3f58605ad19e2c7a2afa7134fcda1a9ee9a2ce7e.tar.gz
qutebrowser-3f58605ad19e2c7a2afa7134fcda1a9ee9a2ce7e.zip
Merge remote-tracking branch 'origin/pr/6543'
-rwxr-xr-xmisc/userscripts/qute-keepassxc15
1 files changed, 9 insertions, 6 deletions
diff --git a/misc/userscripts/qute-keepassxc b/misc/userscripts/qute-keepassxc
index f4e971d3c..a128c2c3e 100755
--- a/misc/userscripts/qute-keepassxc
+++ b/misc/userscripts/qute-keepassxc
@@ -206,16 +206,17 @@ class KeepassXC:
class SecretKeyStore:
- def __init__(self, gpgkey):
+ def __init__(self, gpgkey, insecure):
self.gpgkey = gpgkey
- if gpgkey is None:
+ self.insecure = insecure
+ if self.insecure:
self.path = os.path.join(os.environ['QUTE_DATA_DIR'], 'keepassxc.key')
else:
self.path = os.path.join(os.environ['QUTE_DATA_DIR'], 'keepassxc.key.gpg')
def load(self):
"Load existing association key from file"
- if self.gpgkey is None:
+ if self.insecure:
jsondata = open(self.path, 'r').read()
else:
jsondata = subprocess.check_output(['gpg', '--decrypt', self.path]).decode('utf-8')
@@ -232,7 +233,7 @@ class SecretKeyStore:
"Store newly created association key in file"
self.id = id
jsondata = json.dumps({'id':self.id, 'key':base64.b64encode(self.key).decode('utf-8')})
- if self.gpgkey is None:
+ if self.insecure:
open(self.path, "w").write(jsondata)
else:
subprocess.run(['gpg', '--encrypt', '-o', self.path, '-r', self.gpgkey], input=jsondata.encode('utf-8'), check=True)
@@ -250,8 +251,10 @@ def error(msg):
def connect_to_keepassxc(args):
- assert args.key or args.insecure, "Missing GPG key to use for auth key encryption"
- keystore = SecretKeyStore(args.key)
+ if not args.insecure and not args.key:
+ error("Missing GPG key to use for auth key encryption")
+ return
+ keystore = SecretKeyStore(args.key, args.insecure)
if os.path.isfile(keystore.path):
keystore.load()
kp = KeepassXC(keystore.id, key=keystore.key, socket_path=args.socket)