Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moved from libkeepass to pykeepass #8

Merged
merged 2 commits into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 8 additions & 10 deletions kdbxpasswordpwned.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

import libkeepass
import pykeepass
import requests
import hashlib
import argparse
Expand Down Expand Up @@ -32,19 +32,17 @@ def check_hash(password):
def main(args=None):
opt = build_parser().parse_args(args)

with libkeepass.open(opt.kdbx, password=getpass.getpass(), keyfile=opt.keyfile, mode='rb') as kdb:
for entry in kdb.obj_root.findall('.//Group/Entry'):
uuid = entry.find('./UUID').text
kv = {string.find('./Key').text: string.find('./Value').text for string in entry.findall('./String')}
if not kv['Password']:
with pykeepass.PyKeePass(opt.kdbx, password=getpass.getpass(), keyfile=opt.keyfile) as kdb:
for entry in kdb.entries:
if not entry.password:
continue
r = check_hash(kv['Password'])
r = check_hash(entry.password)
if r > 0:
m = 'Password for %s (%s) seen %d times before' % (kv['Title'], uuid, r)
m = 'Password for %s seen %d times before' % (entry.title, r)
if opt.show_user:
m += ' - %s' % kv.get('UserName')
m += ' - %s' % entry.username
if opt.show_password:
m += ' - %s' % kv['Password']
m += ' - %s' % entry.password
print(m)


Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
libkeepass==0.3.0
requests==2.20.1
pykeepass==3.0.2
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
py_modules=['kdbxpasswordpwned'],
install_requires=[
'requests',
'libkeepass',
'pykeepass==3.0.2',
],
entry_points={
'console_scripts': ['kdbxpasswordpwned=kdbxpasswordpwned:main']
Expand Down
17 changes: 9 additions & 8 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from contextlib import contextmanager
import sys
import os
import construct
try:
from cStringIO import StringIO
except ImportError:
Expand Down Expand Up @@ -61,8 +62,8 @@ def test_check_hash(self, req_mock):
def test_wrong_password(self, gp_mock):
gp_mock.return_value = 'wrong'
self.assertRaisesRegexp(
IOError,
'Master key invalid.',
construct.ChecksumError,
"wrong checksum, read b{0,1}'.+?', computed b{0,1}'.+?'",
kdbxpasswordpwned.main,
[_asset('sample.kdbx')]
)
Expand All @@ -79,8 +80,8 @@ def test_run(self, ch_mock, gp_mock):
self.assertEqual(
fout[0].getvalue(),
'''\
Password for title1 (FEiAje5y9FQmdVCSFDuSRA==) seen 3 times before
Password for title2 (c3NVlIIN/pPhrM9Pk4Ow+Q==) seen 3 times before
Password for title1 seen 3 times before
Password for title2 seen 3 times before
'''
)
ch_mock.assert_has_calls([
Expand All @@ -101,8 +102,8 @@ def test_run_show_user_and_password(self, ch_mock, gp_mock):
self.assertEqual(
fout[0].getvalue(),
'''\
Password for title1 (FEiAje5y9FQmdVCSFDuSRA==) seen 2 times before - testuser - testit
Password for title2 (c3NVlIIN/pPhrM9Pk4Ow+Q==) seen 2 times before - None - blabla
Password for title1 seen 2 times before - testuser - testit
Password for title2 seen 2 times before - None - blabla
'''
)
ch_mock.assert_has_calls([
Expand All @@ -114,8 +115,8 @@ def test_run_show_user_and_password(self, ch_mock, gp_mock):
def test_run_keyfile_missing(self, gp_mock):
gp_mock.return_value = 'reallysafeone'
self.assertRaisesRegexp(
IOError,
'Master key invalid.',
construct.ChecksumError,
"wrong checksum, read b{0,1}'.+?', computed b{0,1}'.+?'",
kdbxpasswordpwned.main,
[_asset('sample_with_key.kdbx')]
)
Expand Down