Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit d592917

Browse files
committed
Improving system partition key choice
1 parent 78276aa commit d592917

File tree

5 files changed

+98
-55
lines changed

5 files changed

+98
-55
lines changed

src/config.ml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,6 @@ let oali_answer_store_dir = "oali_answers"
6262

6363
let sshd_port = 40010
6464

65-
let gen_mkinitcpio_hooks ~encrypt_sys ~use_lvm =
66-
List.filter_map
67-
(fun x -> x)
68-
[
69-
Some "base";
70-
Some "udev";
71-
Some "autodetect";
72-
Some "keyboard";
73-
Some "keymap";
74-
Some "consolefont";
75-
Some "modconf";
76-
Some "block";
77-
(if encrypt_sys then Some "encrypt" else None);
78-
(if use_lvm then Some "lvm2" else None);
79-
Some "filesystems";
80-
Some "fsck";
81-
]
82-
8365
let lvm_vg_name = "vg_sys"
8466

8567
let lvm_lv_root_name = "lv_root"

src/disk_layout.ml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ type layout_choice =
2020
| Sys_part_plus_boot_plus_maybe_EFI
2121
| Sys_part_plus_usb_drive
2222

23+
type sys_part_enc_choice = [
24+
| `None
25+
| `Passphrase
26+
| `Keyfile
27+
]
28+
2329
(* | Lvm_single_disk
2430
* | Lvm_boot_plus_maybe_EFI_plus_pv_s
2531
* | Lvm_usb_drive_plus_pv_s *)
@@ -236,7 +242,7 @@ let make_boot (pool : Storage_unit.pool) ~enc_params ~encrypt ~path =
236242
let primary_key =
237243
Misc_utils.ask_string_confirm
238244
~is_valid:(fun x -> x <> "")
239-
~no_echo:true "Please enter passphrase for encryption"
245+
~no_echo:true "Please enter passphrase for BOOT (/boot) partition encryption"
240246
in
241247
Storage_unit.L1.make_luks ~primary_key ~add_secondary_key:true
242248
~version:`LuksV1 ~path ~mapper_name:Config.boot_mapper_name enc_params
@@ -247,14 +253,28 @@ let make_boot (pool : Storage_unit.pool) ~enc_params ~encrypt ~path =
247253
(Storage_unit.L4.make ~mount_point:Config.boot_mount_point `Ext4);
248254
Storage_unit.make ~l1_id ~l2_id ~l3_id ~l4_id
249255

250-
let make_root_var_home (pool : Storage_unit.pool) ~enc_params ~encrypt ~use_lvm
256+
let make_root_var_home (pool : Storage_unit.pool) ~enc_params ~(encrypt : sys_part_enc_choice) ~use_lvm
251257
path : Storage_unit.t * Storage_unit.t option * Storage_unit.t option =
252258
(* common components - L1, L2 stuff *)
253259
Hashtbl.add pool.l1_pool Params.Sys.l1_id
254-
(if encrypt then
260+
(match encrypt with
261+
| `None -> Storage_unit.L1.make_clear ~path
262+
| `Passphrase ->
263+
let primary_key =
264+
Misc_utils.ask_string_confirm
265+
~is_valid:(fun x -> x <> "")
266+
~no_echo:true "Please enter passphrase for ROOT (/) partition encryption"
267+
in
268+
Storage_unit.L1.make_luks ~primary_key ~path ~mapper_name:Config.sys_mapper_name
269+
enc_params
270+
| `Keyfile ->
255271
Storage_unit.L1.make_luks ~path ~mapper_name:Config.sys_mapper_name
256272
enc_params
257-
else Storage_unit.L1.make_clear ~path);
273+
);
274+
(* (if encrypt then
275+
* Storage_unit.L1.make_luks ~path ~mapper_name:Config.sys_mapper_name
276+
* enc_params
277+
* else Storage_unit.L1.make_clear ~path); *)
258278
Hashtbl.add pool.l2_pool Params.Sys.l2_id
259279
(if use_lvm then Storage_unit.L2.make_lvm ~vg_name:Config.lvm_vg_name
260280
else Storage_unit.L2.make_none ());
@@ -319,7 +339,7 @@ let make_root_var_home (pool : Storage_unit.pool) ~enc_params ~encrypt ~use_lvm
319339
(root, var, home)
320340

