Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Tor executable from install dir #4505

Merged
merged 26 commits into from Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion WalletWasabi.Gui/Global.cs
Expand Up @@ -88,7 +88,7 @@ public Global(string dataDir, string torLogsFile, Config config, UiConfig uiConf
DataDir = dataDir;
Config = config;
UiConfig = uiConfig;
TorSettings = new TorSettings(DataDir, torLogsFile, distributionFolderPath: Path.Combine(EnvironmentHelpers.GetFullBaseDirectory(), "TorDaemons"));
TorSettings = new TorSettings(DataDir, torLogsFile, distributionFolderPath: EnvironmentHelpers.GetFullBaseDirectory());

Logger.InitializeDefaults(Path.Combine(DataDir, "Logs.txt"));

Expand Down
2 changes: 0 additions & 2 deletions WalletWasabi.Packager/ArgsProcessor.cs
Expand Up @@ -16,8 +16,6 @@ public ArgsProcessor(string[] args)

public bool IsReduceOnionsMode() => IsOneOf("reduceonions", "reduceonion");

public bool IsOnlyCreateDigestsMode() => IsOneOf("onlycreatedigests", "onlycreatedigest", "onlydigests", "onlydigest");

public bool IsOnlyBinariesMode() => IsOneOf("onlybinaries");

public bool IsGetOnionsMode() => IsOneOf("getonions", "getonion");
Expand Down
44 changes: 38 additions & 6 deletions WalletWasabi.Packager/MacSignTools.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
Expand Down Expand Up @@ -46,8 +47,6 @@ public static void Sign()
var contentsPath = Path.GetFullPath(Path.Combine(Program.PackagerProjectDirectory.Replace("\\", "//"), "Content", "Osx"));
var entitlementsPath = Path.Combine(contentsPath, "entitlements.plist");
var dmgContentsDir = Path.Combine(contentsPath, "Dmg");
var torZipDirPath = Path.Combine(appMacOsPath, "TorDaemons", "tor-osx64");
var torZipPath = $"{torZipDirPath}.zip";
var desktopDmgFilePath = Path.Combine(desktopPath, dmgFileName);

var signArguments = $"--sign \"L233B2JQ68\" --verbose --force --options runtime --timestamp";
Expand Down Expand Up @@ -116,7 +115,7 @@ public static void Sign()
process.WaitForExit();
}

var filesToCheck = new[] { entitlementsPath, torZipPath };
var filesToCheck = new[] { entitlementsPath };

foreach (var file in filesToCheck)
{
Expand All @@ -134,6 +133,8 @@ public static void Sign()
IoHelpers.EnsureDirectoryExists(appMacOsPath);

var executables = GetExecutables(appPath);

// The main executable needs to be signed last.
var filesToSignInOrder = Directory.GetFiles(appPath, "*.*", SearchOption.AllDirectories)
.OrderBy(file => executables.Contains(file))
.OrderBy(file => new FileInfo(file).Name == "wassabee")
Expand Down Expand Up @@ -420,6 +421,12 @@ private static void SignFile(string arguments, string workingDir)
{
throw new InvalidOperationException(result);
}

if (result.Contains("xcrun: error: invalid active developer path"))
{
throw new InvalidOperationException($"{result}\ntip: run xcode-select --install");
}

Console.WriteLine(result.Trim());
}

Expand Down Expand Up @@ -458,11 +465,36 @@ private static void SignDirectory(string[] files, string workingDir, string sign
}
}

private static string[] GetExecutables(string workingDir)
private static IEnumerable<string> GetExecutables(string appPath)
{
string result = ExecuteBashCommand($"find -H \"{appPath}\" -print0 | xargs -0 file | grep \"Mach-O.* executable\"");

var lines = result.Split("\n").Where(x => !string.IsNullOrWhiteSpace(x));
var files = lines.Select(line => line.Split(":").First());

return files;
}

private static string ExecuteBashCommand(string command)
{
// Can be implemented as: find -H YourAppBundle -print0 | xargs -0 file | grep "Mach-O .*executable"
// according to: https://stackoverflow.com/a/15262019/637142
// Thanks to this we will pass everything as one command.
command = command.Replace("\"", "\"\"");

using var process = Process.Start(new ProcessStartInfo
{
FileName = "/bin/bash",
Arguments = $"-c \"{command}\"",
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
CreateNoWindow = true
});

var result = process.StandardOutput.ReadToEnd();
process.WaitForExit();

return Directory.GetFiles(workingDir, "*.", SearchOption.AllDirectories);
return result;
}
}
}
50 changes: 0 additions & 50 deletions WalletWasabi.Packager/Program.cs
Expand Up @@ -91,15 +91,6 @@ private static async Task Main(string[] args)
return;
}

