def run_delete(args): keyfile = Keyfile.load(args['keyfile'][0]) with Database(keyfile) as d: c = Credentials( args['domain'], args['username']) d.delete(c)
def setUp(self): self.d = TempDir() self.keyfile_path = os.path.join(self.d.name, 'keyfile') self.database_path = os.path.join(self.d.name, 'database') self.keyfile = K.create( self.keyfile_path, self.database_path) D.create(self.keyfile)
def delete(keyfile_path, domain, username): try: k = Keyfile.load(keyfile_path) c = Credentials(domain, username) with Database(k) as d: d.delete(c) notify('Deleted!', 'Account %s@%s deleted' % (username, domain)) except: notify('Error', 'Could not update password')
def copy(keyfile_path, domain, username, pin): try: k = Keyfile.load(keyfile_path) with Database(k) as d: results = d.find(domain=domain, username=username) pbcopy(results[0].unlock(pin)) notify('Copied!', 'Password copied to clipboard') except: notify('Error', 'Could not copy password')
def run_find(args): results = [] for k in args['keyfile']: keyfile = Keyfile.load(k) with Database(keyfile) as d: results += d.find(args.get('domain', ''), args.get('username', '')) if len(results) == 1: if 'pin' in args: results[0].unlock(int(args['pin'])) return pretty_credentials(results)
def run_update(args): keyfile = Keyfile.load(args['keyfile'][0]) with Database(keyfile) as d: c = Credentials( args['domain'], args['username'], plainpassword=args.get( 'password', utilities.generate_password(keyfile, args))) d.update(c, args['pin']) return pretty_credentials([c])
def load_keyfiles(): s = Settings() raw_k = s.get('keyfiles', {}) keyfiles = [] for name in raw_k: try: k = Keyfile.load(raw_k[name]) k.name = name keyfiles.append(k) except: pass return keyfiles
def test_init_override(self): with TempDir() as d: k = os.path.join(d.name, 'keyfile') d = os.path.join(d.name, 'database') cli.main(('init %s %s --key %s --iv %s --length %d --characters %s' % (k, d, self.key, self.iv, self.length, self.characters)).split(' ')) keyfile = Keyfile.load(k) self.assertEqual(k, keyfile.path) self.assertEqual(d, keyfile.database_path) self.assertEqual(self.length, keyfile.length) self.assertEqual(self.characters, keyfile.characters) self.assertEqual(self.key, keyfile.key) self.assertEqual(self.iv, keyfile.iv)
def test_init_defaults(self): with TempDir() as d: k = os.path.join(d.name, 'keyfile') d = os.path.join(d.name, 'database') cli.main(('init %s %s' % (k, d)).split(' ')) keyfile = Keyfile.load(k) self.assertEqual(k, keyfile.path) self.assertEqual(d, keyfile.database_path) self.assertEqual(Keyfile.LENGTH, keyfile.length) self.assertEqual(Keyfile.CHARACTERS, keyfile.characters) keyfile.key keyfile.iv
def update(keyfile_path, domain, username, pin, password=None, length=None, characters=None): try: k = Keyfile.load(keyfile_path) if password is None or length is not None: args = {} if length is not None: args['length'] = length if characters is not None: args['characters'] = characters password = pinscher.utilities.generate_password(k, args) c = Credentials(domain, username, plainpassword=password) with Database(k) as d: d.update(c, pin) pbcopy(c.unlock(pin)) notify('Updated!', 'Password updated and copied to clipboard') except: notify('Error', 'Could not update password')
def qr(keyfile_path, domain, username, pin): try: k = Keyfile.load(keyfile_path) with Database(k) as d: results = d.find(domain=domain, username=username) qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=10, ) qr.add_data(results[0].unlock(pin)) qr.make(fit=True) img = qr.make_image() with tempfile.TemporaryFile('w') as f: img.save(os.path.abspath(f.name)) subprocess.Popen(['qlmanage', '-p', os.path.abspath(f.name)], stdout=open('/dev/null', 'w')) except: notify('Error', 'Could not QR password')
def create(name, keyfile_path=None, database_path=None, length=Keyfile.LENGTH, characters=Keyfile.CHARACTERS): try: if keyfile_path is None: keyfile_path = '%s.pkf' % name if database_path is None: database_path = '%s.pdb' % name keyfile = Keyfile.create( keyfile_path, database_path, length=length, characters=characters) Database.create(keyfile) s = Settings() keyfiles = s.get('keyfiles', {}) keyfiles[name] = keyfile.path s.set(keyfiles=keyfiles) notify('Created the keyfile', 'and initialised a database') except: notify('Error', 'Could not create the keyfile')
def setUp(self): self.d = TempDir() self.k = os.path.join(self.d.name, 'keyfile') d = os.path.join(self.d.name, 'database') cli.main(('init %s %s' % (self.k, d)).split(' ')) self.keyfile = Keyfile.load(self.k)
def run_init(args): keyfile = Keyfile.create(args['keyfile'][0], args['database'], **args) Database.create(keyfile)