321341
let make_layout ~esp_part_path ~boot_part_path ~boot_part_enc_params
322-
~boot_encrypt ~sys_part_path ~sys_part_enc_params ~sys_encrypt ~use_lvm =
342+
~boot_encrypt ~sys_part_path ~sys_part_enc_params ~(sys_encrypt : sys_part_enc_choice) ~use_lvm =
323343
let pool = Storage_unit.make_pool () in
324344
let esp = Option.map (fun path -> make_esp pool ~path) esp_part_path in
325345
let boot =
@@ -332,7 +352,7 @@ let make_layout ~esp_part_path ~boot_part_path ~boot_part_enc_params
332352
in
333353
let lvm_info =
334354
if use_lvm then
335-
if sys_encrypt then
355+
if sys_encrypt <> `None then
336356
Some
337357
{
338358
vg_name = Config.lvm_vg_name;

src/mkinitcpio_utils.ml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
let gen_mkinitcpio_hooks ~(encrypt_sys : Disk_layout.sys_part_enc_choice) ~use_lvm =
2+
List.filter_map
3+
(fun x -> x)
4+
[
5+
Some "base";
6+
Some "udev";
7+
Some "autodetect";
8+
Some "keyboard";
9+
Some "keymap";
10+
Some "consolefont";
11+
Some "modconf";
12+
Some "block";
13+
(match encrypt_sys with
14+
| `None -> None
15+
| `Passphrase | `Keyfile -> Some "encrypt");
16+
(if use_lvm then Some "lvm2" else None);
17+
Some "filesystems";
18+
Some "fsck";
19+
]

