From 6aa64a071ffd4cf16447ee1ed9f492a5906315ea Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 7 Dec 2016 16:14:01 -0500 Subject: [PATCH] Improving exception handling --- locales/en.json | 3 ++- src/yunohost/certificate.py | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/locales/en.json b/locales/en.json index 806def22..7de00f39 100644 --- a/locales/en.json +++ b/locales/en.json @@ -256,5 +256,6 @@ "certmanager_cert_signing_failed" : "Signing the new certificate failed.", "certmanager_no_cert_file" : "Unable to read certificate file for domain {domain:s} (file : {file:s})", "certmanager_conflicting_nginx_file": "Unable to prepare domain for ACME challenge : the nginx configuration file {filepath:s} is conflicting and should be removed first.", - "certmanager_unable_to_determine_self_CA_name": "Unable to determine name of self-signing authority." + "certmanager_self_ca_conf_file_not_found" : "Configuration file not found for self-signing CA ({file:s})", + "certmanager_unable_to_parse_self_CA_name": "Unable to parse name of self-signing authority in {file:s}." } diff --git a/src/yunohost/certificate.py b/src/yunohost/certificate.py index 74e93314..8209160a 100644 --- a/src/yunohost/certificate.py +++ b/src/yunohost/certificate.py @@ -812,17 +812,18 @@ def _domain_is_accessible_through_HTTP(ip, domain): def _name_self_CA(): ca_conf = os.path.join(SSL_DIR, "openssl.ca.cnf") - try : - with open(ca_conf) as f: - lines = f.readlines() + if not os.path.exists(ca_conf) : + logger.warning(m18n.n('certmanager_self_ca_conf_file_not_found', file=ca_conf)) + return "" - for line in lines: - if line.startswith("commonName_default"): - return line.split()[2] - except: - pass + with open(ca_conf) as f: + lines = f.readlines() - logger.warning(m18n.n('certmanager_unable_to_determine_self_CA_name')) + for line in lines: + if line.startswith("commonName_default"): + return line.split()[2] + + logger.warning(m18n.n('certmanager_unable_to_parse_self_CA_name', file=ca_conf)) return ""