~hopem/charms/trusty/neutron-api/fix-ssl-inject

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/core/host.py

  • Committer: Edward Hope-Morley
  • Date: 2015-03-18 12:31:38 UTC
  • Revision ID: edward.hope-morley@canonical.com-20150318123138-tqy4gpd6pemg4wxl
[hopem,r=] fix ssl cert inject

Show diffs side-by-side

added added

removed removed

Lines of Context:
339
339
def pwgen(length=None):
340
340
    """Generate a random pasword."""
341
341
    if length is None:
 
342
        # A random length is ok to use a weak PRNG
342
343
        length = random.choice(range(35, 45))
343
344
    alphanumeric_chars = [
344
345
        l for l in (string.ascii_letters + string.digits)
345
346
        if l not in 'l0QD1vAEIOUaeiou']
 
347
    # Use a crypto-friendly PRNG (e.g. /dev/urandom) for making the
 
348
    # actual password
 
349
    random_generator = random.SystemRandom()
346
350
    random_chars = [
347
 
        random.choice(alphanumeric_chars) for _ in range(length)]
 
351
        random_generator.choice(alphanumeric_chars) for _ in range(length)]
348
352
    return(''.join(random_chars))
349
353
 
350
354