diff --git a/.gitea/workflows/nexjast-ci.yml b/.gitea/workflows/nexjast-ci.yml
index e7315dd6..d9cd6c9a 100644
--- a/.gitea/workflows/nexjast-ci.yml
+++ b/.gitea/workflows/nexjast-ci.yml
@@ -993,7 +993,7 @@ jobs:
python3 tools/ci/verify_os_webinterface.py
dotnet build addons/OSWebInterface/os_webinterface.csproj --configuration Release --no-restore
dotnet run --project tools/ci/OSWebInterfaceSmoke/OSWebInterfaceSmoke.csproj --configuration Release
- dotnet run --project tools/ci/WebDavBackupRegression/WebDavBackupRegression.csproj --configuration Release
+ python3 tools/ci/verify_webdav_private_dll.py
- name: Verify Generation 1 approved-viewer admission policy
shell: bash
diff --git a/.gitignore b/.gitignore
index 586240d9..69816bf8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -105,3 +105,8 @@ bin/opt/
# Per-project SDK output of addons and CI/ops tools
/addons/*/bin/
/tools/**/bin/
+
+# Host-private WebDAV credential assembly (never publish)
+[Oo]gl.[Ww]eb[Dd]av.[Pp]rivate.*
+webdav.credentials
+.webdav-build-*/
diff --git a/addons/OSWebInterface/WebDavBackupStore.cs b/addons/OSWebInterface/WebDavBackupStore.cs
index 4b28e1b3..6cab3300 100644
--- a/addons/OSWebInterface/WebDavBackupStore.cs
+++ b/addons/OSWebInterface/WebDavBackupStore.cs
@@ -2,6 +2,9 @@
using System.Globalization;
using System.Net;
using System.Net.Http.Headers;
+using System.Reflection;
+using System.Reflection.Metadata;
+using System.Reflection.PortableExecutable;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
@@ -12,7 +15,7 @@ namespace OpenGenesisLINK.Addons.OSWebInterface;
/// Fixed, server-side HTTPS backup destination. Never exposes NAS credentials to the browser.
internal sealed class WebDavBackupStore : IDisposable
{
- internal const string CredentialPath = "/etc/opengenesislink/private/webdav.credentials";
+ internal const string CredentialPath = "/etc/opengenesislink/private/Ogl.WebDav.Private.dll";
private static readonly Uri Destination = new("https://s3.stadt-nexverse.de:5006/ogl-backup/");
private static readonly Regex OarName = new(@"^[a-zA-Z0-9_-]{1,60}--[0-9a-f]{32}--[0-9]{8}T[0-9]{6}Z--[0-9a-f]{32}\.oar\z", RegexOptions.CultureInvariant);
private static readonly Regex IarName = new(@"^avatar-[0-9a-f]{32}\.iar\z", RegexOptions.CultureInvariant);
@@ -51,25 +54,83 @@ internal sealed class WebDavBackupStore : IDisposable
try
{
var info = new FileInfo(CredentialPath);
- if (!info.Exists || info.LinkTarget != null || info.Length is < 3 or > 4096 ||
- !OperatingSystem.IsLinux() ||
- (File.GetUnixFileMode(CredentialPath) & (UnixFileMode.GroupRead | UnixFileMode.GroupWrite |
- UnixFileMode.GroupExecute | UnixFileMode.OtherRead | UnixFileMode.OtherWrite |
- UnixFileMode.OtherExecute)) != 0)
- throw new IOException("Private credential file unavailable");
- string[] lines = File.ReadAllLines(CredentialPath);
- if (lines.Length != 2 || string.IsNullOrWhiteSpace(lines[0]) ||
- lines[0].Contains(':') || string.IsNullOrEmpty(lines[1]))
- throw new IOException("Private credential file incomplete");
- return new AuthenticationHeaderValue("Basic",
- Convert.ToBase64String(Encoding.UTF8.GetBytes(lines[0] + ":" + lines[1])));
+ var directory = info.Directory!;
+ if (!OperatingSystem.IsLinux() || !info.Exists || info.LinkTarget != null ||
+ directory.LinkTarget != null || info.Length is < 512 or > 1024 * 1024 ||
+ !IsPrivate(File.GetUnixFileMode(CredentialPath)) ||
+ !IsPrivate(File.GetUnixFileMode(directory.FullName)))
+ throw new IOException("Private WebDAV DLL unavailable");
+ using var input = new FileStream(CredentialPath, FileMode.Open, FileAccess.Read,
+ FileShare.Read | FileShare.Delete);
+ return ReadPrivateAssembly(input);
}
- catch (Exception e) when (e is IOException or UnauthorizedAccessException)
+ catch (Exception e) when (e is IOException or UnauthorizedAccessException or
+ BadImageFormatException or InvalidOperationException or ArgumentException)
{
- throw new BackupException(503, "WebDAV-Zugang ist serverseitig noch nicht eingerichtet.");
+ // Do not log exception details or any metadata values.
+ throw new BackupException(503, "Private WebDAV-DLL fehlt, ist ungültig oder nicht geschützt.");
}
}
+ private static bool IsPrivate(UnixFileMode mode) =>
+ (mode & (UnixFileMode.GroupRead | UnixFileMode.GroupWrite | UnixFileMode.GroupExecute |
+ UnixFileMode.OtherRead | UnixFileMode.OtherWrite | UnixFileMode.OtherExecute)) == 0;
+
+ // Read literal string constants from managed DLL metadata. The private
+ // assembly is never loaded/executed; replacing it is effective on the next
+ // request without leaking credentials into a public assembly or INI.
+ internal static AuthenticationHeaderValue ReadPrivateAssembly(Stream input)
+ {
+ using var pe = new PEReader(input, PEStreamOptions.LeaveOpen);
+ if (!pe.HasMetadata) throw new BadImageFormatException();
+ var md = pe.GetMetadataReader();
+ if (!md.IsAssembly ||
+ md.GetString(md.GetAssemblyDefinition().Name) != "Ogl.WebDav.Private")
+ throw new BadImageFormatException();
+ string? user = null, password = null;
+ bool found = false;
+ foreach (var handle in md.TypeDefinitions)
+ {
+ var type = md.GetTypeDefinition(handle);
+ if (md.GetString(type.Namespace) != "Ogl.Private" ||
+ md.GetString(type.Name) != "WebDavCredentials") continue;
+ if (found) throw new BadImageFormatException();
+ found = true;
+ foreach (var fieldHandle in type.GetFields())
+ {
+ var field = md.GetFieldDefinition(fieldHandle);
+ string name = md.GetString(field.Name);
+ if (name != "Username" && name != "Password") continue;
+ if ((field.Attributes & (FieldAttributes.Literal | FieldAttributes.Static)) !=
+ (FieldAttributes.Literal | FieldAttributes.Static) || field.GetDefaultValue().IsNil)
+ throw new BadImageFormatException();
+ var constant = md.GetConstant(field.GetDefaultValue());
+ if (constant.TypeCode != ConstantTypeCode.String)
+ throw new BadImageFormatException();
+ var blob = md.GetBlobReader(constant.Value);
+ if (blob.Length > 8192 || blob.Length % 2 != 0)
+ throw new BadImageFormatException();
+ string value = blob.ReadUTF16(blob.Length);
+ if (name == "Username")
+ {
+ if (user != null) throw new BadImageFormatException();
+ user = value;
+ }
+ else
+ {
+ if (password != null) throw new BadImageFormatException();
+ password = value;
+ }
+ }
+ }
+ if (string.IsNullOrWhiteSpace(user) || user.Contains(':') ||
+ string.IsNullOrEmpty(password) || user.Any(char.IsControl) ||
+ password.Any(char.IsControl))
+ throw new BadImageFormatException();
+ return new AuthenticationHeaderValue("Basic",
+ Convert.ToBase64String(Encoding.UTF8.GetBytes(user + ":" + password)));
+ }
+
internal void EnsureConfigured() => _ = _authentication();
private static string Folder(string kind) => kind switch
{
diff --git a/doc/OpenGenesisLINK/GEN1_WEBDAV_BACKUPS.md b/doc/OpenGenesisLINK/GEN1_WEBDAV_BACKUPS.md
index df39e226..ff6c5c52 100644
--- a/doc/OpenGenesisLINK/GEN1_WEBDAV_BACKUPS.md
+++ b/doc/OpenGenesisLINK/GEN1_WEBDAV_BACKUPS.md
@@ -6,19 +6,25 @@ https://s3.stadt-nexverse.de:5006/ogl-backup/
Die Zieladresse ist fest im Modul definiert. Zugangsdaten sind ausschließlich serverseitig verfügbar; keine INI-Einstellung und keine Browser-Eingabe nötig.
-## Einmalige Installation der Zugangsdaten
+## Einmalige Installation der privaten Zugangsdaten-DLL
-Auf dem Simulator-Host als root im Terminal (nicht im Chat, Git, Shell-Verlauf oder in einer öffentlich ausgelieferten Datei):
+Auf dem Simulator-Host als root im Terminal:
- install -d -m 700 /etc/opengenesislink/private
- umask 077
- read -rp "WebDAV-Benutzer: " DAV_USER
- read -rsp "WebDAV-Passwort: " DAV_PASS; echo
- printf '%s\n%s\n' "$DAV_USER" "$DAV_PASS" > /etc/opengenesislink/private/webdav.credentials
- chmod 600 /etc/opengenesislink/private/webdav.credentials
- unset DAV_USER DAV_PASS
+ python3 tools/ops/ogl-install-private-webdav-dll.py
-Das Modul prüft Dateirechte und TLS-Zertifikate. Der Benutzer benötigt nur Lesen/Schreiben/MOVE/MKCOL im freigegebenen Backup-Ordner. Keine Zertifikatsprüfung deaktivieren. Bei fehlenden Zugangsdaten wird der Export mit einer klaren Fehlermeldung abgelehnt. Die Datei enthält ein wiederverwendbares Passwort; bei Rotation reicht es, sie zu aktualisieren.
+Benutzer und Passwort werden interaktiv eingegeben. Der Installer erstellt
+/etc/opengenesislink/private/Ogl.WebDav.Private.dll (0600, Verzeichnis 0700).
+Die Zugangsdaten sind feste DLL-Konstanten, keine INI-Einstellungen.
+Die öffentliche Simulator-DLL liest ausschließlich die Metadaten der privaten
+Assembly und führt keinen Code aus ihr aus. Beide Simulatorprozesse nutzen
+denselben absoluten Pfad. Änderungen sind beim nächsten WebDAV-Aufruf wirksam.
+
+Die private DLL ist nicht verschlüsselt: Jeder mit Dateizugriff könnte die
+Konstanten lesen. Sie bleibt außerhalb des Repositorys und aller bin-Verzeichnisse,
+wird von den Release-Packagern ausgeschlossen und darf nicht weitergegeben werden.
+Bei fehlender oder falsch geschützter DLL wird die Backup-Funktion abgelehnt.
+Der Benutzer benötigt Lesen/Schreiben/MOVE/MKCOL im freigegebenen Backup-Ordner.
+TLS-Zertifikate werden geprüft; keine Abschaltung der Prüfung.
## Archivierung und Wiederherstellung
diff --git a/tools/ci/WebDavBackupRegression/Program.cs b/tools/ci/WebDavBackupRegression/Program.cs
index e2410cbd..dbe46ac2 100644
--- a/tools/ci/WebDavBackupRegression/Program.cs
+++ b/tools/ci/WebDavBackupRegression/Program.cs
@@ -14,6 +14,21 @@ static async Task Reject(Func action, string message)
catch (WebDavBackupStore.BackupException) { return; }
throw new Exception(message);
}
+if (args.Length == 2 && args[0] == "--private-fixture")
+{
+ using var fixture = File.OpenRead(args[1]);
+ var header = WebDavBackupStore.ReadPrivateAssembly(fixture);
+ Check(header.Scheme == "Basic" && header.Parameter == Convert.ToBase64String(
+ System.Text.Encoding.UTF8.GetBytes("fixture-user:fixture-only-password")), "Private DLL metadata mismatch");
+ Console.WriteLine("Private DLL metadata regression PASS");
+}
+try
+{
+ using var invalid = new MemoryStream(new byte[512]);
+ _ = WebDavBackupStore.ReadPrivateAssembly(invalid);
+ throw new Exception("Invalid private DLL accepted");
+}
+catch (BadImageFormatException) { }
var root = new Uri("https://backup.example.test/ogl-backup/");
using var handler = new MockDav(root);
using var store = new WebDavBackupStore(new HttpClient(handler), root,
diff --git a/tools/ci/verify_webdav_private_dll.py b/tools/ci/verify_webdav_private_dll.py
new file mode 100644
index 00000000..f449a154
--- /dev/null
+++ b/tools/ci/verify_webdav_private_dll.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+"""Exercise private assembly generation with non-sensitive fixture values only."""
+import importlib.util
+import os
+from pathlib import Path
+import subprocess
+import tempfile
+
+ROOT = Path(__file__).resolve().parents[2]
+
+
+def load(name, path):
+ spec = importlib.util.spec_from_file_location(name, ROOT / path)
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ return module
+
+
+def main():
+ builder = load("private_builder", "tools/ops/ogl-install-private-webdav-dll.py")
+ zip_packager = load("zip_packager", "tools/release/ogl_gen1_snapshot_zip.py")
+ stage_packager = load("stage_packager", "tools/gen11/stage_net10_runtime.py")
+ with tempfile.TemporaryDirectory(prefix="ogl-webdav-fixture-") as directory:
+ root = Path(directory)
+ builder.build_private_assembly(root, "fixture-user", "fixture-only-password")
+ fixture = root / builder.NAME
+ assert fixture.stat().st_mode & 0o777 == 0o600
+ assert not zip_packager.allowed(Path(builder.NAME))
+ assert not zip_packager.allowed(Path("nested") / builder.NAME.upper())
+ assert not stage_packager.allow_root(builder.NAME)
+ subprocess.run(["dotnet", "run", "--project",
+ str(ROOT / "tools/ci/WebDavBackupRegression/WebDavBackupRegression.csproj"),
+ "--configuration", "Release", "--",
+ "--private-fixture", str(fixture)], check=True)
+ print("Private WebDAV DLL packaging exclusions PASS")
+
+
+if __name__ == "__main__":
+ os.umask(0o077)
+ main()
diff --git a/tools/gen11/stage_net10_runtime.py b/tools/gen11/stage_net10_runtime.py
index 6551f848..731acefb 100644
--- a/tools/gen11/stage_net10_runtime.py
+++ b/tools/gen11/stage_net10_runtime.py
@@ -60,6 +60,8 @@ def allow_native(name: str, rid: str) -> bool:
def allow_root(name: str) -> bool:
lower = name.lower()
+ if lower.startswith("ogl.webdav.private.") or lower == "webdav.credentials":
+ return False
if lower.endswith(".dll") and not lower.endswith(".tests.dll"):
return True
if lower.endswith((".dll.config", ".exe.config", ".runtimeconfig.json", ".deps.json")):
@@ -76,6 +78,8 @@ def allow_root(name: str) -> bool:
def copy(source: Path, dest: Path) -> None:
+ if source.name.lower().startswith("ogl.webdav.private.") or source.name.lower() == "webdav.credentials":
+ raise ValueError("Private WebDAV material must not be staged")
if source.is_symlink():
raise ValueError(f"Symlinks are not allowed in staging: {source}")
if not source.is_file():
diff --git a/tools/ops/ogl-install-private-webdav-dll.py b/tools/ops/ogl-install-private-webdav-dll.py
new file mode 100755
index 00000000..9925a6a6
--- /dev/null
+++ b/tools/ops/ogl-install-private-webdav-dll.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python3
+"""Build a host-local credential assembly without Git, command-line or log secrets."""
+import getpass
+import json
+import os
+from pathlib import Path
+import stat
+import subprocess
+import sys
+import tempfile
+
+ROOT = Path("/etc/opengenesislink/private")
+NAME = "Ogl.WebDav.Private.dll"
+
+
+def build_private_assembly(root, username, password):
+ if (not username.strip() or ":" in username or not password or
+ any(ord(c) < 32 or ord(c) == 127 for c in username + password) or
+ len(username) > 1024 or len(password) > 4096):
+ raise ValueError("Invalid WebDAV credentials")
+ root.mkdir(mode=0o700, parents=True, exist_ok=True)
+ st = root.lstat()
+ if not stat.S_ISDIR(st.st_mode) or st.st_uid != os.geteuid() or st.st_mode & 0o077:
+ raise PermissionError("Private directory must be owned by installer and mode 0700")
+ # Build inputs and all compiler outputs stay under the private directory.
+ # No password in argv, environment, stdout, or repository.
+ with tempfile.TemporaryDirectory(prefix=".webdav-build-", dir=root) as tmp:
+ work = Path(tmp)
+ (work / "Private.csproj").write_text(
+ ''
+ 'net10.0'
+ 'Ogl.WebDav.Private'
+ 'nonefalse'
+ 'false'
+ '', encoding="utf-8")
+ (work / "WebDavCredentials.cs").write_text(
+ "namespace Ogl.Private { internal static class WebDavCredentials { "
+ "internal const string Username = " + json.dumps(username, ensure_ascii=True) + "; "
+ "internal const string Password = " + json.dumps(password, ensure_ascii=True) + "; } }",
+ encoding="utf-8")
+ result = subprocess.run(
+ ["dotnet", "build", "Private.csproj", "-c", "Release", "--nologo",
+ "--disable-build-servers", "-o", "out"],
+ cwd=work, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
+ timeout=120, env={**os.environ, "DOTNET_CLI_TELEMETRY_OPTOUT": "1"})
+ if result.returncode:
+ raise RuntimeError("Private DLL build failed; previous DLL unchanged")
+ output = work / "out" / NAME
+ if not output.is_file() or output.stat().st_size < 512:
+ raise RuntimeError("Private DLL output missing")
+ output.chmod(0o600)
+ os.replace(output, root / NAME)
+
+
+def main():
+ if os.geteuid() != 0 or not sys.stdin.isatty():
+ raise SystemExit("Run interactively as root on the simulator host.")
+ os.umask(0o077)
+ username = input("WebDAV-Benutzer: ").strip()
+ password = getpass.getpass("WebDAV-Passwort: ")
+ confirmation = getpass.getpass("WebDAV-Passwort wiederholen: ")
+ if password != confirmation:
+ raise SystemExit("Passwörter stimmen nicht überein; keine Änderung.")
+ try:
+ build_private_assembly(ROOT, username, password)
+ except (ValueError, OSError, RuntimeError, subprocess.SubprocessError):
+ raise SystemExit("Private DLL konnte nicht erstellt werden; vorheriger Stand bleibt erhalten.")
+ print("Private WebDAV-DLL installiert:", ROOT / NAME)
+ print("Keine INI, kein Git-Commit der Zugangsdaten. Die DLL ist nur für root lesbar.")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tools/release/ogl_gen1_snapshot_zip.py b/tools/release/ogl_gen1_snapshot_zip.py
index 1e4e6f87..b1cf7cbb 100644
--- a/tools/release/ogl_gen1_snapshot_zip.py
+++ b/tools/release/ogl_gen1_snapshot_zip.py
@@ -35,7 +35,8 @@ def allowed(path):
and not name.endswith(SKIP_SUFFIXES)
and name not in ("secrets.json", "appsettings.production.json",
"opensimconsolehistory.txt", "robustconsolehistory.txt")
- and not name.startswith("map-")
+ and not name.startswith(("map-", "ogl.webdav.private."))
+ and name != "webdav.credentials"
and (not name.endswith(".ini") or path.as_posix() in STATIC_INIS))
def create_zip(bin_dir, out, sha, repo, channel="development-main-snapshot"):
@@ -124,7 +125,8 @@ def selftest():
for private in ("Regions/NexVerse-Deutschland.ini", "assets/test.dat",
"fsassets/hash.gz", "opt/cache/fsassets/data/file.gz",
"ops-data/private.json", "MAP-example.png",
- "private.env", "OpenSimConsoleHistory.txt", "snapshot.oar"):
+ "private.env", "OpenSimConsoleHistory.txt", "snapshot.oar",
+ "Ogl.WebDav.Private.dll", "nested/OGL.WEBDAV.PRIVATE.dll", "webdav.credentials"):
item = bin_dir / private
item.parent.mkdir(parents=True, exist_ok=True)
item.write_text("PRIVATE")
diff --git a/tools/release/package_gen1_runtime.py b/tools/release/package_gen1_runtime.py
index 6497bd1c..09f5df3f 100644
--- a/tools/release/package_gen1_runtime.py
+++ b/tools/release/package_gen1_runtime.py
@@ -28,6 +28,8 @@ def sha(path: Path) -> str:
return h.hexdigest()
def copy(source: Path, relative: str) -> None:
+ if source.name.lower().startswith("ogl.webdav.private.") or source.name.lower() == "webdav.credentials":
+ return
if not source.is_file():
raise FileNotFoundError(source)
target = STAGE / relative