Blame SOURCES/0001-Do-not-use-default-values-that-need-reading-the-conf.patch

1b831e
From d6dd71e3a3fe8e822fbcaa0d88f19a0c3332cacd Mon Sep 17 00:00:00 2001
1b831e
From: Sergio Correia <scorreia@redhat.com>
1b831e
Date: Tue, 15 Nov 2022 07:09:13 -0300
1b831e
Subject: [PATCH] Do not use default values that need reading the config in
1b831e
 methods
1b831e
1b831e
Following up from the recent refactoring that moved the EK validation
1b831e
to cert_utils, in a few places were added default method values that
1b831e
were reading the configuration files directly.
1b831e
1b831e
It was not such a great idea becasue it then made those config files as
1b831e
required to even import the modules.
1b831e
1b831e
Example "from keylime import cert_utils" now also requires that the
1b831e
tenant configuration be available for getting the path for the TPM
1b831e
cert store.
1b831e
1b831e
Let's stop doing that.
1b831e
1b831e
Signed-off-by: Sergio Correia <scorreia@redhat.com>
1b831e
---
1b831e
 keylime/cert_utils.py       | 5 +++--
1b831e
 keylime/tenant.py           | 2 +-
1b831e
 keylime/tpm/tpm_abstract.py | 2 +-
1b831e
 keylime/tpm/tpm_main.py     | 4 ++--
1b831e
 keylime/tpm_ek_ca.py        | 6 +++---
1b831e
 5 files changed, 10 insertions(+), 9 deletions(-)
1b831e
1b831e
diff --git a/keylime/cert_utils.py b/keylime/cert_utils.py
1b831e
index d2fc54d..3576c64 100644
1b831e
--- a/keylime/cert_utils.py
1b831e
+++ b/keylime/cert_utils.py
1b831e
@@ -12,7 +12,7 @@ from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
1b831e
 from pyasn1.codec.der import decoder, encoder
1b831e
 from pyasn1_modules import pem, rfc2459
1b831e
 
1b831e
-from keylime import config, keylime_logging, tpm_ek_ca
1b831e
+from keylime import keylime_logging, tpm_ek_ca
1b831e
 
1b831e
 # Issue #944 -- python-cryptography won't parse malformed certs,
1b831e
 # such as some Nuvoton ones we have encountered in the field.
1b831e
@@ -56,9 +56,10 @@ def x509_pem_cert(pem_cert_data: str):
1b831e
         return x509.load_der_x509_certificate(data=encoder.encode(pyasn1_cert), backend=default_backend())
1b831e
 
1b831e
 
1b831e
-def verify_ek(ekcert, tpm_cert_store=config.get("tenant", "tpm_cert_store")):
1b831e
+def verify_ek(ekcert: bytes, tpm_cert_store: str) -> bool:
1b831e
     """Verify that the provided EK certificate is signed by a trusted root
1b831e
     :param ekcert: The Endorsement Key certificate in DER format
1b831e
+    :param tpm_cert_store: The path for the TPM certificate store
1b831e
     :returns: True if the certificate can be verified, False otherwise
1b831e
     """
1b831e
     try:
1b831e
diff --git a/keylime/tenant.py b/keylime/tenant.py
1b831e
index b574d04..076b849 100644
1b831e
--- a/keylime/tenant.py
1b831e
+++ b/keylime/tenant.py
1b831e
@@ -430,7 +430,7 @@ class Tenant:
1b831e
             elif ekcert is None:
1b831e
                 logger.warning("No EK cert provided, require_ek_cert option in config set to True")
1b831e
                 return False
1b831e
-            elif not self.tpm_instance.verify_ek(base64.b64decode(ekcert)):
1b831e
+            elif not self.tpm_instance.verify_ek(base64.b64decode(ekcert), config.get("tenant", "tpm_cert_store")):
1b831e
                 logger.warning("Invalid EK certificate")
1b831e
                 return False
1b831e
 
1b831e
diff --git a/keylime/tpm/tpm_abstract.py b/keylime/tpm/tpm_abstract.py
1b831e
index ff41837..df6222c 100644
1b831e
--- a/keylime/tpm/tpm_abstract.py
1b831e
+++ b/keylime/tpm/tpm_abstract.py
1b831e
@@ -97,7 +97,7 @@ class AbstractTPM(metaclass=ABCMeta):
1b831e
         pass
1b831e
 
1b831e
     @abstractmethod
1b831e
-    def verify_ek(self, ekcert):
1b831e
+    def verify_ek(self, ekcert, tpm_cert_store):
1b831e
         pass
1b831e
 
1b831e
     @abstractmethod
1b831e
diff --git a/keylime/tpm/tpm_main.py b/keylime/tpm/tpm_main.py
1b831e
index e1d1cf8..e244dfa 100644
1b831e
--- a/keylime/tpm/tpm_main.py
1b831e
+++ b/keylime/tpm/tpm_main.py
1b831e
@@ -776,12 +776,12 @@ class tpm(tpm_abstract.AbstractTPM):
1b831e
                 os.remove(sesspath)
1b831e
         return key
1b831e
 
1b831e
-    def verify_ek(self, ekcert):
1b831e
+    def verify_ek(self, ekcert, tpm_cert_store):
1b831e
         """Verify that the provided EK certificate is signed by a trusted root
1b831e
         :param ekcert: The Endorsement Key certificate in DER format
1b831e
         :returns: True if the certificate can be verified, false otherwise
1b831e
         """
1b831e
-        return cert_utils.verify_ek(ekcert)
1b831e
+        return cert_utils.verify_ek(ekcert, tpm_cert_store)
1b831e
 
1b831e
     def get_tpm_manufacturer(self, output=None):
1b831e
         vendorStr = None
1b831e
diff --git a/keylime/tpm_ek_ca.py b/keylime/tpm_ek_ca.py
1b831e
index fb66c07..bc84571 100644
1b831e
--- a/keylime/tpm_ek_ca.py
1b831e
+++ b/keylime/tpm_ek_ca.py
1b831e
@@ -1,13 +1,13 @@
1b831e
 import glob
1b831e
 import os
1b831e
 
1b831e
-from keylime import config, keylime_logging
1b831e
+from keylime import keylime_logging
1b831e
 
1b831e
 logger = keylime_logging.init_logging("tpm_ek_ca")
1b831e
 trusted_certs = {}
1b831e
 
1b831e
 
1b831e
-def check_tpm_cert_store(tpm_cert_store=config.get("tenant", "tpm_cert_store")):
1b831e
+def check_tpm_cert_store(tpm_cert_store):
1b831e
     if not os.path.isdir(tpm_cert_store):
1b831e
         logger.error("The directory %s does not exist.", tpm_cert_store)
1b831e
         raise Exception(f"The directory {tpm_cert_store} does not exist.")
1b831e
@@ -20,7 +20,7 @@ def check_tpm_cert_store(tpm_cert_store=config.get("tenant", "tpm_cert_store")):
1b831e
         raise Exception(f"The directory {tpm_cert_store} does not contain " f"any .pem files")
1b831e
 
1b831e
 
1b831e
-def cert_loader(tpm_cert_store=config.get("tenant", "tpm_cert_store")):
1b831e
+def cert_loader(tpm_cert_store):
1b831e
     file_list = glob.glob(os.path.join(tpm_cert_store, "*.pem"))
1b831e
     my_trusted_certs = {}
1b831e
     for file_path in file_list:
1b831e
-- 
1b831e
2.38.1
1b831e