예제 #1
0
    def test_init(self):
        init_dir = tempfile.mkdtemp()
        PasswordStore.init(
            '5C5833E3',
            path=os.path.join(init_dir, '.password-store')
        )

        self.assertTrue(
            os.path.isdir(os.path.join(init_dir, '.password-store'))
        )

        self.assertTrue(
            os.path.isfile(
                os.path.join(init_dir, '.password-store', '.gpg-id')
            )
        )

        self.assertEqual(
            open(
                os.path.join(init_dir, '.password-store', '.gpg-id'),
                'r'
            ).read(),
            '5C5833E3\n'
        )

        shutil.rmtree(init_dir)
예제 #2
0
파일: main.py 프로젝트: toXel/pass_export
def main():
    store = PasswordStore()
    entries = store.get_passwords_list()
    with open('pass.csv', 'w', newline='') as csvfile:
        csvwriter = csv.writer(csvfile)
        for entry in entries:
            csvwriter.writerow(parse(entry, store))
예제 #3
0
    def test_init(self):
        init_dir = tempfile.mkdtemp()
        PasswordStore.init(
            '5C5833E3',
            path=os.path.join(init_dir, '.password-store')
        )

        self.assertTrue(
            os.path.isdir(os.path.join(init_dir, '.password-store'))
        )

        self.assertTrue(
            os.path.isfile(
                os.path.join(init_dir, '.password-store', '.gpg-id')
            )
        )

        self.assertEqual(
            open(
                os.path.join(init_dir, '.password-store', '.gpg-id'),
                'r'
            ).read(),
            '5C5833E3\n'
        )

        shutil.rmtree(init_dir)
예제 #4
0
    def test_init_clone(self):
        origin_dir = tempfile.mkdtemp()
        destination_dir = tempfile.mkdtemp()

        subprocess.Popen(
            [
                'git',
                '--git-dir=%s' % os.path.join(origin_dir, '.git'),
                '--work-tree=%s' % origin_dir,
                'init',
                origin_dir
            ],
            shell=False
        ).wait()

        open(os.path.join(origin_dir, 'test_git_init_clone.gpg'), 'a').close()

        subprocess.Popen(
            [
                'git',
                '--git-dir=%s' % os.path.join(origin_dir, '.git'),
                '--work-tree=%s' % origin_dir,
                'add', 'test_git_init_clone.gpg',
            ]
        ).wait()

        subprocess.Popen(
            [
                'git',
                '--git-dir=%s' % os.path.join(origin_dir, '.git'),
                '--work-tree=%s' % origin_dir,
                'commit',
                '-m', '"testcommit"',
            ]
        ).wait()

        # Init
        PasswordStore.init(
            path=destination_dir,
            clone_url=origin_dir,
            gpg_id='3CCC3A3A'
        )

        # The key should be imported
        self.assertTrue(
            os.path.isfile(
                os.path.join(destination_dir, 'test_git_init_clone.gpg')
            )
        )

        # The gpg-id file should be created
        self.assertTrue(
            os.path.isfile(
                os.path.join(destination_dir, '.gpg-id')
            )
        )

        shutil.rmtree(origin_dir)
        shutil.rmtree(destination_dir)
예제 #5
0
    def test_init_clone(self):
        origin_dir = tempfile.mkdtemp()
        destination_dir = tempfile.mkdtemp()

        subprocess.Popen(
            [
                'git',
                '--git-dir=%s' % os.path.join(origin_dir, '.git'),
                '--work-tree=%s' % origin_dir,
                'init',
                origin_dir
            ],
            shell=False
        ).wait()

        open(os.path.join(origin_dir, 'test_git_init_clone.gpg'), 'a').close()

        subprocess.Popen(
            [
                'git',
                '--git-dir=%s' % os.path.join(origin_dir, '.git'),
                '--work-tree=%s' % origin_dir,
                'add', 'test_git_init_clone.gpg',
            ]
        ).wait()

        subprocess.Popen(
            [
                'git',
                '--git-dir=%s' % os.path.join(origin_dir, '.git'),
                '--work-tree=%s' % origin_dir,
                'commit',
                '-m', '"testcommit"',
            ]
        ).wait()

        # Init
        PasswordStore.init(
            path=destination_dir,
            clone_url=origin_dir,
            gpg_id='3CCC3A3A'
        )

        # The key should be imported
        self.assertTrue(
            os.path.isfile(
                os.path.join(destination_dir, 'test_git_init_clone.gpg')
            )
        )

        # The gpg-id file should be created
        self.assertTrue(
            os.path.isfile(
                os.path.join(destination_dir, '.gpg-id')
            )
        )

        shutil.rmtree(origin_dir)
        shutil.rmtree(destination_dir)
예제 #6
0
 def test_get_decrypted_password_only_password(self):
     store = PasswordStore(self.dir)
     password = '******'
     store.insert_password('hello.com', password)
     self.assertEqual(
         'ELLO',
         store.get_decrypted_password('hello.com')
     )
