4
4
5
5
import re
6
6
import time
7
- import time
7
+ import socket
8
8
import hashlib
9
9
import argparse
10
10
import subprocess
@@ -644,19 +644,17 @@ def copy_to_qube(self, attribute: int, qube: str, trust_level: int) -> None:
644
644
return
645
645
646
646
print (f'[+] Copying password of credential { self .title } to { qube } .' )
647
- value = self .get_secret (). encode ()
647
+ value = self .get_secret ()
648
648
649
649
elif attribute == 11 :
650
650
print (f'[+] Copying username of credential { self .title } to { qube } .' )
651
- value = self .username . encode ()
651
+ value = self .username
652
652
653
653
elif attribute == 12 :
654
654
print (f'[+] Copying url of credential { self .title } to { qube } .' )
655
- value = self .url . encode ()
655
+ value = self .url
656
656
657
- process = subprocess .Popen (['qrexec-client-vm' , qube , 'custom.QubesKeepass' ], stdin = subprocess .PIPE )
658
- process .stdin .write (value )
659
- process .stdin .close ()
657
+ perform_copy (qube , value )
660
658
661
659
qube_hash = hashlib .md5 (qube .encode ()).hexdigest ()
662
660
lockfile = Path .home () / f'.qubes-keepass-{ qube_hash } .lock'
@@ -675,14 +673,35 @@ def copy_to_qube(self, attribute: int, qube: str, trust_level: int) -> None:
675
673
676
674
else :
677
675
lockfile .unlink ()
678
-
679
- process = subprocess .Popen (['qrexec-client-vm' , qube , 'custom.QubesKeepass' ], stdin = subprocess .PIPE )
680
- process .stdin .write ('' .encode ())
681
- process .stdin .close ()
676
+ perform_copy (qube , '' )
682
677
683
678
print (f'[+] Clipboard of { qube } cleared.' )
684
679
685
680
681
+ def perform_copy (qube : str , data : str ) -> None :
682
+ '''
683
+ Performs the actual copy operation. Before the data is copied, the function checks
684
+ whether the qube to copy the data to is the vault qube. In this case, the copy operation
685
+ isn't performed via qrexec-client-vm, as it does not work for invoking commands within
686
+ the same qube.
687
+
688
+ Parameters:
689
+ qube qube to copy the data to
690
+ data the data to copy
691
+
692
+ Returns:
693
+ None
694
+ '''
695
+ if socket .gethostname () != qube :
696
+ process = subprocess .Popen (['qrexec-client-vm' , qube , 'custom.QubesKeepass' ], stdin = subprocess .PIPE )
697
+
698
+ else :
699
+ process = subprocess .Popen (['/etc/qubes-rpc/custom.QubesKeepass' ], stdin = subprocess .PIPE )
700
+
701
+ process .stdin .write (data .encode ())
702
+ process .stdin .close ()
703
+
704
+
686
705
class CredentialCollection :
687
706
'''
688
707
Represents a collection of Credential objects.
@@ -838,7 +857,7 @@ def load(service: Secret.Service) -> CredentialCollection:
838
857
return CredentialCollection (credentials )
839
858
840
859
841
- parser = argparse .ArgumentParser (description = '''qubes-keepass v1.2.0 - A rofi based KeePassXC frontend for Qubes''' )
860
+ parser = argparse .ArgumentParser (description = '''qubes-keepass v1.2.1 - A rofi based KeePassXC frontend for Qubes''' )
842
861
parser .add_argument ('qube' , help = 'qube to copy the credential to' )
843
862
parser .add_argument ('--trust-level' , type = int , help = 'numerical trust level of the qube' )
844
863
parser .add_argument ('--config' , help = 'path to the configuration file' )
0 commit comments