src/oali.ml

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,27 @@ User is allowed to continue said setup if they wishes to however
219219
selected to not encrypt root";
220220
confirm_answer_is_correct_end_retry ~ret:encrypt_sys)
221221
in
222-
{ config with encrypt_sys = Some encrypt });
222+
if encrypt then (
223+
if encrypt_boot then
224+
{ config with encrypt_sys = Some `Keyfile }
225+
else (
226+
print_endline "Since boot partition is not encrypted, please specify whether system partition should use passphrase or keyfile";
227+
let choices =
228+
[
229+
("passphrase", `Passphrase);
230+
("keyfile", `Keyfile);
231+
]
232+
in
233+
let choice = pick_choice_kv choices in
234+
{ config with encrypt_sys = Some choice }
235+
)
236+
)
237+
else
238+
{ config with encrypt_sys = Some `None }
239+
);
223240
reg ~name:"Adjust cryptsetup parameters for root partition" ~doc:luks_doc
224241
(fun answer_store config ->
225-
if Option.get config.encrypt_sys then
242+
if Option.get config.encrypt_sys <> `None then
226243
let iter_time_ms, key_size_bits =
227244
retry ~answer_store (fun () ->
228245
let iter_time_ms =
@@ -646,27 +663,31 @@ if using the USB key disk layout|}
646663
config);
647664
reg ~name:"Install keyfile for /"
648665
~doc:{|Sets up keyfile to be embedded into the initramfs|}
649-
(fun _answer_store config ->
650-
if Option.get config.encrypt_sys then (
651-
let disk_layout = Option.get config.disk_layout in
652-
let root = Disk_layout.get_root disk_layout in
653-
match root.l1 with
654-
| Clear _ -> failwith "Expected LUKS"
655-
| Luks { info; _ } ->
656-
let keyfile_path =
657-
concat_file_names
658-
[
659-
Config.root_mount_point;
660-
Config.root_dir;
661-
Config.sys_part_keyfile_name;
662-
]
663-
in
664-
let oc = open_out_bin keyfile_path in
665-
Fun.protect
666-
~finally:(fun () -> close_out oc)
667-
(fun () -> output_string oc info.primary_key);
668-
Unix.chmod keyfile_path 0o000)
669-
else print_endline "Skipped";
666+
(fun _answer_store config -> (
667+
match Option.get config.encrypt_sys with
668+
| `None | `Passphrase ->
669+
print_endline "Skipped"
670+
| `Keyfile -> (
671+
let disk_layout = Option.get config.disk_layout in
672+
let root = Disk_layout.get_root disk_layout in
673+
match root.l1 with
674+
| Clear _ -> failwith "Expected LUKS"
675+
| Luks { info; _ } ->
676+
let keyfile_path =
677+
concat_file_names
678+
[
679+
Config.root_mount_point;
680+
Config.root_dir;
681+
Config.sys_part_keyfile_name;
682+
]
683+
in
684+
let oc = open_out_bin keyfile_path in
685+
Fun.protect
686+
~finally:(fun () -> close_out oc)
687+
(fun () -> output_string oc info.primary_key);
688+
Unix.chmod keyfile_path 0o000)
689+
)
690+
;
670691
config);
671692
reg ~name:"Install keyfile for unlocking /boot"
672693
~doc:
@@ -754,13 +775,14 @@ The line is then commented if disk layout uses USB key|}
754775
match Re.matches re s with
755776
| [] -> [ s ]
756777
| _ ->
757-
if encrypt_sys then
778+
match encrypt_sys with
779+
| `Keyfile ->
758780
[
759781
Printf.sprintf "FILES=(%s)"
760782
(concat_file_names
761783
[ "/root"; Config.sys_part_keyfile_name ]);
762784
]
763-
else [ s ]
785+
| `None | `Passphrase -> [ s ]
764786
in
765787
let fill_in_HOOKS =
766788
let re = "^HOOKS" |> Re.Posix.re |> Re.compile in
@@ -771,7 +793,7 @@ The line is then commented if disk layout uses USB key|}
771793
[
772794
Printf.sprintf "HOOKS=(%s)"
773795
(String.concat " "
774-
(Config.gen_mkinitcpio_hooks ~encrypt_sys ~use_lvm));
796+
(Mkinitcpio_utils.gen_mkinitcpio_hooks ~encrypt_sys ~use_lvm));
775797
]
776798
in
777799
File.filter_map_lines ~file fill_in_FILES;
@@ -1060,10 +1082,10 @@ Recovery kit creation decision is as follows
10601082
concat_file_names [ Config.root_mount_point; Config.root_dir ]
10611083
in
10621084
match (encrypt_boot, encrypt_sys) with
1063-
| true, true -> [ dst_boot; dst_root ]
1064-
| true, false -> [ dst_boot ]
1065-
| false, true -> [ dst_root ]
1066-
| false, false -> [ dst_boot; dst_root ]
1085+
| true, `Passphrase | true, `Keyfile -> [ dst_boot; dst_root ]
1086+
| true, `None -> [ dst_boot ]
1087+
| false, `Passphrase | false, `Keyfile -> [ dst_root ]
1088+
| false, `None -> [ dst_boot; dst_root ]
10671089
in
10681090
dst_s
10691091
|> List.iter (fun dst_dir_path ->

src/task_config.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type t = {
66
hardened_as_default : bool option;
77
use_lvm : bool option;
88
encrypt_boot : bool option;
9-
encrypt_sys : bool option;
9+
encrypt_sys : Disk_layout.sys_part_enc_choice option;
1010
boot_part_enc_params : Storage_unit.Luks_info.enc_params option;
1111
sys_part_enc_params : Storage_unit.Luks_info.enc_params option;
1212
editor : string option;

0 commit comments

Comments
 (0)