From 03235ab51d102ba722e71adf00d2f721c77cd222 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Thu, 1 Jun 2017 21:02:41 +0200 Subject: Fixed random password generator. The equal sign is no longer used to generate random password since it's already used as token name and password delimiter in password.conf. https://pagure.io/dogtagpki/issue/2556 Change-Id: Id59f9aae4d01958f69c305e7d5cda44ce5c81c84 --- base/common/python/pki/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'base/common/python') diff --git a/base/common/python/pki/__init__.py b/base/common/python/pki/__init__.py index 1fc538547..0478b325f 100644 --- a/base/common/python/pki/__init__.py +++ b/base/common/python/pki/__init__.py @@ -45,6 +45,11 @@ PACKAGE_VERSION = SHARE_DIR + '/VERSION' CERT_HEADER = "-----BEGIN CERTIFICATE-----" CERT_FOOTER = "-----END CERTIFICATE-----" +# Valid punctuation characters for random password. +# This is identical to string.punctuation minus the equal +# sign since it's used as delimiter in password.conf. +PUNCTUATIONS = '!"#$%&\'()*+,-./:;<>?@[\\]^_`{|}~' + def read_text(message, options=None, default=None, delimiter=':', @@ -139,7 +144,7 @@ def generate_password(): * digits (string.digits) * ASCII lowercase letters (string.ascii_lowercase) * ASCII uppercase letters (string.ascii_uppercase) - * ASCII non-alphanumeric characters (string.punctuation) + * ASCII non-alphanumeric characters (PUNCTUATIONS) * non-ASCII characters If an ASCII uppercase letter is the first character of the password, @@ -159,7 +164,7 @@ def generate_password(): valid_chars = string.digits +\ string.ascii_lowercase +\ string.ascii_uppercase +\ - string.punctuation + PUNCTUATIONS chars = [] @@ -168,7 +173,7 @@ def generate_password(): chars.append(rnd.choice(string.digits)) chars.append(rnd.choice(string.ascii_lowercase)) chars.append(rnd.choice(string.ascii_uppercase)) - chars.append(rnd.choice(string.punctuation)) + chars.append(rnd.choice(PUNCTUATIONS)) # add 6 additional random chars chars.extend(rnd.choice(valid_chars) for i in range(6)) -- cgit