Skip to content

Commit 5a3902c

Browse files
Add support for installing with FDE.
Signed-off-by: Sasha Finkelstein <[email protected]>
1 parent 8bbbb8c commit 5a3902c

3 files changed

Lines changed: 47 additions & 11 deletions

File tree

build.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ cd "$(dirname "$0")"
88
PYTHON_VER=3.9.6
99
PYTHON_PKG=python-$PYTHON_VER-macos11.pkg
1010
PYTHON_URI="https://www.python.org/ftp/python/$PYTHON_VER/$PYTHON_PKG"
11+
ENCRYPTOR_URI="https://github.com/WhatAmISupposedToPutHere/encryptor/releases/download/v0.1/encryptor.tar.gz"
1112

1213
M1N1="$PWD/m1n1"
1314
ARTWORK="$PWD/artwork"
@@ -44,6 +45,7 @@ echo "Downloading installer components..."
4445
cd "$DL"
4546

4647
wget -Nc "$PYTHON_URI"
48+
wget -Nc "$ENCRYPTOR_URI"
4749

4850
echo "Building m1n1..."
4951

@@ -54,7 +56,7 @@ make -C "$M1N1" RELEASE=1 CHAINLOADING=1 -j4
5456
echo "Copying files..."
5557

5658
cp -r "$SRC"/* "$PACKAGE/"
57-
rm "$PACKAGE/asahi_firmware"
59+
rm -r "$PACKAGE/asahi_firmware"
5860
cp -r "$AFW" "$PACKAGE/"
5961
cp "$ARTWORK/logos/icns/AsahiLinux_logomark.icns" "$PACKAGE/logo.icns"
6062
mkdir -p "$PACKAGE/boot"
@@ -83,7 +85,7 @@ cd python3.*
8385
rm -rf test ensurepip idlelib
8486
cd lib-dynload
8587
rm -f _test* _tkinter*
86-
88+
8789

8890
echo "Copying certificates..."
8991

@@ -94,6 +96,8 @@ echo "Packaging installer..."
9496

9597
cd "$PACKAGE"
9698

99+
tar xf "$DL/encryptor.tar.gz"
100+
97101
echo "$VER" > version.tag
98102

99103
if [ "$1" == "prod" ]; then

src/main.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def get_admin_credentials(self):
239239
self.admin_password = getpass.getpass(f'Password for {self.admin_user}: ')
240240

241241
def action_install_into_container(self, avail_parts):
242-
template = self.choose_os()
242+
template, fde = self.choose_os()
243243

244244
containers = {str(i): p.desc for i,p in enumerate(self.parts) if p in avail_parts}
245245

@@ -253,7 +253,7 @@ def action_install_into_container(self, avail_parts):
253253

254254
self.ins = stub.StubInstaller(self.sysinfo, self.dutil, self.osinfo)
255255
self.ins.load_ipsw(ipsw)
256-
self.osins = osinstall.OSInstaller(self.dutil, self.data, template)
256+
self.osins = osinstall.OSInstaller(self.dutil, self.data, template, fde)
257257
self.osins.load_package()
258258

259259
self.do_install()
@@ -266,9 +266,9 @@ def action_wipe(self):
266266

267267
print()
268268

269-
template = self.choose_os()
269+
template, fde = self.choose_os()
270270

271-
self.osins = osinstall.OSInstaller(self.dutil, self.data, template)
271+
self.osins = osinstall.OSInstaller(self.dutil, self.data, template, fde)
272272
self.osins.load_package()
273273

274274
min_size = STUB_SIZE + self.osins.min_size
@@ -286,9 +286,9 @@ def action_wipe(self):
286286
self.do_install(os_size)
287287

288288
def action_install_into_free(self, avail_free):
289-
template = self.choose_os()
289+
template, fde = self.choose_os()
290290

291-
self.osins = osinstall.OSInstaller(self.dutil, self.data, template)
291+
self.osins = osinstall.OSInstaller(self.dutil, self.data, template, fde)
292292
self.osins.load_package()
293293

294294
min_size = STUB_SIZE + self.osins.min_size
@@ -498,7 +498,10 @@ def choose_os(self):
498498
idx = self.choice("OS", [i["name"] for i in os_list])
499499
os = os_list[idx]
500500
logging.info(f"Chosen OS: {os['name']}")
501-
return os
501+
fde = False
502+
if os.get("supports_fde", False) or True:
503+
fde = self.yesno("Enable disk encryption?")
504+
return (os, fde)
502505

503506
def set_reduced_security(self):
504507
while True:

src/osinstall.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class OSInstaller(PackageInstaller):
88
PART_ALIGNMENT = 1024 * 1024
9-
def __init__(self, dutil, data, template):
9+
def __init__(self, dutil, data, template, fde):
1010
super().__init__()
1111
self.dutil = dutil
1212
self.data = data
@@ -16,6 +16,7 @@ def __init__(self, dutil, data, template):
1616
self.efi_part = None
1717
self.idata_targets = []
1818
self.install_size = self.min_size
19+
self.fde = fde
1920

2021
@property
2122
def default_os_name(self):
@@ -131,6 +132,7 @@ def install(self, stub_ins):
131132
self.extract_file(icon, stub_ins.icon_path)
132133
self.flush_progress()
133134

135+
raw_images = []
134136
for part, info in zip(self.template["partitions"], self.part_info):
135137
logging.info(f"Installing partition {part!r} -> {info.name}")
136138
image = part.get("image", None)
@@ -139,9 +141,11 @@ def install(self, stub_ins):
139141
logging.info(f"Extract: {image}")
140142
zinfo = self.pkg.getinfo(image)
141143
with self.pkg.open(image) as sfd, \
142-
open(f"/dev/r{info.name}", "r+b") as dfd:
144+
open(f"/dev/r{info.name}", "r+b") as dfd:
143145
self.fdcopy(sfd, dfd, zinfo.file_size)
146+
144147
self.flush_progress()
148+
145149
source = part.get("source", None)
146150
if source:
147151
p_plain(f" Copying from {source} into {info.name} partition...")
@@ -160,11 +164,36 @@ def install(self, stub_ins):
160164
data_path = os.path.join(mountpoint, "asahi")
161165
os.makedirs(data_path, exist_ok=True)
162166
self.idata_targets.append(data_path)
167+
if not (source or part.get("copy_firmware", False) or part.get("copy_installer_data", False)):
168+
raw_images.append(info.name)
163169

164170
if "extras" in self.template:
165171
assert self.efi_part is not None
166172
self.download_extras()
167173

174+
if self.fde:
175+
p_progress("Encrypting OS image ...")
176+
args = [
177+
"./encryptor/qemu-system-aarch64",
178+
"-nographic",
179+
"-L", "./encryptor/qemu/",
180+
"-chardev", "stdio,id=term0",
181+
"-serial", "chardev:term0",
182+
"-cpu", "host",
183+
"-smp", "cpus=8,sockets=1,cores=8,threads=1",
184+
"-machine", "virt",
185+
"-accel", "hvf",
186+
"-m", "4096",
187+
"-kernel", "./encryptor/vmlinuz-virt",
188+
"-initrd", "./encryptor/initramfs",
189+
"-device", "virtio-rng-pci",
190+
"-monitor", "/dev/null",
191+
"-append", "quiet"
192+
]
193+
for i, name in enumerate(raw_images):
194+
args.extend(["-drive", f"if=virtio,format=raw,index={i + 1},file=/dev/{name}"])
195+
subprocess.run(args, check=True)
196+
168197
p_progress("Preparing to finish installation...")
169198

170199
logging.info(f"Building boot object")

0 commit comments

Comments
 (0)