#NEWLINE# def generate_files( self , config ) : #NEWLINE# #INDENT# tls_certificate_path = config [ 'tls_certificate_path' ] #NEWLINE# tls_private_key_path = config [ 'tls_private_key_path' ] #NEWLINE# tls_dh_params_path = config [ 'tls_dh_params_path' ] #NEWLINE# if ( not os . path . exists ( tls_private_key_path ) ) : #NEWLINE# #INDENT# with open ( tls_private_key_path , 'w' ) as private_key_file : #NEWLINE# #INDENT# tls_private_key = crypto . PKey ( ) #NEWLINE# tls_private_key . generate_key ( crypto . TYPE_RSA , 2048 ) #NEWLINE# private_key_pem = crypto . dump_privatekey ( crypto . FILETYPE_PEM , tls_private_key ) #NEWLINE# private_key_file . write ( private_key_pem ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# with open ( tls_private_key_path ) as private_key_file : #NEWLINE# #INDENT# private_key_pem = private_key_file . read ( ) #NEWLINE# tls_private_key = crypto . load_privatekey ( crypto . FILETYPE_PEM , private_key_pem ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not os . path . exists ( tls_certificate_path ) ) : #NEWLINE# #INDENT# with open ( tls_certificate_path , 'w' ) as certificate_file : #NEWLINE# #INDENT# cert = crypto . X509 ( ) #NEWLINE# subject = cert . get_subject ( ) #NEWLINE# subject . CN = config [ 'server_name' ] #NEWLINE# cert . set_serial_number ( 1000 ) #NEWLINE# cert . gmtime_adj_notBefore ( 0 ) #NEWLINE# cert . gmtime_adj_notAfter ( ( ( ( ( 10 * 365 ) * 24 ) * 60 ) * 60 ) ) #NEWLINE# cert . set_issuer ( cert . get_subject ( ) ) #NEWLINE# cert . set_pubkey ( tls_private_key ) #NEWLINE# cert . sign ( tls_private_key , 'sha256' ) #NEWLINE# cert_pem = crypto . dump_certificate ( crypto . FILETYPE_PEM , cert ) #NEWLINE# certificate_file . write ( cert_pem ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not os . path . exists ( tls_dh_params_path ) ) : #NEWLINE# #INDENT# if GENERATE_DH_PARAMS : #NEWLINE# #INDENT# subprocess . check_call ( [ 'openssl' , 'dhparam' , '-outform' , 'PEM' , '-out' , tls_dh_params_path , '2048' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# with open ( tls_dh_params_path , 'w' ) as dh_params_file : #NEWLINE# #INDENT# dh_params_file . write ( '2048-bit DH parameters taken from rfc3526\n-----BEGIN DH PARAMETERS-----\nMIIBCAKCAQEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb\nIlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjft\nawv/XLb0Brft7jhr+1qJn6WunyQRfEsf5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT\nmmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVSu57VKQdwlpZtZww1Tkq8mATxdGwIyhgh\nfDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq\n5RXSJhiY+gUQFXKOWoqsqmj//////////wIBAg==\n-----END DH PARAMETERS-----\n' )