Skip to content

Commit 266fb37

Browse files
d-w-moorealanking
authored andcommitted
[#526] can now opt out of strong primes to speed up SSL & PAM tests
Also: setupssl.py now has a usage help.
1 parent 1c9ca03 commit 266fb37

1 file changed

Lines changed: 33 additions & 9 deletions

File tree

irods/test/setupssl.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,28 @@ def create_server_cert(process_output = sys.stdout, irods_key_path = 'irods.key'
2525
p.wait()
2626
return p.returncode
2727

28-
def create_ssl_dir(irods_key_path = 'irods.key'):
28+
29+
def create_ssl_dir(irods_key_path = 'irods.key', ssl_dir = '', use_strong_primes_for_dh_generation = True):
30+
ssl_dir = ssl_dir or IRODS_SSL_DIR
2931
save_cwd = os.getcwd()
3032
silent_run = { 'shell': True, 'stderr' : PIPE, 'stdout' : PIPE }
3133
try:
32-
if not (os.path.exists(IRODS_SSL_DIR)):
33-
os.mkdir(IRODS_SSL_DIR)
34-
os.chdir(IRODS_SSL_DIR)
34+
if not (os.path.exists(ssl_dir)):
35+
os.mkdir(ssl_dir)
36+
os.chdir(ssl_dir)
3537
if not keep_old:
3638
Popen("openssl genrsa -out '{irods_key_path}' 2048 && chmod 600 '{irods_key_path}'".format(**locals()),
3739
**silent_run).communicate()
3840
with open("/dev/null","wb") as dev_null:
3941
if 0 == create_server_cert(process_output = dev_null, irods_key_path = irods_key_path):
4042
if not keep_old:
41-
Popen('openssl dhparam -2 -out dhparams.pem',**silent_run).communicate()
43+
# https://www.openssl.org/docs/man1.0.2/man1/dhparam.html#:~:text=DH%20parameter%20generation%20with%20the,that%20may%20be%20possible%20otherwise.
44+
if use_strong_primes_for_dh_generation:
45+
dhparam_generation_command = 'openssl dhparam -2 -out dhparams.pem'
46+
else:
47+
dhparam_generation_command = 'openssl dhparam -dsaparam -out dhparams.pem 4096'
48+
print('cmd=',dhparam_generation_command )
49+
Popen(dhparam_generation_command,**silent_run).communicate()
4250
return os.listdir(".")
4351
finally:
4452
os.chdir(save_cwd)
@@ -57,14 +65,30 @@ def test(options, args=()):
5765
if affirm[:1].lower() == 'y':
5866
if not keep_old:
5967
shutil.rmtree(IRODS_SSL_DIR,ignore_errors=True)
60-
print("Generating new '{}'. This may take a while.".format(IRODS_SSL_DIR), file=sys.stderr)
61-
ssl_dir_files = create_ssl_dir()
62-
print('ssl_dir_files=', ssl_dir_files)
68+
dh_strong_primes = '-q' not in options
69+
wait_warning = (' This may take a while.' if dh_strong_primes else '')
70+
print("Generating new '{}'.{}".format(IRODS_SSL_DIR, wait_warning), file = sys.stderr)
71+
ssl_dir_files = create_ssl_dir(use_strong_primes_for_dh_generation = dh_strong_primes)
72+
print('ssl_dir_files=', ssl_dir_files, file = sys.stderr)
6373

6474
if __name__ == '__main__':
6575
import getopt
66-
opt, arg_list = getopt.getopt(sys.argv[1:],'x:fh:k')
76+
try:
77+
opt, arg_list = getopt.getopt(sys.argv[1:],'x:fh:kq')
78+
except getopt.GetoptError:
79+
print("""Usage: {sys.argv[0]} [-f] [-h <hostname>] [-k] [-q] [-x <extension>]
80+
-f Force replacement of the existing SSL directory (/etc/irods/ssl) with a new one, containing newly generated files.
81+
-h In the generated certificate, use the given hostname rather than the value returned from socket.gethostname()
82+
-k (Keep old secrets files.) Do not generate new key file or dhparams.pem file.
83+
-q For testing; do a quick generation of a dhparams.pem file rather than waiting on system entropy to make it more secure.
84+
-x Optional extra extension for appending to end of the filename for the generated certificate.
85+
86+
Any invalid option prints this help.
87+
""".format(**locals()), file = sys.stderr)
88+
exit(1)
89+
6790
opt_lookup = dict(opt)
91+
6892
ext = opt_lookup.get('-x','')
6993
if ext:
7094
ext = '.' + ext.lstrip('.')

0 commit comments

Comments
 (0)