Replace random.randint() with os.urandom()

This commit is contained in:
Tarjei Husøy (via Travis CI) 2014-10-02 15:08:28 +02:00 committed by Colton Myers
parent ce3ee8bafd
commit 25ea6060b7
4 changed files with 4 additions and 10 deletions

View file

@ -9,7 +9,6 @@ Interact with virtual machine images via libguestfs
import os
import tempfile
import hashlib
import random
# Import Salt libs
import salt.utils
@ -49,7 +48,7 @@ def mount(location, access='rw'):
if os.listdir(root):
# Stuf is in there, don't use it
hash_type = getattr(hashlib, __opts__.get('hash_type', 'md5'))
rand = hash_type(str(random.randint(1, 1000000))).hexdigest()
rand = hash_type(os.urandom(32)).hexdigest()
root = os.path.join(
tempfile.gettempdir(),
'guest',

View file

@ -6,7 +6,6 @@ Wheel system wrapper for key system
# Import python libs
import os
import hashlib
import random
# Import salt libs
import salt.key
@ -79,7 +78,7 @@ def gen(id_=None, keysize=2048):
returned as a dict containing pub and priv keys
'''
if id_ is None:
id_ = hashlib.sha512(str(random.SystemRandom().randint(0, 99999999))).hexdigest()
id_ = hashlib.sha512(os.urandom(32)).hexdigest()
ret = {'priv': '',
'pub': ''}
priv = salt.crypt.gen_keys(__opts__['pki_dir'], id_, keysize)

View file

@ -17,7 +17,6 @@ import re
import sys
import json
import time
import random
import shutil
import hashlib
import argparse
@ -89,8 +88,7 @@ def generate_vm_name(options):
if 'BUILD_NUMBER' in os.environ:
random_part = 'BUILD{0:0>6}'.format(os.environ.get('BUILD_NUMBER'))
else:
random_part = hashlib.md5(
str(random.randint(1, 100000000))).hexdigest()[:6]
random_part = os.urandom(3).encode('hex')
return '{0}-{1}-{2}'.format(options.vm_prefix, options.vm_source, random_part)

View file

@ -16,7 +16,6 @@ import re
import sys
import json
import time
import random
import shutil
import hashlib
import optparse
@ -95,8 +94,7 @@ def generate_vm_name(options):
if 'BUILD_NUMBER' in os.environ:
random_part = 'BUILD{0:0>6}'.format(os.environ.get('BUILD_NUMBER'))
else:
random_part = hashlib.md5(
str(random.randint(1, 100000000))).hexdigest()[:6]
random_part = os.urandom(3).encode('hex')
return '{0}-{1}-{2}'.format(options.vm_prefix, options.platform, random_part)