Skip to content

Commit 1a2dca5

Browse files
committed
add support for encrypted signing keys
1 parent fd8319a commit 1a2dca5

5 files changed

Lines changed: 261 additions & 64 deletions

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
Tuple Launch
2+
================================================================================
3+
Use the following link to download the toolchain for this project:
4+
5+
https://ziglang.org/builds/zig-linux-x86_64-0.10.0-dev.2674+d980c6a38.tar.xz
6+
7+
Download/extract the archve and run `zig build` with the resulting `zig` executable.
8+
9+
This will generate executables in the `zig-out` directory which will include:
10+
11+
* the `signing` executable for generating new keys/signing and verifying signatures.
12+
* the `tuple-launch` and `tuple-flatpak-launch` executables which are used by Tuple
13+
uses during its launch process.
14+
115
Tuple Launch Process
216
================================================================================
317
Tuple requires privileged access that the flatpak portal doesn't provide. To

build.zig

Lines changed: 83 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,101 @@ const Step = std.build.Step;
55
pub fn build(b: *Builder) void {
66
const mode = b.standardReleaseOptions();
77
const strip = b.option(bool, "strip", "strip binaries") orelse true;
8-
buildAnytype(b, "", mode, strip);
8+
9+
const path_prefix = "";
10+
const signing_exe = addSigningExe(b, path_prefix);
11+
const dev_signing = Signing{
12+
.exe = signing_exe,
13+
.key_filename = b.pathFromRoot("tuple_dev_ed25519"),
14+
};
15+
_ = addLaunchExes(b, path_prefix, mode, .customer, .{ .pubkey_filepath = "tuple_dev_ed25519.pub", .strip = strip, .exe_suffix = "" , .signing = null });
16+
_ = addLaunchExes(b, path_prefix, mode, .dev , .{ .pubkey_filepath = "tuple_dev_ed25519.pub", .strip = strip, .exe_suffix = "-dev", .signing = dev_signing });
17+
}
18+
19+
pub const SigningExe = struct {
20+
exe: *std.build.LibExeObjStep,
21+
};
22+
23+
fn concat(b: *Builder, left: []const u8, right: []const u8) []u8 {
24+
return std.mem.concat(b.allocator, u8, &.{left, right}) catch unreachable;
925
}
1026