// Start with digest creation and return if only digest creation.
CreateDigests();

OnlyCreateDigests = argsProcessor.IsOnlyCreateDigestsMode();
if (OnlyCreateDigests)
{
return;
}

// Only binaries mode is for deterministic builds.
OnlyBinaries = argsProcessor.IsOnlyBinariesMode();

Expand Down Expand Up @@ -128,38 +119,6 @@ private static async Task Main(string[] args)
}
}

private static void CreateDigests()
{
var tempDir = "DigestTempDir";
IoHelpers.TryDeleteDirectoryAsync(tempDir).GetAwaiter().GetResult();
Directory.CreateDirectory(tempDir);

var torDaemonsDir = Path.Combine(LibraryProjectDirectory, "TorDaemons");
string torWinZip = Path.Combine(torDaemonsDir, "tor-win64.zip");
IoHelpers.BetterExtractZipToDirectoryAsync(torWinZip, tempDir).GetAwaiter().GetResult();
File.Move(Path.Combine(tempDir, "Tor", "tor.exe"), Path.Combine(tempDir, "TorWin"));

string torLinuxZip = Path.Combine(torDaemonsDir, "tor-linux64.zip");
IoHelpers.BetterExtractZipToDirectoryAsync(torLinuxZip, tempDir).GetAwaiter().GetResult();
File.Move(Path.Combine(tempDir, "Tor", "tor"), Path.Combine(tempDir, "TorLin"));

string torOsxZip = Path.Combine(torDaemonsDir, "tor-osx64.zip");
IoHelpers.BetterExtractZipToDirectoryAsync(torOsxZip, tempDir).GetAwaiter().GetResult();
File.Move(Path.Combine(tempDir, "Tor", "tor.real"), Path.Combine(tempDir, "TorOsx"));

var tempDirInfo = new DirectoryInfo(tempDir);
var binaries = tempDirInfo.GetFiles();
Console.WriteLine("Digests:");
foreach (var file in binaries)
{
var filePath = file.FullName;
var hash = ByteHelpers.ToHex(IoHelpers.GetHashFile(filePath)).ToLowerInvariant();
Console.WriteLine($"{file.Name}: {hash}");
}

IoHelpers.TryDeleteDirectoryAsync(tempDir).GetAwaiter().GetResult();
}

