From: Redouane Kachach Date: Wed, 14 Dec 2022 10:06:25 +0000 (+0100) Subject: mgr/mgr_util: fixing some tox issues X-Git-Tag: v18.1.0~532^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=d359d75f861ec7c289587679ee30221e5e9a843f;p=ceph.git mgr/mgr_util: fixing some tox issues Fixes: https://tracker.ceph.com/issues/58378 Signed-off-by: Redouane Kachach --- diff --git a/src/pybind/mgr/mgr_util.py b/src/pybind/mgr/mgr_util.py index 2424e3adab0c1..8c1e5be44161b 100644 --- a/src/pybind/mgr/mgr_util.py +++ b/src/pybind/mgr/mgr_util.py @@ -575,10 +575,14 @@ def verify_cacrt_content(crt): # type: (str) -> None from OpenSSL import crypto try: - x509 = crypto.load_certificate(crypto.FILETYPE_PEM, crt) + crt_buffer = crt.encode("ascii") if isinstance(crt, str) else crt + x509 = crypto.load_certificate(crypto.FILETYPE_PEM, crt_buffer) if x509.has_expired(): org, cn = get_cert_issuer_info(crt) - end_date = datetime.datetime.strptime(x509.get_notAfter().decode('ascii'), '%Y%m%d%H%M%SZ') + no_after = x509.get_notAfter() + end_date = None + if no_after is not None: + end_date = datetime.datetime.strptime(no_after.decode('ascii'), '%Y%m%d%H%M%SZ') msg = f'Certificate issued by "{org}/{cn}" expired on {end_date}' logger.warning(msg) raise ServerConfigException(msg) @@ -607,8 +611,9 @@ def get_cert_issuer_info(crt: str) -> Tuple[Optional[str],Optional[str]]: from OpenSSL import crypto, SSL try: + crt_buffer = crt.encode("ascii") if isinstance(crt, str) else crt (org_name, cn) = (None, None) - cert = crypto.load_certificate(crypto.FILETYPE_PEM, crt) + cert = crypto.load_certificate(crypto.FILETYPE_PEM, crt_buffer) components = cert.get_issuer().get_components() for c in components: if c[0].decode() == 'O': # org comp @@ -631,7 +636,8 @@ def verify_tls(crt, key): raise ServerConfigException( 'Invalid private key: {}'.format(str(e))) try: - _crt = crypto.load_certificate(crypto.FILETYPE_PEM, crt) + crt_buffer = crt.encode("ascii") if isinstance(crt, str) else crt + _crt = crypto.load_certificate(crypto.FILETYPE_PEM, crt_buffer) except ValueError as e: raise ServerConfigException( 'Invalid certificate key: {}'.format(str(e)) diff --git a/src/pybind/mgr/tox.ini b/src/pybind/mgr/tox.ini index 85e7ae3db11bb..aaabd7ba6404b 100644 --- a/src/pybind/mgr/tox.ini +++ b/src/pybind/mgr/tox.ini @@ -158,20 +158,20 @@ deps = flake8 allowlist_externals = bash modules = - alerts - balancer - cephadm - cli_api - crash - devicehealth - diskprediction_local - hello - iostat - localpool - nfs - orchestrator - prometheus - rbd_support + alerts \ + balancer \ + cephadm \ + cli_api \ + crash \ + devicehealth \ + diskprediction_local \ + hello \ + iostat \ + localpool \ + nfs \ + orchestrator \ + prometheus \ + rbd_support \ selftest commands = flake8 --config=tox.ini {posargs} \