27+
pub fn addSigningExe(b: *Builder, comptime path_prefix: []const u8) SigningExe {
28+
const exe = b.addExecutable("signing", path_prefix ++ "signing.zig");
29+
exe.single_threaded = true;
30+
exe.override_dest_dir = .prefix;
31+
exe.install();
32+
return SigningExe{ .exe = exe };
33+
}
34+
35+
pub const LaunchExeVariant = enum { dev, customer };
36+
37+
pub const LaunchExes = struct {
38+
launch: *std.build.LibExeObjStep,
39+
flatpak_launch: *std.build.LibExeObjStep,
40+
};
41+
42+
pub const Signing = struct {
43+
exe: SigningExe,
44+
key_filename: []const u8,
45+
};
46+
1147
// This function allows this build to be used as apart of another build.zig. Set `path_prefix`
1248
// to the sub_path where this build.zig file exists (include trailing slash).
13-
pub fn buildAnytype(b: *Builder, comptime path_prefix: []const u8, mode: std.builtin.Mode, strip: bool) void {
49+
pub fn addLaunchExes(
50+
b: *Builder,
51+
path_prefix: []const u8,
52+
mode: std.builtin.Mode,
53+
variant: LaunchExeVariant,
54+
opt: struct {
55+
pubkey_filepath: []const u8,
56+
strip: bool,
57+
exe_suffix: []const u8,
58+
signing: ?Signing,
59+
},
60+
) LaunchExes {
1461
const target = std.zig.CrossTarget.parse(.{
1562
.arch_os_abi = "x86_64-linux",
1663
}) catch unreachable;
1764

18-
const signing_exe = b.addExecutable("signing", path_prefix ++ "signing.zig");
19-
signing_exe.single_threaded = true;
20-
signing_exe.override_dest_dir = .prefix;
21-
signing_exe.install();
22-
2365
const path_prefix_no_ts = std.mem.trimRight(u8, path_prefix, "/");
2466

25-
const LaunchExeVariant = enum { dev, customer };
26-
inline for (std.meta.fields(LaunchExeVariant)) |field| {
27-
const variant = @intToEnum(LaunchExeVariant, field.value);
28-
const suffix = switch (variant) { .dev => "-dev", .customer => "" };
29-
const build_options = b.addOptions();
30-
build_options.addOption(LaunchExeVariant, "variant", variant);
31-
32-
{
33-
const exe = b.addExecutable("tuple-launch" ++ suffix, path_prefix ++ "launch.zig");
34-
exe.addIncludePath(b.pathFromRoot(path_prefix_no_ts));
35-
exe.setBuildMode(mode);
36-
exe.setTarget(target);
37-
exe.single_threaded = true;
38-
exe.strip = strip;
39-
exe.override_dest_dir = .prefix;
40-
exe.install();
41-
exe.addOptions("build_options", build_options);
42-
}
43-
{
44-
const exe = b.addExecutable("tuple-flatpak-launch" ++ suffix, path_prefix ++ "flatpak-launch.zig");
45-
exe.addIncludePath(b.pathFromRoot(path_prefix_no_ts));
46-
exe.setBuildMode(mode);
47-
exe.setTarget(target);
48-
exe.single_threaded = true;
49-
exe.strip = strip;
50-
exe.override_dest_dir = .prefix;
51-
exe.install();
52-
exe.addOptions("build_options", build_options);
53-
54-
const sign_exe = signing_exe.run();
67+
const build_options = b.addOptions();
68+
build_options.addOption(LaunchExeVariant, "variant", variant);
69+
build_options.addOption([]const u8, "pubkey_filepath", opt.pubkey_filepath);
70+
71+
const launch_exe = blk: {
72+
const exe = b.addExecutable(concat(b, "tuple-launch", opt.exe_suffix), concat(b, path_prefix, "launch.zig"));
73+
exe.addIncludePath(b.pathFromRoot(path_prefix_no_ts));
74+
exe.setBuildMode(mode);
75+
exe.setTarget(target);
76+
exe.single_threaded = true;
77+
exe.strip = opt.strip;
78+
exe.override_dest_dir = .prefix;
79+
exe.install();
80+
exe.addOptions("build_options", build_options);
81+
break :blk exe;
82+
};
83+
const flatpak_launch_exe = blk: {
84+
const exe = b.addExecutable("tuple-flatpak-launch", concat(b, path_prefix, "flatpak-launch.zig"));
85+
exe.addIncludePath(b.pathFromRoot(path_prefix_no_ts));
86+
exe.setBuildMode(mode);
87+
exe.setTarget(target);
88+
exe.single_threaded = true;
89+
exe.strip = opt.strip;
90+
exe.override_dest_dir = .prefix;
91+
exe.install();
92+
exe.addOptions("build_options", build_options);
93+
94+
if (opt.signing) |signing| {
95+
const sign_exe = signing.exe.exe.run();
5596
sign_exe.addArg("sign");
56-
sign_exe.addArg(b.pathFromRoot(path_prefix ++ "tuple_dev_ed25519"));
97+
sign_exe.addArg(signing.key_filename);
5798
sign_exe.addArtifactArg(exe);
5899
b.getInstallStep().dependOn(&sign_exe.step);
59100
}
60-
}
101+
break :blk exe;
102+
};
103+
104+
return .{ .launch = launch_exe, .flatpak_launch = flatpak_launch_exe };
61105
}

launch.zig

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,6 @@ pub fn main() !void {
233233
os.exit(0xff);
234234
}
235235

236-
const launch_suffix = switch (build_options.variant) {
237-
.dev => "-dev",
238-
.customer => "",
239-
};
240-
241236
pub fn getTupleFlatpakLaunchExe(
242237
flatpak_id: []const u8,
243238
flatpak_install_kind: FlatpakInstallKind,
@@ -292,11 +287,11 @@ pub fn getTupleFlatpakLaunchExe(
292287
}
293288
const location = std.mem.trimRight(u8, result.stdout, "\n\r ");
294289
log.debug(@src(), "flatpak location is '{s}'", .{location});
295-
return try std.fmt.allocPrintZ(global_arena.allocator(), "{s}/files/bin/tuple-flatpak-launch" ++ launch_suffix, .{location});
290+
return try std.fmt.allocPrintZ(global_arena.allocator(), "{s}/files/bin/tuple-flatpak-launch", .{location});
296291
}
297292

298293
const tuple_dev_ed25519_pub = blk: {
299-
const pub_hex = @embedFile("tuple_dev_ed25519.pub");
294+
const pub_hex = @embedFile(build_options.pubkey_filepath);
300295
var buf: [Signer.public_length]u8 = undefined;
301296
const len = (std.fmt.hexToBytes(&buf, pub_hex) catch @panic("pub keyfile contained non-hex digits")).len;
302297
std.debug.assert(len == buf.len);

0 commit comments

Comments
 (0)