private static void ReportStatus()
{
if (OnlyBinaries)
Expand Down Expand Up @@ -401,7 +360,6 @@ private static void Publish()
Tools.ClearSha512Tags(currentBinDistDirectory);

// Remove Tor binaries that are not relevant to the platform.
var torFolder = new DirectoryInfo(Path.Combine(currentBinDistDirectory, "TorDaemons"));
var toNotRemove = "";
if (target.StartsWith("win"))
{
Expand All @@ -416,14 +374,6 @@ private static void Publish()
toNotRemove = "osx";
}

foreach (var file in torFolder.EnumerateFiles())
{
if (!file.Name.Contains("data", StringComparison.OrdinalIgnoreCase) && !file.Name.Contains(toNotRemove, StringComparison.OrdinalIgnoreCase))
{
File.Delete(file.FullName);
}
}

// Remove binaries that are not relevant to the platform.
var binaryFolder = new DirectoryInfo(Path.Combine(currentBinDistDirectory, "Microservices", "Binaries"));

Expand Down
19 changes: 9 additions & 10 deletions WalletWasabi.Tests/UnitTests/Tor/TorSettingsTests.cs
Expand Up @@ -2,6 +2,7 @@
using System.Runtime.InteropServices;
using WalletWasabi.Tor;
using Xunit;
using System.IO;

namespace WalletWasabi.Tests.UnitTests.Tor
{
Expand All @@ -13,20 +14,18 @@ public class TorSettingsTests
[Fact]
public void GetCmdArgumentsTest()
{
var settings = new TorSettings("temp", "temp/Tor.log", "temp/TorDaemons");
var settings = new TorSettings(Path.Combine("temp", "tempDataDir"), Path.Combine("temp", "Tor.log"), "tempDistributionDir");
var endpoint = new IPEndPoint(IPAddress.Loopback, WalletWasabi.Helpers.Constants.DefaultTorSocksPort);

string arguments = settings.GetCmdArguments(endpoint);
string expected;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
expected = @"--SOCKSPort 127.0.0.1:9050 --DataDirectory ""temp\tordata"" --GeoIPFile ""temp\tor\Data\Tor\geoip"" GeoIPv6File ""temp\tor\Data\Tor\geoip6""";
}
else
{
expected = @"--SOCKSPort 127.0.0.1:9050 --DataDirectory ""temp/tordata"" --GeoIPFile ""temp/tor/Data/Tor/geoip"" GeoIPv6File ""temp/tor/Data/Tor/geoip6""";
}
string expected = string.Join(
" ",
$"--SOCKSPort 127.0.0.1:9050",
$"--DataDirectory \"{Path.Combine("temp", "tempDataDir", "tordata")}\"",
$"--GeoIPFile \"{Path.Combine("tempDistributionDir", "Tor", "Geoip", "geoip")}\"",
$"--GeoIPv6File \"{Path.Combine("tempDistributionDir", "Tor", "Geoip", "geoip6")}\"",
$"--Log \"notice file {Path.Combine("temp", "Tor.log")}\"");

Assert.Equal(expected, arguments);
}
Expand Down
4 changes: 4 additions & 0 deletions WalletWasabi/Microservices/Binaries/README.md
Expand Up @@ -5,5 +5,9 @@
3. Make sure the Linux and the OSX binaries are executable:
`git update-index --chmod=+x hwi`
`git update-index --chmod=+x bitcoind`
`git update-index --chmod=+x .\lin64\Tor\tor`
`git update-index --chmod=+x .\win64\Tor\tor.exe`
`git update-index --chmod=+x .\osx64\Tor\tor`
`git update-index --chmod=+x .\osx64\Tor\tor.real`
4. Commit, push.
5. Make sure CI passes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added WalletWasabi/Microservices/Binaries/lin64/Tor/tor
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions WalletWasabi/Microservices/Binaries/osx64/Tor/tor
@@ -0,0 +1,12 @@
#!/bin/sh
# Compiled Python modules require a compatible Python, which means 32-bit 2.6.
export VERSIONER_PYTHON_VERSION=2.6
export DYLD_LIBRARY_PATH=.:$DYLD_LIBRARY_PATH
# Set the current working directory to the directory containing this executable,
# so that pluggable transport executables can be given with relative paths. This
# works around a change in OS X 10.9, where the current working directory is
# otherwise set to "/" when an application bundle is started from Finder.
# https://trac.torproject.org/projects/tor/ticket/10030
cd "$(dirname "$0")"
exec ./tor.real "$@"
# Random Comment Dump to change the digest "je202kjnfoj2iuwkekjjreiejr9"
molnard marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
13 changes: 9 additions & 4 deletions WalletWasabi/Microservices/MicroserviceHelpers.cs
Expand Up @@ -7,23 +7,23 @@ namespace WalletWasabi.Microservices
{
public static class MicroserviceHelpers
{
public static string GetBinaryPath(string binaryNameWithoutExtension)
public static string GetBinaryFolder()
{
var fullBaseDirectory = EnvironmentHelpers.GetFullBaseDirectory();

string commonPartialPath = Path.Combine(fullBaseDirectory, "Microservices", "Binaries");
string path;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
path = Path.Combine(commonPartialPath, $"win64", $"{binaryNameWithoutExtension}.exe");
path = Path.Combine(commonPartialPath, $"win64");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
path = Path.Combine(commonPartialPath, $"lin64", binaryNameWithoutExtension);
path = Path.Combine(commonPartialPath, $"lin64");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
path = Path.Combine(commonPartialPath, $"osx64", binaryNameWithoutExtension);
path = Path.Combine(commonPartialPath, $"osx64");
}
else
{
Expand All @@ -32,5 +32,10 @@ public static string GetBinaryPath(string binaryNameWithoutExtension)

return path;
}

public static string GetBinaryPath(string binaryNameWithoutExtension)
{
return Path.Combine(GetBinaryFolder(), RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? $"{binaryNameWithoutExtension}.exe" : $"{binaryNameWithoutExtension}");
}
}
}