1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 23:25:24 +00:00

Merge pull request #514 from sianciou/security_issue

fix insecure randomness
This commit is contained in:
catborise 2022-07-08 23:11:44 +03:00 committed by GitHub
commit f6915ac51f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,5 @@
import random
import secrets
import re
import string
@ -25,7 +26,7 @@ def randomMAC():
def randomUUID():
"""Generate a random UUID."""
u = [random.randint(0, 255) for ignore in range(0, 16)]
u = [secrets.randbelow(256) for ignore in range(0, 16)]
u[6] = (u[6] & 0x0F) | (4 << 4)
u[8] = (u[8] & 0x3F) | (2 << 6)
return "-".join(["%02x" * 4, "%02x" * 2, "%02x" * 2, "%02x" * 2, "%02x" * 6]) % tuple(u)
@ -33,7 +34,7 @@ def randomUUID():
def randomPasswd(length=12, alphabet=string.ascii_letters + string.digits):
"""Generate a random password"""
return "".join([random.choice(alphabet) for i in range(length)])
return "".join([secrets.choice(alphabet) for i in range(length)])
def get_max_vcpus(conn, type=None):