Skip to content

Verify downloaded binaries #4275

Open
@YoshiRulz

Description

@YoshiRulz

//try acquiring file
using (var hf = new HawkFile(fn))
{
using (var exe = OSTailoredCode.IsUnixHost ? hf.BindArchiveMember("ffmpeg") : hf.BindFirstOf(".exe"))
{
//last chance. exiting, don't dump the new ffmpeg file
if (exiting)
return;
exe!.GetStream().CopyTo(fs);
fs.Dispose();
if (OSTailoredCode.IsUnixHost)
{
OSTailoredCode.ConstructSubshell("chmod", $"+x {FFmpegService.FFmpegPath}", checkStdout: false).Start();
Thread.Sleep(50); // Linux I/O flush idk
}
}
}
//make sure it worked
if (!FFmpegService.QueryServiceAvailable()) throw new Exception("download failed");
succeeded = true;

private const string BIN_HOST_URI_LINUX_X64 = "https://github.com/TASEmulators/ffmpeg-binaries/raw/master/ffmpeg-4.4.1-static-linux-x64.7z";
private const string BIN_HOST_URI_WIN_X64 = "https://github.com/TASEmulators/ffmpeg-binaries/raw/master/ffmpeg-4.4.1-static-windows-x64.7z";

Not great, there's some trustworthiness to those addresses, but it gets worse...


private static bool DownloadDll(string url)
{
if (url.StartsWithOrdinal("http:"))
{
// force https
url = url.Replace("http:", "https:");
}
using var downloadForm = new RAIntegrationDownloaderForm(url);
downloadForm.ShowDialog();
return downloadForm.DownloadSucceeded();
}
public static bool CheckUpdateRA(IDialogParent dialogParent)
{
try
{
var http = new HttpCommunication(null, "https://retroachievements.org/dorequest.php?r=latestintegration", null);
var info = JsonConvert.DeserializeObject<Dictionary<string, object>>(http.ExecGet());
if (info.TryGetValue("Success", out var success) && (bool)success)
{
var lastestVer = new Version((string)info["LatestVersion"]);
var minVer = new Version((string)info["MinimumVersion"]);
if (_version < minVer)
{
if (!dialogParent.ModalMessageBox2(
text:
"An update is required to use RetroAchievements. Do you want to download the update now?",
caption: "Update",
icon: EMsgBoxIcon.Question,
useOKCancel: false)) return false;
DetachDll();
var ret = DownloadDll((string)info["LatestVersionUrlX64"]);

...because this blindly follows any address returned in the first response 🙃 And bonus points for copy-pasting:
//try acquiring file
using (var dll = new HawkFile(fn))
{
var data = dll!.ReadAllBytes();
//last chance. exiting, don't dump the new RAIntegration file
if (_exiting)
return;
DirectoryInfo parentDir = new(Path.GetDirectoryName(_path)!);
if (!parentDir.Exists) parentDir.Create();
if (File.Exists(_path)) File.Delete(_path);
File.WriteAllBytes(_path, data);
}
_succeeded = true;


Simple solution for FFmpeg is to hardcode the checksum.

RA's API seems to be down at the moment so I can't check if that includes a checksum, but even if it did, it would need to be signed as well (and we hardcode the pubkey).
And assert info["LatestVersionUrlX64"].StartsWith("https://retroachievements.org/").

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions