diff --git a/include/echoion/standalone/RuntimePaths.hpp b/include/echoion/standalone/RuntimePaths.hpp index 88122a1..8ee1646 100644 --- a/include/echoion/standalone/RuntimePaths.hpp +++ b/include/echoion/standalone/RuntimePaths.hpp @@ -32,6 +32,9 @@ namespace Echoion::Standalone const std::filesystem::path& installRoot, const std::filesystem::path& executableDirectory); + [[nodiscard]] std::optional + bundledCertificateBundle(const std::filesystem::path& installRoot); + [[nodiscard]] std::expected resolveAvatarCacheDirectory( const std::filesystem::path& configuredDirectory, diff --git a/src/RuntimePaths.cpp b/src/RuntimePaths.cpp index 7996086..ffceb14 100644 --- a/src/RuntimePaths.cpp +++ b/src/RuntimePaths.cpp @@ -120,7 +120,10 @@ namespace Echoion::Standalone if (std::filesystem::is_regular_file( packagedDirectory / "web" / "index.html", error) && !error) { - return packagedDirectory; + // Installed config paths are rooted at the release prefix (for + // example ./share/echoion/web), so the working directory must be + // the installation root rather than share/echoion itself. + return installRoot; } error.clear(); @@ -132,6 +135,19 @@ namespace Echoion::Standalone return std::nullopt; } + std::optional + bundledCertificateBundle(const std::filesystem::path& installRoot) + { + const auto bundle = + installRoot / "share" / "echoion" / "certs" / "ca-certificates.crt"; + std::error_code error; + if (!std::filesystem::is_regular_file(bundle, error) || error || + std::filesystem::file_size(bundle, error) == 0 || error) { + return std::nullopt; + } + return bundle.lexically_normal(); + } + std::expected resolveAvatarCacheDirectory( const std::filesystem::path& configuredDirectory, diff --git a/src/main.cpp b/src/main.cpp index b9e4c23..b551194 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -558,6 +558,16 @@ int main(int argc, char** argv) std::cerr << "Cannot export ECHOION_HOME\n"; return 2; } + if (!environmentPath("SSL_CERT_FILE")) { + if (const auto certificateBundle = + Echoion::Standalone::bundledCertificateBundle(installRoot)) { + const auto bundleString = certificateBundle->string(); + if (::setenv("SSL_CERT_FILE", bundleString.c_str(), 0) != 0) { + std::cerr << "Cannot export bundled TLS certificate store\n"; + return 2; + } + } + } for (const std::string_view requiredValue : {"--config", "--state-dir"}) { if (hasArgument(argc, argv, requiredValue) && !optionalArgumentPath(argc, argv, requiredValue)) { diff --git a/tests/test_runtime_paths.cpp b/tests/test_runtime_paths.cpp index 053451f..7059d0a 100644 --- a/tests/test_runtime_paths.cpp +++ b/tests/test_runtime_paths.cpp @@ -101,11 +101,19 @@ int main() const auto packagedIndex = installRoot / "share" / "echoion" / "web" / "index.html"; check(writeFile(packagedIndex), "failed to create packaged web fixture"); - check( - Echoion::Standalone::runtimeWorkingDirectory(installRoot, - executableDirectory) == - installRoot / "share" / "echoion", - "packaged web root did not select share/echoion as working directory"); + check(Echoion::Standalone::runtimeWorkingDirectory( + installRoot, executableDirectory) == installRoot, + "packaged web root did not select the installation root as working " + "directory"); + const auto bundledCertificates = + installRoot / "share" / "echoion" / "certs" / "ca-certificates.crt"; + check(!Echoion::Standalone::bundledCertificateBundle(installRoot), + "missing bundled certificate store was accepted"); + check(writeFile(bundledCertificates), + "failed to create bundled certificate store fixture"); + check(Echoion::Standalone::bundledCertificateBundle(installRoot) == + bundledCertificates, + "bundled certificate store was not resolved from the install root"); std::filesystem::remove_all(installRoot / "share"); const auto developmentIndex = executableDirectory / "web" / "index.html"; check(writeFile(developmentIndex), diff --git a/tests/test_stage_release.sh b/tests/test_stage_release.sh index c57a4d1..3433bb4 100755 --- a/tests/test_stage_release.sh +++ b/tests/test_stage_release.sh @@ -14,6 +14,7 @@ mkdir -p -- \ "$bundle/bin" \ "$bundle/lib" \ "$bundle/service" \ + "$bundle/share/echoion/certs" \ "$bundle/share/echoion/tools" \ "$bundle/share/echoion/web" printf '#!/bin/sh\necho "echoiond must not run during release staging" >&2\nexit 97\n' \ @@ -27,6 +28,7 @@ install -m 0644 -- \ "$service_templates/echoion-updater.timer.in" \ "$bundle/service/" printf '{"webRoot":"./web"}\n' > "$bundle/share/echoion/config.example.json" +printf 'test trust bundle\n' > "$bundle/share/echoion/certs/ca-certificates.crt" install -m 0755 -- "$manifest_validator" \ "$bundle/share/echoion/tools/validate-release-manifest.py" printf '\n' > "$bundle/share/echoion/web/index.html"