diff --git a/cmd/package b/cmd/package index cdc7cc8cf..d45e86b4f 100755 --- a/cmd/package +++ b/cmd/package @@ -17,7 +17,7 @@ # Creates a package for Testrun MAKE_SRC_DIR=make -TESTRUN_VER="1-2-2" +TESTRUN_VER="1-3-alpha" # Delete existing make files rm -rf $MAKE_SRC_DIR/usr diff --git a/framework/python/src/api/api.py b/framework/python/src/api/api.py index f97e564d3..450c76bd8 100644 --- a/framework/python/src/api/api.py +++ b/framework/python/src/api/api.py @@ -645,9 +645,12 @@ async def upload_cert(self, # Get file contents contents = await file.read() - # Pass to session to check and write - cert_obj = self._session.upload_cert(filename, - contents) + try: + # Pass to session to check and write + cert_obj = self._session.upload_cert(filename, + contents) + except IOError: + LOGGER.error("An error occurred whilst uploading the certificate") # Return error if something went wrong if cert_obj is None: diff --git a/framework/python/src/common/session.py b/framework/python/src/common/session.py index bce74754e..7160c8f84 100644 --- a/framework/python/src/common/session.py +++ b/framework/python/src/common/session.py @@ -15,6 +15,7 @@ """Track testing status.""" import copy import datetime +import pytz import json import os from common import util, logger @@ -389,6 +390,8 @@ def get_timezone(self): def upload_cert(self, filename, content): + now = datetime.datetime.now(pytz.utc) + try: # Parse bytes into x509 object cert = x509.load_pem_x509_certificate(content, default_backend()) @@ -399,9 +402,14 @@ def upload_cert(self, filename, content): issuer = cert.issuer.get_attributes_for_oid( NameOID.ORGANIZATION_NAME)[0].value + status = 'Valid' + if now > cert.not_valid_after_utc: + status = 'Expired' + # Craft python dictionary with values cert_obj = { 'name': common_name, + 'status': status, 'organisation': issuer, 'expires': cert.not_valid_after_utc, 'filename': filename @@ -430,6 +438,8 @@ def load_certs(self): LOGGER.debug(f'Loading certificates from {CERTS_PATH}') + now = datetime.datetime.now(pytz.utc) + self._certs = [] for cert_file in os.listdir(CERTS_PATH): @@ -450,9 +460,14 @@ def load_certs(self): issuer = cert.issuer.get_attributes_for_oid( NameOID.ORGANIZATION_NAME)[0].value + status = 'Valid' + if now > cert.not_valid_after_utc: + status = 'Expired' + # Craft python dictionary with values cert_obj = { 'name': common_name, + 'status': status, 'organisation': issuer, 'expires': cert.not_valid_after_utc, 'filename': cert_file diff --git a/framework/requirements.txt b/framework/requirements.txt index bf6a9bb95..3989c3b74 100644 --- a/framework/requirements.txt +++ b/framework/requirements.txt @@ -26,3 +26,4 @@ markdown==3.5.2 # Requirements for the session cryptography==42.0.7 +pytz==2024.1 \ No newline at end of file diff --git a/make/DEBIAN/control b/make/DEBIAN/control index dff4ce378..9ea73aaa1 100644 --- a/make/DEBIAN/control +++ b/make/DEBIAN/control @@ -1,5 +1,5 @@ Package: Testrun -Version: 1.2.2 +Version: 1.3-alpha Architecture: amd64 Maintainer: Google Homepage: https://github.com/google/testrun