Example #1
0
    def entropy_action(self, args):
        """Display each site's potential password entropy in bits.

        This is the same thing as the base 2 logarithm of the number of
        possible passwords for a site.
        """

        entropy = [('schema' if args.schema else 'site', 'entropy', '(bits)'), ('', '', '')]
        if args.schema:
            pre_entropy = []
            for schema_name, schema in self.config.get_all_schemata().items():
                multibase = multibase_of_schema(schema, self.config.words)
                pre_entropy.append((schema_name, math.log(multibase.max_encodable_value + 1, 2)))
        else:
            default_site = self.config.get_site('default')
            pre_entropy = [
                (site, math.log(site_config['multibase'].max_encodable_value + 1, 2))
                for site, site_config in self.config.get_all_sites().items()
                if site_config['schema'] != default_site['schema'] or site == 'default'
            ]
        pre_entropy.sort(key=operator.itemgetter(1, 0), reverse=True)
        entropy.extend([site] + ('%0.2f' % bits).split('.')
                       for site, bits in pre_entropy)
        max_site_len, max_ibits_len, max_fbits_len = [
            len(max(x, key=len)) for x in zip(*entropy)]
        print()
        for e, (site, ibits, fbits) in enumerate(entropy):
            if e == 0:
                site = site.center(max_site_len)
            print('%*s   %*s%s%*s' % (
                -max_site_len, site, max_ibits_len, ibits,
                '.' if ibits.isdigit() else ' ', -max_fbits_len, fbits))
Example #2
0
# Copyright (c) Aaron Gallagher <*****@*****.**>
# See COPYING for details.

import string

import pytest

from passacre.schema import multibase_of_schema
from passacre import features, generator, signing_uuid

_shush_pyflakes = [features]
hex_multibase = multibase_of_schema([string.hexdigits[:16]] * 64)


class FakeYubiKey(object):
    def open_first_key(self):
        return self

    def hmac_challenge_response(self, challenge, slot):
        self.challenge = challenge
        self.slot = slot
        return b'spam ' * 4


def test_extend_password_with_yubikey(monkeypatch):
    monkeypatch.setattr(features.yubikey, 'usable', True)
    yk = FakeYubiKey()
    password = generator.extend_password_with_yubikey('spam',
                                                      {'yubikey-slot': 1},
                                                      YubiKey=yk)
    assert password == '7370616d207370616d207370616d207370616d20:spam'
Example #3
0
 def multibase_of_schema(self, schema):
     ret = multibase_of_schema(schema)
     if self.word_list_path is not None:
         ret['words'] = {'source': {'filePath': self.word_list_path}}
     return ret
Example #4
0
def verify_multibase_schema(schema):
    multibase_of_schema(schema)
Example #5
0
# Copyright (c) Aaron Gallagher <*****@*****.**>
# See COPYING for details.

import string

from passacre._backend_capnp import default_client
from passacre.compat import hexlify
from passacre.schema import multibase_of_schema
from passacre import features, signing_uuid

_site_multibase = multibase_of_schema(
    [string.ascii_letters + string.digits + '-_'] * 48)


def generate(username, password, site, options, client=default_client):
    """Generate a password with the passacre method.

    1. A string is generated from ``username:`` (if a username is specified),
       contacenated with ``password:site``, concatentated with 1024 null bytes
       for every iteration.
    2. A pseudo-random number generator is initialized using the string as a
       seed.
    3. The PRNG is asked for an integer below the maximum value that
       ``multibase`` can encode.
    4. That integer is encoded with
       ``multibase`` and the encoded value is returned.
    """

    if options.get('yubikey-slot'):
        password = extend_password_with_yubikey(password, options)
    kdf = {}
Example #6
0
 def multibase_of_schema(self, schema):
     ret = multibase_of_schema(schema)
     if self.word_list_path is not None:
         ret['words'] = {'source': {'filePath': self.word_list_path}}
     return ret
Example #7
0
def verify_multibase_schema(schema):
    multibase_of_schema(schema)
Example #8
0
# Copyright (c) Aaron Gallagher <*****@*****.**>
# See COPYING for details.

import string

from passacre._backend_capnp import default_client
from passacre.compat import hexlify
from passacre.schema import multibase_of_schema
from passacre import features, signing_uuid


_site_multibase = multibase_of_schema([string.ascii_letters + string.digits + '-_'] * 48)


def generate(username, password, site, options, client=default_client):
    """Generate a password with the passacre method.

    1. A string is generated from ``username:`` (if a username is specified),
       contacenated with ``password:site``, concatentated with 1024 null bytes
       for every iteration.
    2. A pseudo-random number generator is initialized using the string as a
       seed.
    3. The PRNG is asked for an integer below the maximum value that
       ``multibase`` can encode.
    4. That integer is encoded with
       ``multibase`` and the encoded value is returned.
    """

    if options.get('yubikey-slot'):
        password = extend_password_with_yubikey(password, options)
    kdf = {}
Example #9
0
 def fill_out_config(self, config):
     config['multibase'] = multibase_of_schema(config['schema'], self.words)
     config['iterations'] = (
         config.get('iterations', 1000) + config.get('increment', 0))
Example #10
0
# Copyright (c) Aaron Gallagher <*****@*****.**>
# See COPYING for details.

import string

import pytest

from passacre.schema import multibase_of_schema
from passacre import features, generator, signing_uuid


_shush_pyflakes = [features]
hex_multibase = multibase_of_schema([string.hexdigits[:16]] * 64)


class FakeYubiKey(object):
    def open_first_key(self):
        return self

    def hmac_challenge_response(self, challenge, slot):
        self.challenge = challenge
        self.slot = slot
        return b'spam ' * 4


def test_extend_password_with_yubikey(monkeypatch):
    monkeypatch.setattr(features.yubikey, 'usable', True)
    yk = FakeYubiKey()
    password = generator.extend_password_with_yubikey('spam', {'yubikey-slot': 1}, YubiKey=yk)
    assert password == '7370616d207370616d207370616d207370616d20:spam'
    assert yk.challenge == signing_uuid.bytes
Example #11
0
 def fill_out_config(self, config):
     config['multibase'] = multibase_of_schema(config['schema'], self.words)
     config['iterations'] = (config.get('iterations', 1000) +
                             config.get('increment', 0))