import os
import pakfire
import shutil
+import ssl
import systemd.journal
import tempfile
import urllib.parse
# Open the archive
return p.open(path)
+ @property
+ def ssl_context(self):
+ # 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()
+
+ with tempfile.NamedTemporaryFile(mode="w") as f_key:
+ f_key.write(key)
+ f_key.flush()
+
+ context.load_cert_chain(f_cert.name, f_key.name)
+
+ 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
# Bugzilla
"bugzilla:version" : self.backend.bugzilla.version,
+ # Certificates
+ "load-certificate" : self.backend.load_certificate,
+
# Cleanup
"cleanup" : self.backend.cleanup,