예제 #7
0
 def test_get_passwords_list(self):
     store = PasswordStore(self.dir)
     self.assertListEqual(
         sorted(store.get_passwords_list()),
         sorted([
             'test.com',
             'linux.ca',
             'passwordstore.org',
             'Email/email.com',
         ]))
예제 #8
0
 def test_get_passwords_list(self):
     store = PasswordStore(self.dir)
     self.assertListEqual(
         sorted(store.get_passwords_list()),
         sorted([
             'test.com',
             'linux.ca',
             'passwordstore.org',
             'Email/email.com',
         ])
     )
예제 #9
0
    def test_constructor(self):
        # Construct on properly initialized directory
        store = PasswordStore(self.dir)
        self.assertEqual(store._get_gpg_id(self.dir), '5C5833E3')
        self.assertFalse(store.uses_git)
        self.assertEqual(self.dir, store.path)

        # Fail gracefully on missing .gpg-id
        gpg_id_path = os.path.join(self.dir, '.gpg-id')
        os.remove(gpg_id_path)
        self.assertRaises(Exception, PasswordStore, self.dir)
예제 #10
0
    def test_encrypt_decrypt(self):
        self.assertFalse(
            os.path.isfile(os.path.join(self.dir, 'hello.com.gpg')))

        store = PasswordStore(self.dir)
        password = '******'
        store.insert_password('hello.com', password)

        self.assertTrue(os.path.isfile(os.path.join(self.dir,
                                                    'hello.com.gpg')))

        self.assertEqual(password, store.get_decrypted_password('hello.com'))
예제 #11
0
    def test_generate_password(self):
        only_letters = PasswordStore.generate_password(digits=False,
                                                       symbols=False)

        self.assertTrue(only_letters.isalpha())

        alphanum = PasswordStore.generate_password(digits=True, symbols=False)
        self.assertTrue(alphanum.isalnum())
        for char in alphanum:
            self.assertTrue(char not in string.punctuation)

        length_100 = PasswordStore.generate_password(length=100)
        self.assertEqual(len(length_100), 100)
예제 #12
0
    def test_generate_password(self):
        only_letters = PasswordStore.generate_password(
            digits=False,
            symbols=False
        )

        self.assertTrue(only_letters.isalpha())

        alphanum = PasswordStore.generate_password(digits=True, symbols=False)
        self.assertTrue(alphanum.isalnum())
        for char in alphanum:
            self.assertTrue(char not in string.punctuation)

        length_100 = PasswordStore.generate_password(length=100)
        self.assertEqual(len(length_100), 100)
예제 #13
0
    def test_encrypt_decrypt(self):
        self.assertFalse(
            os.path.isfile(os.path.join(self.dir, 'hello.com.gpg'))
        )

        store = PasswordStore(self.dir)
        password = '******'
        store.insert_password('hello.com', password)

        self.assertTrue(
            os.path.isfile(os.path.join(self.dir, 'hello.com.gpg'))
        )

        self.assertEqual(
            password,
            store.get_decypted_password('hello.com')
        )
예제 #14
0
def generate(pass_name, pass_length, no_symbols):
    symbols = not no_symbols

    password = PasswordStore.generate_password(digits=True,
                                               symbols=symbols,
                                               length=pass_length)

    print(password)
예제 #15
0
 def test_get_decrypted_password_deeply_nested(self):
     store = PasswordStore(self.dir)
     self.assertFalse(os.path.isdir(os.path.join(self.dir, 'A', 'B', 'C')))
     store.insert_password('A/B/C/D/hello.com', 'Alice')
     store.insert_password('A/B/C/hello.com', 'Bob')
     self.assertEqual('Alice',
                      store.get_decrypted_password('A/B/C/D/hello.com'))
     self.assertEqual('Bob',
                      store.get_decrypted_password('A/B/C/hello.com'))
     self.assertTrue(
         os.path.isdir(os.path.join(self.dir, 'A', 'B', 'C', 'D')))
예제 #16
0
def generate(pass_name, pass_length, no_symbols):
    symbols = not no_symbols

    password = PasswordStore.generate_password(
        digits=True,
        symbols=symbols,
        length=pass_length
    )

    print(password)
예제 #17
0
    def test_generate_password_uses_correct_gpg_id(self):
        store = PasswordStore(self.dir)

        def get_gpg_ids_used(filename):
            gpg = subprocess.Popen(
                [GPG_BIN, '--list-packets',
                 os.path.join(self.dir, filename)],
                shell=False,
                stdout=subprocess.PIPE)
            gpg.wait()
            pubkeys = []
            for line in gpg.stdout.readlines():
                line = line.decode()
                if line.startswith(':pubkey'):
                    pubkeys.append(line.split()[-1])

            return pubkeys

        store.generate_password('should_use_main_key')
        pubkeys = get_gpg_ids_used('should_use_main_key.gpg')
        self.assertTrue(len(pubkeys) == 1)
        self.assertEqual(pubkeys[0], '6C8110881C10BC07')

        store.generate_password('Email/should_use_secondary_key')
        pubkeys = get_gpg_ids_used(
            os.path.join('Email', 'should_use_secondary_key.gpg'))
        self.assertTrue(len(pubkeys) == 1)
        self.assertEqual(pubkeys[0], '4B52397C4C1C5D70')
