summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2017-06-01 21:02:41 +0200
committerEndi S. Dewata <edewata@redhat.com>2017-06-02 17:35:24 +0200
commit03235ab51d102ba722e71adf00d2f721c77cd222 (patch)
treeee6e117610b3dce2ebc3a8df0133a4bb2a7daa7f /base
parent9f3bd9675045dad08aaf78c0c6e7d0655ee45933 (diff)
downloadpki-03235ab51d102ba722e71adf00d2f721c77cd222.tar.gz
pki-03235ab51d102ba722e71adf00d2f721c77cd222.tar.xz
pki-03235ab51d102ba722e71adf00d2f721c77cd222.zip
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
Diffstat (limited to 'base')
-rw-r--r--base/common/python/pki/__init__.py11
1 files changed, 8 insertions, 3 deletions
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))