]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/mgr_util: fixing some tox issues 49635/head
authorRedouane Kachach <rkachach@redhat.com>
Wed, 14 Dec 2022 10:06:25 +0000 (11:06 +0100)
committerRedouane Kachach <rkachach@redhat.com>
Thu, 5 Jan 2023 10:22:13 +0000 (11:22 +0100)
Fixes: https://tracker.ceph.com/issues/58378
Signed-off-by: Redouane Kachach <rkachach@redhat.com>
src/pybind/mgr/mgr_util.py
src/pybind/mgr/tox.ini

index 2424e3adab0c119fb4a61931d577db40d8bb4423..8c1e5be44161b74da8647592ab62703019349c77 100644 (file)
@@ -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))
index 85e7ae3db11bb84cbb6f892e14199ab98873d43d..aaabd7ba6404b698a37a406a08d9337e2b256e49 100644 (file)
@@ -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} \