예제 #18
0
    def test_get_decypted_password_specific_entry(self):
        store = PasswordStore(self.dir)
        password = '******'
        store.insert_password('hello.com', password)

        # When there is no 'password:'******'ELLO',
            store.get_decypted_password('hello.com', entry=EntryType.password)
        )

        store.insert_password('hello.com', 'sdfsdf\npassword: pwd')
        self.assertEqual(
            'pwd',
            store.get_decypted_password('hello.com', entry=EntryType.password)
        )

        store.insert_password('hello.com', 'sdf\npassword: pwd\nusername: bob')
        self.assertEqual(
            'bob',
            store.get_decypted_password('hello.com', entry=EntryType.username)
        )
예제 #19
0
    def test_generate_in_place(self):
        store = PasswordStore(self.dir)

        self.assertRaises(Exception,
                          store.generate_password,
                          'nope.org',
                          first_line_only=True)

        store.insert_password('nope.org', 'pw\nremains intact')
        store.generate_password('nope.org', length=3, first_line_only=True)

        new_content = store.get_decrypted_password('nope.org')
        new_password, _, remainder = new_content.partition('\n')
        self.assertNotEqual(new_password, 'pw')
        self.assertEqual(remainder, 'remains intact')
예제 #20
0
def main(ctx, password_store_dir, password_store_git, editor):

    # init does not need any of this.
    if ctx.invoked_subcommand == "init":
        return

    # Prepare the config file
    config = {
        'password_store':
        PasswordStore(path=password_store_dir, git_dir=password_store_git),
        'editor':
        editor
    }

    ctx.obj = config

    # By default, invoke ls
    if ctx.invoked_subcommand is None:
        ctx.invoke(ls)
예제 #21
0
 def test_get_decrypted_password_deeply_nested(self):
     store = PasswordStore(self.dir)
     self.assertFalse(
         os.path.isdir(os.path.join(self.dir, 'A', 'B', 'C'))
     )
     store.insert_password('A/B/C/D/hello.com', 'Alice')
     store.insert_password('A/B/C/hello.com', 'Bob')
     self.assertEqual(
         'Alice',
         store.get_decrypted_password('A/B/C/D/hello.com')
     )
     self.assertEqual(
         'Bob',
         store.get_decrypted_password('A/B/C/hello.com')
     )
     self.assertTrue(
         os.path.isdir(os.path.join(self.dir, 'A', 'B', 'C', 'D'))
     )
예제 #22
0
    def test_get_decrypted_password_specific_entry(self):
        store = PasswordStore(self.dir)
        password = '******'
        store.insert_password('hello.com', password)

        # When there is no 'password:'******'ELLO',
            store.get_decrypted_password('hello.com',
                                         entry=EntryType.password))

        store.insert_password('hello.com', 'sdfsdf\npassword: pwd')
        self.assertEqual(
            'pwd',
            store.get_decrypted_password('hello.com',
                                         entry=EntryType.password))

        store.insert_password(
            'hello', 'sdf\npassword: pwd\nusername: bob\nhost: salut.fr')
        self.assertEqual(
            'bob',
            store.get_decrypted_password('hello', entry=EntryType.username))
        self.assertEqual(
            'salut.fr',
            store.get_decrypted_password('hello', entry=EntryType.hostname))
예제 #23
0
def init(path, clone, gpg_id):
    PasswordStore.init(gpg_id, path, clone_url=clone)
    click.echo("Password store initialized for %s." % gpg_id)
예제 #24
0
 def test_constructor(self):
     store = PasswordStore(self.dir)
     self.assertEqual(store.gpg_id, '5C5833E3')
     self.assertFalse(store.uses_git)
     self.assertEqual(self.dir, store.path)
예제 #25
0
    def test_generate_password(self):
        store = PasswordStore(self.dir)

        store.generate_password('letters.net', digits=False, symbols=False)
        only_letters = store.get_decrypted_password('letters.net')
        self.assertTrue(only_letters.isalpha())

        store.generate_password('alphanum.co.uk', digits=True, symbols=False)
        alphanum = store.get_decrypted_password('alphanum.co.uk')
        self.assertTrue(alphanum.isalnum())
        for char in alphanum:
            self.assertTrue(char not in string.punctuation)

        store.generate_password('hundred.org', length=100)
        length_100 = store.get_decrypted_password('hundred.org')
        self.assertEqual(len(length_100), 100)
예제 #26
0
 def test_get_decrypted_password_doesnt_exist(self):
     store = PasswordStore(self.dir)
     self.assertRaises(Exception, store.get_decrypted_password, 'nope.com')
예제 #27
0
def init(path, clone, gpg_id):
    PasswordStore.init(gpg_id, path, clone_url=clone)
    click.echo("Password store initialized for %s." % gpg_id)