Commit f6b0d909 authored by segfault's avatar segfault

Fix Mumble

- Use MountPoint.host_path instead of MountPoint.target
- Fix missing return if TLS certificate not found
- Minor code cleanup
parent ba67c9ff
......@@ -21,9 +21,17 @@ from onionkit.mountpoint import MountPoint
logger = getLogger(__name__)
FINGERPRINT_LOADING_TIMEOUT = 2
DB_NAME = "mumble-server.sqlite"
data_dir = Path("/var/lib/mumble-server/")
db_file = Path(data_dir, "mumble-server.sqlite")
class DataDir(MountPoint):
source = Path("data")
target = Path("/var/lib/mumble-server")
owner = "mumble-server"
group = "mumble-server"
is_dir = True
data_dir = DataDir()
class MumbleConfigFile(DataFile, MountPoint):
......@@ -34,8 +42,7 @@ class MumbleConfigFile(DataFile, MountPoint):
@property
def default_content(self) -> str:
return self.target.read_text()
return self.source.read_text()
config_file = MumbleConfigFile()
......@@ -105,25 +112,26 @@ class TLSFingerprint(option.OnionServiceOption):
raise ReadOnlyOptionError("Option %r can't be modified" % self.Name)
def load(self) -> str:
db_file = Path(data_dir.source, DB_NAME)
if not db_file.exists():
logger.warning("Could not load TLS certificate of service %r: No such file: %s", self.service.Name, db_file)
return str()
connection = sqlite3.connect(str(db_file))
c = connection.cursor()
cursor = sqlite3.connect(str(db_file)).cursor()
cert_row = None
start_time = loop_time = time.perf_counter()
while loop_time - start_time < FINGERPRINT_LOADING_TIMEOUT:
c.execute("SELECT value FROM config WHERE key = 'certificate'")
cert_row = c.fetchone()
start_time = time.perf_counter()
while time.perf_counter() - start_time < FINGERPRINT_LOADING_TIMEOUT:
cursor.execute("SELECT value FROM config WHERE key = 'certificate'")
cert_row = cursor.fetchone()
if cert_row:
break
time.sleep(0.01)
loop_time = time.perf_counter()
time.sleep(0.1)
if not cert_row:
logger.warning("Could not load TLS Certificate of service %r: No certificate in database %r",
self.service.Name, db_file)
logger.warning("Could not load TLS Certificate of service %r: No certificate in database %s (timeout %s)",
self.service.Name, db_file, FINGERPRINT_LOADING_TIMEOUT)
return str()
cert_string = cert_row[0]
cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert_string)
return cert.digest("sha1").decode()
......@@ -158,7 +166,7 @@ class MumbleServer(OnionService):
data_files = [
config_file,
MountPoint(source=Path("data"), target=data_dir, owner="mumble-server", group="mumble-server", is_dir=True)
data_dir
]
def configure_options(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment