comparison cutils/genpwd.py @ 244:42f7ecd70ec1

genpwd: Renamed algorithms and changed restricted the WEB character repertoire to not use delims and sub-delims from URLs and URIs
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 08 Feb 2025 10:52:02 +0100
parents 86417af99561
children 35c06dcca856
comparison
equal deleted inserted replaced
243:86417af99561 244:42f7ecd70ec1
25 import sys 25 import sys
26 26
27 from . import (__version__, __revision__) 27 from . import (__version__, __revision__)
28 28
29 29
30 #
31 # Unreserved characters according to RFC 1738 (URL) **and** RFC 3986 (URI)
32 # No general delimiters and no sub-delimiters.
33 #
30 WEB_CHARS = (b"ABCDEFGHIJKLMNOPQRSTUVWYXZabcdefghijklmnopqrstuvwxyz" 34 WEB_CHARS = (b"ABCDEFGHIJKLMNOPQRSTUVWYXZabcdefghijklmnopqrstuvwxyz"
31 b"0123456789.,-_;!()[]{}*") 35 b"0123456789-._")
32 WEB_SAFE_CHARS = (b"ABCDEFGHJKLMNPQRSTUVWYXZabcdefghijkmnopqrstuvwxyz" 36 SAFE_WEB_CHARS = (b"ABCDEFGHJKLMNPQRSTUVWYXZabcdefghijkmnopqrstuvwxyz"
33 b"23456789.,-_;!") 37 b"23456789-._")
34 WEB_SAFE2_CHARS = b".,-_;!" + WEB_SAFE_CHARS # prefer punctionation chars 38 SAFE_WEB_CHARS_2 = b".-_" + SAFE_WEB_CHARS # prefer punctionation chars
35 # Most visible characters but no space 39 # Most visible characters but no space
36 FULL_ASCII = (b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" 40 FULL_ASCII = (b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
37 b"abcdefghijklmnopqrstuvwxyz!#$%&/()*+-.,:;<=>?@^_`[\\]{|}'\"~") 41 b"abcdefghijklmnopqrstuvwxyz!#$%&/()*+-.,:;<=>?@^_`[\\]{|}'\"~")
38 # 42 #
39 # A safer variant of FULL_ASCII: 43 # A safer variant of FULL_ASCII:
64 "-E", dest="use_bin_length", action="store_true", 68 "-E", dest="use_bin_length", action="store_true",
65 help="For some repertoires make OUTPUT-LENGTH the number of bytes" 69 help="For some repertoires make OUTPUT-LENGTH the number of bytes"
66 " that is to be read from random sources instead of output bytes") 70 " that is to be read from random sources instead of output bytes")
67 aparser.add_argument( 71 aparser.add_argument(
68 "--repertoire", "--type", "-t", 72 "--repertoire", "--type", "-t",
69 choices=("web", "web-safe", "web-safe2", "ascii", "safe-ascii", 73 choices=("web", "safe-web", "safe-web-2", "ascii", "safe-ascii",
70 "alnum", "safe-alnum", 74 "alnum", "safe-alnum",
71 "bin-base64", "bin-urlsafe-base64", "bin-base32", 75 "bin-base64", "bin-urlsafe-base64", "bin-base32",
72 "bin-ascii85", "bin-hex", ), 76 "bin-ascii85", "bin-hex", ),
73 default="web-safe2", 77 default="safe-web-2",
74 help=""" 78 help="""
75 Select from a character repertoire. 79 Select from a character repertoire.
76 All repertoires that start with "bin-" just encode the output of 80 All repertoires that start with "bin-" just encode the output of
77 "os.urandom()" with the selected encoder. 81 "os.urandom()" with the selected encoder.
78 Default: web-safe2 82 Default: web-safe2
83 87
84 opts = aparser.parse_args(args=argv) 88 opts = aparser.parse_args(args=argv)
85 89
86 if opts.repertoire == "web": 90 if opts.repertoire == "web":
87 pwd = gen_from_repertoire(opts.req_length, WEB_CHARS) 91 pwd = gen_from_repertoire(opts.req_length, WEB_CHARS)
88 elif opts.repertoire == "web-safe": 92 elif opts.repertoire == "safe-web":
89 pwd = gen_from_repertoire(opts.req_length, WEB_SAFE_CHARS) 93 pwd = gen_from_repertoire(opts.req_length, SAFE_WEB_CHARS)
90 elif opts.repertoire == "web-safe2": 94 elif opts.repertoire == "safe-web-2":
91 pwd = gen_from_repertoire(opts.req_length, WEB_SAFE2_CHARS) 95 pwd = gen_from_repertoire(opts.req_length, SAFE_WEB_CHARS_2)
92 elif opts.repertoire == "ascii": 96 elif opts.repertoire == "ascii":
93 pwd = gen_from_repertoire(opts.req_length, FULL_ASCII) 97 pwd = gen_from_repertoire(opts.req_length, FULL_ASCII)
94 elif opts.repertoire == "safe-ascii": 98 elif opts.repertoire == "safe-ascii":
95 pwd = gen_from_repertoire(opts.req_length, SAFE_ASCII) 99 pwd = gen_from_repertoire(opts.req_length, SAFE_ASCII)
96 elif opts.repertoire == "alnum": 100 elif opts.repertoire == "alnum":