]> git.ipfire.org Git - pbs.git/commitdiff
backend: Load SSL context from certificate files
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 Feb 2025 15:23:37 +0000 (15:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 Feb 2025 15:24:18 +0000 (15:24 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/__init__.py
src/scripts/pakfire-build-service

index ca3e5e8f83550a7d5b461d515b5adf8e5e1d4504..ac6e89b2fb1ddbcd26fbc5136720141aef989641 100644 (file)
@@ -481,39 +481,25 @@ class Backend(object):
 
        @property
        def ssl_context(self):
+               """
+                       Returns a SSL context with our client certificate
+               """
                # Create SSL context
                context = ssl.create_default_context()
 
                # Fetch client certificate
-               certificate = self.settings.get("client-certificate", None)
-               key         = self.settings.get("client-key", None)
-
-               # Apply client certificate
-               if certificate and key:
-                       with tempfile.NamedTemporaryFile(mode="w") as f_cert:
-                               f_cert.write(certificate)
-                               f_cert.flush()
+               certificate = self.config.get("ssl", "certificate")
+               key         = self.config.get("ssl", "key")
 
-                               with tempfile.NamedTemporaryFile(mode="w") as f_key:
-                                       f_key.write(key)
-                                       f_key.flush()
+               # Raise an error if we don't have certificates
+               if not certificate or not key:
+                       raise RuntimeError("Missing SSL configuration")
 
-                                       context.load_cert_chain(f_cert.name, f_key.name)
+               # Load the certificate chain
+               context.load_cert_chain(certificate, key)
 
                return context
 
-       async def load_certificate(self, certfile, keyfile):
-               with self.db.transaction():
-                       # Load certificate
-                       with open(certfile) as f:
-                               self.settings.set("client-certificate", f.read())
-
-                       # Load key file
-                       with open(keyfile) as f:
-                               self.settings.set("client-key", f.read())
-
-                       log.info("Updated certificates")
-
        async def cleanup(self):
                """
                        Called regularly to cleanup any left-over resources
index bb407e81f4ece49832d0f7c964599c20c8dbed44..12e23d8b2f435ecb5f5c59092601d12e2f5607c2 100644 (file)
@@ -24,9 +24,6 @@ class Cli(object):
                        # Builders
                        "builders:autoscale"  : self.backend.builders.autoscale,
 
-                       # Certificates
-                       "load-certificate"    : self.backend.load_certificate,
-
                        # Cleanup
                        "cleanup"             : self.backend.cleanup,