diff --git a/repos/gems/recipes/pkg/file_vault/archives b/repos/gems/recipes/pkg/file_vault/archives index bdc56dbaff..e0cdbc459e 100644 --- a/repos/gems/recipes/pkg/file_vault/archives +++ b/repos/gems/recipes/pkg/file_vault/archives @@ -1,9 +1,7 @@ _/src/init _/src/libc -_/src/libpng _/src/zlib _/src/fs_query -_/src/menu_view _/src/tresor _/src/vfs_block _/src/vfs_jitterentropy @@ -15,3 +13,7 @@ _/src/posix _/src/rump _/src/sandbox _/src/file_vault +_/src/file_vault_gui +_/src/report_rom +_/src/menu_view +_/src/libpng diff --git a/repos/gems/recipes/pkg/file_vault/runtime b/repos/gems/recipes/pkg/file_vault/runtime index 1af026adfb..d40e283158 100644 --- a/repos/gems/recipes/pkg/file_vault/runtime +++ b/repos/gems/recipes/pkg/file_vault/runtime @@ -1,15 +1,15 @@ - + - + - - + + @@ -18,10 +18,8 @@ - - @@ -43,7 +41,11 @@ + + + + @@ -65,35 +67,61 @@ - - + + + + + + + + + + + + + + + + + - - - - - - + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/repos/gems/recipes/pkg/file_vault_config_report/README b/repos/gems/recipes/pkg/file_vault_config_report/README deleted file mode 100644 index a88de3a2e1..0000000000 --- a/repos/gems/recipes/pkg/file_vault_config_report/README +++ /dev/null @@ -1 +0,0 @@ -See repos/gems/src/app/file_vault/README. diff --git a/repos/gems/recipes/pkg/file_vault_config_report/archives b/repos/gems/recipes/pkg/file_vault_config_report/archives deleted file mode 100644 index a96843d2e0..0000000000 --- a/repos/gems/recipes/pkg/file_vault_config_report/archives +++ /dev/null @@ -1,15 +0,0 @@ -_/src/init -_/src/libc -_/src/zlib -_/src/fs_query -_/src/tresor -_/src/vfs_block -_/src/vfs_jitterentropy -_/src/vfs -_/src/openssl -_/src/fs_tool -_/src/fs_utils -_/src/posix -_/src/rump -_/src/sandbox -_/src/file_vault diff --git a/repos/gems/recipes/pkg/file_vault_config_report/hash b/repos/gems/recipes/pkg/file_vault_config_report/hash deleted file mode 100644 index dbcb9975f7..0000000000 --- a/repos/gems/recipes/pkg/file_vault_config_report/hash +++ /dev/null @@ -1 +0,0 @@ -2024-04-18 119c76ec69dc9094ec8ff6e5fab286c74bc3e255 diff --git a/repos/gems/recipes/pkg/file_vault_config_report/runtime b/repos/gems/recipes/pkg/file_vault_config_report/runtime deleted file mode 100644 index e69c1a947f..0000000000 --- a/repos/gems/recipes/pkg/file_vault_config_report/runtime +++ /dev/null @@ -1,98 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/repos/gems/recipes/pkg/test-file_vault_config_report/README b/repos/gems/recipes/pkg/test-file_vault/README similarity index 100% rename from repos/gems/recipes/pkg/test-file_vault_config_report/README rename to repos/gems/recipes/pkg/test-file_vault/README diff --git a/repos/gems/recipes/pkg/test-file_vault_config_report/archives b/repos/gems/recipes/pkg/test-file_vault/archives similarity index 59% rename from repos/gems/recipes/pkg/test-file_vault_config_report/archives rename to repos/gems/recipes/pkg/test-file_vault/archives index aee3408e2c..38b5c7edcb 100644 --- a/repos/gems/recipes/pkg/test-file_vault_config_report/archives +++ b/repos/gems/recipes/pkg/test-file_vault/archives @@ -1,4 +1,4 @@ -_/pkg/file_vault_config_report +_/pkg/file_vault _/src/report_rom _/src/dynamic_rom _/src/vfs diff --git a/repos/gems/recipes/pkg/test-file_vault_config_report/hash b/repos/gems/recipes/pkg/test-file_vault/hash similarity index 100% rename from repos/gems/recipes/pkg/test-file_vault_config_report/hash rename to repos/gems/recipes/pkg/test-file_vault/hash diff --git a/repos/gems/recipes/pkg/test-file_vault_config_report/runtime b/repos/gems/recipes/pkg/test-file_vault/runtime similarity index 94% rename from repos/gems/recipes/pkg/test-file_vault_config_report/runtime rename to repos/gems/recipes/pkg/test-file_vault/runtime index 91ade441cd..5f95dfb303 100644 --- a/repos/gems/recipes/pkg/test-file_vault_config_report/runtime +++ b/repos/gems/recipes/pkg/test-file_vault/runtime @@ -6,11 +6,11 @@ - <ui_report version="step_*" state="uninitialized"/>* - <ui_report version="step_*" state="initializing"/>* - <ui_report version="step_*" state="unlocked"/>* - <ui_report version="step_*" state="locked"/>* - <ui_report version="step_*" state="unlocked"/>* + <ui_report version="step_*" state="uninitialized"* + <ui_report version="step_*" state="initializing"* + <ui_report version="step_*" state="unlocked"* + <ui_report version="step_*" state="locked"* + <ui_report version="step_*" state="unlocked"* @@ -145,7 +145,7 @@ - + diff --git a/repos/gems/recipes/pkg/test-file_vault_config_report_no_entropy/README b/repos/gems/recipes/pkg/test-file_vault_no_entropy/README similarity index 100% rename from repos/gems/recipes/pkg/test-file_vault_config_report_no_entropy/README rename to repos/gems/recipes/pkg/test-file_vault_no_entropy/README diff --git a/repos/gems/recipes/pkg/test-file_vault_config_report_no_entropy/archives b/repos/gems/recipes/pkg/test-file_vault_no_entropy/archives similarity index 59% rename from repos/gems/recipes/pkg/test-file_vault_config_report_no_entropy/archives rename to repos/gems/recipes/pkg/test-file_vault_no_entropy/archives index aee3408e2c..38b5c7edcb 100644 --- a/repos/gems/recipes/pkg/test-file_vault_config_report_no_entropy/archives +++ b/repos/gems/recipes/pkg/test-file_vault_no_entropy/archives @@ -1,4 +1,4 @@ -_/pkg/file_vault_config_report +_/pkg/file_vault _/src/report_rom _/src/dynamic_rom _/src/vfs diff --git a/repos/gems/recipes/pkg/test-file_vault_config_report_no_entropy/hash b/repos/gems/recipes/pkg/test-file_vault_no_entropy/hash similarity index 100% rename from repos/gems/recipes/pkg/test-file_vault_config_report_no_entropy/hash rename to repos/gems/recipes/pkg/test-file_vault_no_entropy/hash diff --git a/repos/gems/recipes/pkg/test-file_vault_config_report_no_entropy/runtime b/repos/gems/recipes/pkg/test-file_vault_no_entropy/runtime similarity index 94% rename from repos/gems/recipes/pkg/test-file_vault_config_report_no_entropy/runtime rename to repos/gems/recipes/pkg/test-file_vault_no_entropy/runtime index 676a90e92c..ababdda86b 100644 --- a/repos/gems/recipes/pkg/test-file_vault_config_report_no_entropy/runtime +++ b/repos/gems/recipes/pkg/test-file_vault_no_entropy/runtime @@ -6,11 +6,11 @@ - <ui_report version="step_*" state="uninitialized"/>* - <ui_report version="step_*" state="initializing"/>* - <ui_report version="step_*" state="unlocked"/>* - <ui_report version="step_*" state="locked"/>* - <ui_report version="step_*" state="unlocked"/>* + <ui_report version="step_*" state="uninitialized"* + <ui_report version="step_*" state="initializing"* + <ui_report version="step_*" state="unlocked"* + <ui_report version="step_*" state="locked"* + <ui_report version="step_*" state="unlocked"* @@ -145,7 +145,7 @@ - + diff --git a/repos/gems/recipes/src/file_vault_gui/content.mk b/repos/gems/recipes/src/file_vault_gui/content.mk new file mode 100644 index 0000000000..0ab88b8045 --- /dev/null +++ b/repos/gems/recipes/src/file_vault_gui/content.mk @@ -0,0 +1,14 @@ +SRC_DIR := src/app/file_vault_gui +MIRROR_FROM_REP_DIR := \ + lib/mk/dialog.mk src/lib/dialog include/dialog src/app/file_vault/include \ + src/lib/tresor/include/tresor/types.h \ + src/lib/tresor/include/tresor/assertion.h \ + src/lib/tresor/include/tresor/verbosity.h \ + src/lib/tresor/include/tresor/math.h + +content: $(MIRROR_FROM_REP_DIR) + +$(MIRROR_FROM_REP_DIR): + $(mirror_from_rep_dir) + +include $(GENODE_DIR)/repos/base/recipes/src/content.inc diff --git a/repos/gems/recipes/src/file_vault_gui/hash b/repos/gems/recipes/src/file_vault_gui/hash new file mode 100644 index 0000000000..6cee2b0120 --- /dev/null +++ b/repos/gems/recipes/src/file_vault_gui/hash @@ -0,0 +1 @@ +2024-04-23-l 9b6c3e2457e3cc22233bd9f82aa191bdff79cfdf diff --git a/repos/gems/recipes/src/file_vault_gui/used_apis b/repos/gems/recipes/src/file_vault_gui/used_apis new file mode 100644 index 0000000000..ccc405aac9 --- /dev/null +++ b/repos/gems/recipes/src/file_vault_gui/used_apis @@ -0,0 +1,8 @@ +base +os +gems +report_session +gui_session +input_session +framebuffer_session +sandbox diff --git a/repos/gems/run/depot_autopilot.run b/repos/gems/run/depot_autopilot.run index 8b4b9eb5b0..9d85ab7fa7 100644 --- a/repos/gems/run/depot_autopilot.run +++ b/repos/gems/run/depot_autopilot.run @@ -662,8 +662,8 @@ set default_test_pkgs { test-entrypoint test-expat test-fault_detection - test-file_vault_config_report - test-file_vault_config_report_no_entropy + test-file_vault + test-file_vault_no_entropy test-fs_packet test-fs_report test-fs_rom_update @@ -775,12 +775,12 @@ proc skip_test_if { condition test } { # # pbxa9 and zynq_qemu don't support jitterentropy # -skip_test_if [expr ([have_board pbxa9] || [have_board zynq_qemu])] test-file_vault_config_report -skip_test_if [expr !([have_board pbxa9] || [have_board zynq_qemu])] test-file_vault_config_report_no_entropy +skip_test_if [expr ([have_board pbxa9] || [have_board zynq_qemu])] test-file_vault +skip_test_if [expr !([have_board pbxa9] || [have_board zynq_qemu])] test-file_vault_no_entropy # rpi has a quite limited amount of RAM -skip_test_if [have_board rpi] test-file_vault_config_report -skip_test_if [have_board rpi] test-file_vault_config_report_no_entropy +skip_test_if [have_board rpi] test-file_vault +skip_test_if [have_board rpi] test-file_vault_no_entropy set skip_test(test-fault_detection) [expr [have_spec pistachio] || [have_spec fiasco]] set skip_test(test-fs_packet) [expr ![interactive] && [have_include "power_on/qemu"]] @@ -800,8 +800,8 @@ if {[have_spec foc]} { set skip_test(test-libc) [have_board pbxa9] set skip_test(test-tcp_bulk_lxip) [have_board pbxa9] # foc on pbxa9 caps RAM at 256 MiB - skip tests with excessive RAM demand - skip_test_if [have_board pbxa9] test-file_vault_config_report - skip_test_if [have_board pbxa9] test-file_vault_config_report_no_entropy + skip_test_if [have_board pbxa9] test-file_vault + skip_test_if [have_board pbxa9] test-file_vault_no_entropy } if {[have_spec riscv]} { set skip_test(gcov) true @@ -814,7 +814,7 @@ if {[have_spec riscv]} { set skip_test(test-tcp_bulk_lxip) true set skip_test(test-trace_logger) true set skip_test(test-xml_generator) true - set skip_test(test-file_vault_config_report) true + set skip_test(test-file_vault) true } # diff --git a/repos/gems/run/file_vault.inc b/repos/gems/run/file_vault.inc deleted file mode 100644 index 940353d866..0000000000 --- a/repos/gems/run/file_vault.inc +++ /dev/null @@ -1,423 +0,0 @@ -proc ui_is { arg } { - - global ui - return [string equal $arg $ui ] -} - -proc jent_avail { } { - - if {[have_board pbxa9]} { return 0 } - if {[have_board zynq_qemu]} { return 0 } - return 1 -} - -proc jent_avail_attr { } { - - if {[jent_avail]} { return "yes" } - return "no" -} - -build { app/file_vault } - -create_boot_directory - -append archives " - [depot_user]/src/[base_src] - [depot_user]/src/init - [depot_user]/src/libc - [depot_user]/src/zlib - [depot_user]/src/fs_query - [depot_user]/src/tresor - [depot_user]/src/vfs_block - [depot_user]/src/vfs - [depot_user]/src/openssl - [depot_user]/src/fs_tool - [depot_user]/src/fs_utils - [depot_user]/src/posix - [depot_user]/src/rump - [depot_user]/src/sandbox -" - -append_if [jent_avail] archives " [depot_user]/src/vfs_jitterentropy " - -lappend_if [ui_is menu_view] archives [depot_user]/src/nitpicker -lappend_if [ui_is menu_view] archives [depot_user]/src/menu_view -lappend_if [ui_is menu_view] archives [depot_user]/src/libpng -lappend_if [ui_is menu_view] archives [depot_user]/pkg/fonts_fs -lappend_if [ui_is menu_view] archives [depot_user]/pkg/[drivers_interactive_pkg] - -lappend_if [ui_is config_and_report] archives [depot_user]/src/report_rom -lappend_if [ui_is config_and_report] archives [depot_user]/src/dynamic_rom - -lappend_if [have_board linux] archives [depot_user]/src/lx_fs - -import_from_depot $archives - -append config { - - - - - - - - - - - - - - - - - - - - - - - - - - - -} -append_if [ui_is menu_view] config { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -} -append_if [ui_is config_and_report] config { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -} -if {[have_board linux]} { - - append config { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - } - -} else { - - append config { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - } -} -append config { - - - - - - - - - - - -} -append_if [ui_is menu_view] config { - - - -} -append_if [ui_is config_and_report] config { - - - -} -append config { - - - - - - - - - - - - - - - - - -} - -install_config $config - -if {[have_board linux]} { - - if {[ui_is config_and_report]} { - - exec rm -rf bin/file_vault_dir - } - exec mkdir -p bin/file_vault_dir/data - exec mkdir -p bin/file_vault_dir/trust_anchor -} - -append boot_modules [build_artifacts] - -lappend_if [have_board linux] boot_modules file_vault_dir - -if {[ui_is menu_view]} { - - set fd [open [run_dir]/genode/focus w] - puts $fd " \"/>" - close $fd - - append qemu_args " -display gtk " - build_boot_image $boot_modules - run_genode_until forever -} - -if {[ui_is config_and_report]} { - - build_boot_image $boot_modules - - append exp_output {.*.*\n} - append exp_output {.*.*\n} - append exp_output {.*.*\n} - append exp_output {.*.*\n} - append exp_output {.*.*\n} - - append qemu_args " -display none " - run_genode_until $exp_output 70 -} diff --git a/repos/gems/run/file_vault.run b/repos/gems/run/file_vault.run index 0116aa796f..12da9639a8 100644 --- a/repos/gems/run/file_vault.run +++ b/repos/gems/run/file_vault.run @@ -1,2 +1,279 @@ -set ui "menu_view" -source ${genode_dir}/repos/gems/run/file_vault.inc +proc jent_avail { } { + + if {[have_board pbxa9]} { return 0 } + if {[have_board zynq_qemu]} { return 0 } + return 1 +} + +proc jent_avail_attr { } { + + if {[jent_avail]} { return "yes" } + return "no" +} + +build { app/file_vault } + +create_boot_directory + +append archives " + [depot_user]/src/[base_src] + [depot_user]/src/init + [depot_user]/src/libc + [depot_user]/src/zlib + [depot_user]/src/fs_query + [depot_user]/src/tresor + [depot_user]/src/vfs_block + [depot_user]/src/vfs + [depot_user]/src/openssl + [depot_user]/src/fs_tool + [depot_user]/src/fs_utils + [depot_user]/src/posix + [depot_user]/src/rump + [depot_user]/src/sandbox + [depot_user]/src/report_rom + [depot_user]/src/dynamic_rom +" + +append_if [jent_avail] archives " [depot_user]/src/vfs_jitterentropy " + +lappend_if [have_board linux] archives [depot_user]/src/lx_fs + +import_from_depot $archives + +append config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +append_if [have_board linux] config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +append_if [expr ![have_board linux]] config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +append config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +install_config $config + +if {[have_board linux]} { + exec rm -rf bin/file_vault_dir + exec mkdir -p bin/file_vault_dir/data + exec mkdir -p bin/file_vault_dir/trust_anchor +} + +append boot_modules [build_artifacts] + +lappend_if [have_board linux] boot_modules file_vault_dir + +build_boot_image $boot_modules + +append exp_output {.* - + @@ -437,7 +437,7 @@ lappend_if [have_board linux] boot_modules [file tail [lx_fs_dir]] build_boot_image $boot_modules append qemu_args " -display none " -run_genode_until ".*\n" 100 +run_genode_until " dynamic_init -> log_terminal\].*} diff --git a/repos/gems/run/file_vault_config_report.run b/repos/gems/run/file_vault_config_report.run deleted file mode 100644 index 675721dc29..0000000000 --- a/repos/gems/run/file_vault_config_report.run +++ /dev/null @@ -1,2 +0,0 @@ -set ui "config_and_report" -source ${genode_dir}/repos/gems/run/file_vault.inc diff --git a/repos/gems/run/file_vault_gui.run b/repos/gems/run/file_vault_gui.run new file mode 100644 index 0000000000..059cddac67 --- /dev/null +++ b/repos/gems/run/file_vault_gui.run @@ -0,0 +1,311 @@ +proc jent_avail { } { + if {[have_board pbxa9]} { return 0 } + if {[have_board zynq_qemu]} { return 0 } + return 1 +} + +proc jent_avail_attr { } { + if {[jent_avail]} { return "yes" } + return "no" +} + +build { app/file_vault app/file_vault_gui } + +create_boot_directory + +append archives " + [depot_user]/src/[base_src] + [depot_user]/src/init + [depot_user]/src/libc + [depot_user]/src/zlib + [depot_user]/src/fs_query + [depot_user]/src/tresor + [depot_user]/src/vfs_block + [depot_user]/src/report_rom + [depot_user]/src/vfs + [depot_user]/src/openssl + [depot_user]/src/fs_tool + [depot_user]/src/fs_utils + [depot_user]/src/posix + [depot_user]/src/rump + [depot_user]/src/sandbox" + +append_if [jent_avail] archives " [depot_user]/src/vfs_jitterentropy " + +lappend archives [depot_user]/src/nitpicker +lappend archives [depot_user]/src/menu_view +lappend archives [depot_user]/src/libpng +lappend archives [depot_user]/pkg/fonts_fs +lappend archives [depot_user]/pkg/[drivers_interactive_pkg] + +lappend_if [have_board linux] archives [depot_user]/src/lx_fs + +import_from_depot $archives + +append config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +append_if [have_board linux] config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +append_if [expr ![have_board linux]] config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +append config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +install_config $config + +if {[have_board linux]} { + exec mkdir -p bin/file_vault_gui_dir/data + exec mkdir -p bin/file_vault_gui_dir/trust_anchor +} +append boot_modules [build_artifacts] + +lappend_if [have_board linux] boot_modules file_vault_gui_dir + +set fd [open [run_dir]/genode/focus w] +puts $fd " \"/>" +close $fd + +append qemu_args " -display gtk " +build_boot_image $boot_modules +run_genode_until forever diff --git a/repos/gems/src/app/file_vault/README b/repos/gems/src/app/file_vault/README index 16d0832ad0..c3a2312ab1 100644 --- a/repos/gems/src/app/file_vault/README +++ b/repos/gems/src/app/file_vault/README @@ -32,10 +32,7 @@ The file vault doesn't consider runtime modifications to its "normal" configuration (in contrast to modifications to the UI configuration in "config and report" mode). This is an example File Vault configuration: -! -! +! ! ! ! @@ -43,12 +40,9 @@ and report" mode). This is an example File Vault configuration: ! ! -The "user_interface" attribute knows the two values "config_and_report" and -"menu_view" with the latter being the default. The verbosity attributes are all +The verbosity attributes are all set to "no" by default. If "verbose_state" is set to "yes" the vault will -reflect its internal state at the LOG session. If "verbose_ui_config" is set to -"yes" the vault will reflect the state of the applied UI config at the LOG -session (user passphrases are not exposed to the LOG session). +reflect its internal state at the LOG session. The vault currently still requires a directory named "tresor" to be present in its local VFS. The vault will store a very small file "./file_vault/state" inside @@ -150,8 +144,7 @@ configuration and one Report session for UI reports. Further resources ~~~~~~~~~~~~~~~~~ -The test scripts _gems/recipes/pkg/test-file_vault_config_report_, -_gems/run/file_vault.run_, and_gems/run/file_vault_config_report.run_ +The test scripts _gems/recipes/pkg/test-file_vault_ and _gems/run/file_vault.run_ provide examples on how to manually integrate the file vault. The latter can also be used for analyzing and developing the vault - when targeting native Linux execution even with a persistent storage back-end. The file vault was diff --git a/repos/gems/src/app/file_vault/capacity.cc b/repos/gems/src/app/file_vault/capacity.cc deleted file mode 100644 index b8d18b3a71..0000000000 --- a/repos/gems/src/app/file_vault/capacity.cc +++ /dev/null @@ -1,58 +0,0 @@ -/* - * \brief Printable byte capacity - * \author Norman Feske - * \author Martin Stein - * \date 2018-04-30 - */ - -/* - * Copyright (C) 2018 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -/* local includes */ -#include - - -/************** - ** Capacity_** - **************/ - -void File_vault::Capacity::print(Output &out) const -{ - static constexpr uint64_t KB = 1024; - static constexpr uint64_t MB = 1024 * KB; - static constexpr uint64_t GB = 1024 * MB; - - Text const text { - (_value >= GB) ? Text((float)_value/GB, " GiB") : - (_value >= MB) ? Text((float)_value/MB, " MiB") : - (_value >= KB) ? Text((float)_value/KB, " KiB") : - Text(_value, " bytes") }; - - Genode::print(out, text); -} - - -File_vault::Capacity::Capacity(uint64_t value) -: - _value { value } -{ } - - -/********************* - ** Capacity_string ** - *********************/ - -File_vault::Capacity_string::Capacity_string(uint64_t value) -: - Capacity::Text { Capacity { value } } -{ } - - -File_vault::Capacity_string::operator char const *() -{ - return Capacity::Text::string(); -} diff --git a/repos/gems/src/app/file_vault/capacity.h b/repos/gems/src/app/file_vault/capacity.h deleted file mode 100644 index 46dd1b34be..0000000000 --- a/repos/gems/src/app/file_vault/capacity.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * \brief Printable byte capacity - * \author Norman Feske - * \author Martin Stein - * \date 2018-04-30 - */ - -/* - * Copyright (C) 2018 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -#ifndef _CAPACITY_H_ -#define _CAPACITY_H_ - -/* local includes */ -#include - -namespace File_vault { - - class Capacity; - class Capacity_string; -} - -class File_vault::Capacity -{ - private: - - uint64_t const _value; - - public: - - using Text = String<64>; - - Capacity(uint64_t value); - - void print(Output &out) const; -}; - -class File_vault::Capacity_string : public Capacity::Text -{ - public: - - Capacity_string(uint64_t value); - - operator char const *(); -}; - -#endif /* _CAPACITY_H_ */ diff --git a/repos/gems/src/app/file_vault/dynamic_array.h b/repos/gems/src/app/file_vault/dynamic_array.h deleted file mode 100644 index 12407e274e..0000000000 --- a/repos/gems/src/app/file_vault/dynamic_array.h +++ /dev/null @@ -1,194 +0,0 @@ -/* - * \brief Dynamically growing array - * \author Norman Feske - * \date 2020-01-12 - */ - -/* - * Copyright (C) 2020 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -#ifndef _DYNAMIC_ARRAY_H_ -#define _DYNAMIC_ARRAY_H_ - -/* Genode includes */ -#include - -namespace File_vault { - - using namespace Genode; - - template - struct Dynamic_array; -} - - -template -struct File_vault::Dynamic_array -{ - public: - - struct Index { unsigned value; }; - - private: - - Allocator &_alloc; - - using Element = Constructible; - - Element *_array = nullptr; - - unsigned _capacity = 0; - unsigned _upper_bound = 0; /* index after last used element */ - - bool _index_valid(Index at) const - { - return (at.value < _upper_bound) && _array[at.value].constructed(); - } - - /* - * Noncopyable - */ - Dynamic_array(Dynamic_array const &other); - void operator = (Dynamic_array const &); - - public: - - /** - * Moving constructor - */ - Dynamic_array(Dynamic_array &other) - : - _alloc(other._alloc), _array(other._array), - _capacity(other._capacity), _upper_bound(other._upper_bound) - { - other._array = nullptr; - other._capacity = 0; - other._upper_bound = 0; - } - - Dynamic_array(Allocator &alloc) : _alloc(alloc) { } - - ~Dynamic_array() - { - if (!_array) - return; - - clear(); - - _alloc.free(_array, _capacity*sizeof(Element)); - } - - void clear() - { - if (_upper_bound > 0) - for (unsigned i = _upper_bound; i > 0; i--) - destruct(Index{i - 1}); - } - - template - void insert(Index at, ARGS &&... args) - { - /* grow array if index exceeds current capacity or if it's full */ - if (at.value >= _capacity || _upper_bound == _capacity) { - - size_t const new_capacity = - 2 * max(_capacity, max(8U, at.value)); - - Element *new_array = nullptr; - try { - (void)_alloc.alloc(sizeof(Element)*new_capacity, &new_array); - - for (unsigned i = 0; i < new_capacity; i++) - construct_at(&new_array[i]); - } - catch (... /* Out_of_ram, Out_of_caps */ ) { throw; } - - if (_array) { - for (unsigned i = 0; i < _upper_bound; i++) - new_array[i].construct(*_array[i]); - - _alloc.free(_array, sizeof(Element)*_capacity); - } - - _array = new_array; - _capacity = new_capacity; - } - - /* make room for new element */ - if (_upper_bound > 0) - for (unsigned i = _upper_bound; i > at.value; i--) - _array[i].construct(*_array[i - 1]); - - _array[at.value].construct(args...); - - _upper_bound = max(at.value + 1, _upper_bound + 1); - } - - template - void append(ARGS &&... args) { insert(Index{_upper_bound}, args...); } - - bool exists(Index at) const { return _index_valid(at); } - - Index upper_bound() const { return Index { _upper_bound }; } - - void destruct(Index at) - { - if (!_index_valid(at)) - return; - - _array[at.value].destruct(); - - if (_upper_bound > 0) - for (unsigned i = at.value; i < _upper_bound - 1; i++) - _array[i].construct(*_array[i + 1]); - - _upper_bound--; - _array[_upper_bound].destruct(); - } - - template - void apply(Index at, FN const &fn) - { - if (_index_valid(at)) - fn(*_array[at.value]); - } - - template - void apply(Index at, FN const &fn) const - { - if (_index_valid(at)) - fn(*_array[at.value]); - } - - struct Range { Index at; unsigned length; }; - - template - void for_each(Range range, FN const &fn) const - { - unsigned const first = range.at.value; - unsigned const limit = min(_upper_bound, first + range.length); - - for (unsigned i = first; i < limit; i++) - if (_array[i].constructed()) - fn(Index{i}, *_array[i]); - } - - template - void for_each(FN const &fn) const - { - for_each(Range { .at = { 0U }, .length = ~0U }, fn); - } - - void print(Output &out) const - { - for (unsigned i = 0; i < _upper_bound; i++) - if (_array[i].constructed()) - Genode::print(out, *_array[i]); - } -}; - -#endif /* _DYNAMIC_ARRAY_H_ */ diff --git a/repos/gems/src/app/file_vault/gui_input_event_handler.h b/repos/gems/src/app/file_vault/gui_input_event_handler.h deleted file mode 100644 index 6f0a04dc0d..0000000000 --- a/repos/gems/src/app/file_vault/gui_input_event_handler.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * \brief Interface for handling input events - * \author Norman Feske - * \date 2018-05-02 - */ - -/* - * Copyright (C) 2018 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -#ifndef _GUI_INPUT_EVENT_HANDLER_H_ -#define _GUI_INPUT_EVENT_HANDLER_H_ - -/* Genode includes */ -#include -#include - -namespace Gui { struct Input_event_handler; } - -struct Gui::Input_event_handler : Genode::Interface -{ - virtual void handle_input_event(Input::Event const &) = 0; -}; - -#endif /* _GUI_INPUT_EVENT_HANDLER_H_ */ diff --git a/repos/gems/src/app/file_vault/gui_session_component.h b/repos/gems/src/app/file_vault/gui_session_component.h deleted file mode 100644 index 7ad183058e..0000000000 --- a/repos/gems/src/app/file_vault/gui_session_component.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * \brief GUI wrapper for monitoring the user input of GUI components - * \author Norman Feske - * \date 2020-01-12 - */ - -/* - * Copyright (C) 2020 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -#ifndef _GUI_SESSION_COMPONENT_H_ -#define _GUI_SESSION_COMPONENT_H_ - -/* Genode includes */ -#include -#include -#include - -/* local includes */ -#include - -namespace Gui { - - using namespace Genode; - - struct Session_component; -} - - -struct Gui::Session_component : Session_object -{ - Env &_env; - - Input_event_handler &_event_handler; - - Gui::Connection _connection; - - Input::Session_component _input_component { _env, _env.ram() }; - - Signal_handler _input_handler { - _env.ep(), *this, &Session_component::_handle_input }; - - void _handle_input() - { - _connection.input()->for_each_event([&] (Input::Event ev) { - - /* handle event locally within the sculpt manager */ - _event_handler.handle_input_event(ev); - - _input_component.submit(ev); - }); - } - - template - Session_component(Env &env, Input_event_handler &event_handler, ARGS &&... args) - : - Session_object(args...), - _env(env), _event_handler(event_handler), - _connection(env, _label.string()) - { - _connection.input()->sigh(_input_handler); - _env.ep().manage(_input_component); - _input_component.event_queue().enabled(true); - } - - ~Session_component() { _env.ep().dissolve(_input_component); } - - void upgrade(Session::Resources const &resources) - { - _connection.upgrade(resources); - } - - Framebuffer::Session_capability framebuffer_session() override { - return _connection.framebuffer_session(); } - - Input::Session_capability input_session() override { - return _input_component.cap(); } - - View_handle create_view(View_handle parent) override { - return _connection.create_view(parent); } - - void destroy_view(View_handle view) override { - _connection.destroy_view(view); } - - View_handle view_handle(View_capability view_cap, View_handle handle) override { - return _connection.view_handle(view_cap, handle); } - - View_capability view_capability(View_handle view) override { - return _connection.view_capability(view); } - - void release_view_handle(View_handle view) override { - _connection.release_view_handle(view); } - - Dataspace_capability command_dataspace() override { - return _connection.command_dataspace(); } - - void execute() override { - _connection.execute(); } - - Framebuffer::Mode mode() override { - return _connection.mode(); } - - void mode_sigh(Signal_context_capability sigh) override { - _connection.mode_sigh(sigh); } - - void buffer(Framebuffer::Mode mode, bool use_alpha) override - { - /* - * Do not call 'Connection::buffer' to avoid paying session quota - * from our own budget. - */ - _connection.Client::buffer(mode, use_alpha); - } - - void focus(Capability session) override { - _connection.focus(session); } -}; - -#endif /* _GUI_SESSION_COMPONENT_H_ */ diff --git a/repos/gems/src/app/file_vault/include/file_vault/types.h b/repos/gems/src/app/file_vault/include/file_vault/types.h new file mode 100644 index 0000000000..3b9ce7c1e4 --- /dev/null +++ b/repos/gems/src/app/file_vault/include/file_vault/types.h @@ -0,0 +1,297 @@ +/* + * \brief Common types + * \author Martin Stein + * \date 2021-02-25 + */ + +/* + * Copyright (C) 2021 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#ifndef _FILE_VAULT__TYPES_H_ +#define _FILE_VAULT__TYPES_H_ + +/* Genode includes */ +#include + +namespace File_vault { + + using namespace Tresor; + using namespace Genode; + + static constexpr Tree_degree TRESOR_VBD_DEGREE = 64; + static constexpr Tree_level_index TRESOR_VBD_MAX_LVL = 5; + static constexpr Tree_degree TRESOR_FREE_TREE_DEGREE = 64; + static constexpr Tree_level_index TRESOR_FREE_TREE_MAX_LVL = 5; + static constexpr size_t MIN_CLIENT_FS_SIZE = 100 * 1024; + static constexpr size_t MIN_PASSPHRASE_LENGTH = 8; + + struct Number_of_clients { uint64_t value; }; + struct Operation_id { uint64_t value; }; + + + using Version_string = String<80>; + + template + static void read_optional_attr(Xml_node const &node, char const *attr, Constructible &dst) + { + if (node.has_attribute(attr)) + dst.construct(node.attribute_value(attr, T { })); + } + + struct Ui_report + { + using State_string = String<32>; + + enum State { + INVALID, UNINITIALIZED, INITIALIZING, LOCKED, UNLOCKING, UNLOCKED, LOCKING }; + + static State_string state_to_string(State state) + { + switch (state) { + case INVALID: return "invalid"; + case UNINITIALIZED: return "uninitialized"; + case INITIALIZING: return "initializing"; + case LOCKED: return "locked"; + case UNLOCKING: return "unlocking"; + case UNLOCKED: return "unlocked"; + case LOCKING: return "locking"; + } + ASSERT_NEVER_REACHED; + } + + static State string_to_state(State_string str) + { + if (str == "uninitialized") return UNINITIALIZED; + if (str == "initializing") return INITIALIZING; + if (str == "locked") return LOCKED; + if (str == "unlocking") return UNLOCKING; + if (str == "unlocked") return UNLOCKED; + if (str == "locking") return LOCKING; + return INVALID; + } + + struct Rekey + { + Operation_id id; + bool finished; + + Rekey(Xml_node const &node) + : id(node.attribute_value("id", 0ULL)), finished(node.attribute_value("finished", false)) { } + + Rekey(Operation_id id, bool finished) : id(id), finished(finished) { } + + void generate(Xml_generator &xml) + { + xml.attribute("id", id.value); + xml.attribute("finished", finished); + } + }; + + struct Extend + { + Operation_id id { }; + bool finished { }; + + Extend(Xml_node const &node) + : id(node.attribute_value("id", 0ULL)), finished(node.attribute_value("finished", false)) { } + + Extend(Operation_id id, bool finished) : id(id), finished(finished) { } + + void generate(Xml_generator &xml) + { + xml.attribute("id", id.value); + xml.attribute("finished", finished); + } + }; + + State state { INVALID }; + Version_string version { }; + Number_of_bytes image_size { }; + Number_of_bytes capacity { }; + Number_of_clients num_clients { }; + Constructible rekey { }; + Constructible extend { }; + + Ui_report() { } + + Ui_report(Xml_node const &node) + : + state(string_to_state(node.attribute_value("state", State_string()))), + version(node.attribute_value("version", Version_string())), + image_size(node.attribute_value("image_size", Number_of_bytes())), + capacity(node.attribute_value("capacity", Number_of_bytes())), + num_clients(node.attribute_value("num_clients", 0ULL)) + { + node.with_optional_sub_node("rekey", [&] (Xml_node const &n) { rekey.construct(n); }); + node.with_optional_sub_node("extend", [&] (Xml_node const &n) { extend.construct(n); }); + } + + void generate(Xml_generator &xml) + { + xml.attribute("state", state_to_string(state)); + xml.attribute("version", version); + xml.attribute("image_size", image_size); + xml.attribute("capacity", capacity); + xml.attribute("num_clients", num_clients.value); + if (rekey.constructed()) + xml.node("rekey", [&] { rekey->generate(xml); }); + if (extend.constructed()) + xml.node("extend", [&] { extend->generate(xml); }); + } + }; + + struct Ui_config + { + struct Extend + { + using Tree_string = String<4>; + + enum Tree { VIRTUAL_BLOCK_DEVICE, FREE_TREE }; + + Operation_id id; + Tree tree; + Number_of_bytes num_bytes; + + static Tree string_to_tree(Tree_string const &str) + { + if (str == "vbd") return VIRTUAL_BLOCK_DEVICE; + if (str == "ft") return FREE_TREE; + ASSERT_NEVER_REACHED; + } + + static Tree_string tree_to_string(Tree tree_arg) + { + switch (tree_arg) { + case VIRTUAL_BLOCK_DEVICE: return "vbd"; + case FREE_TREE: return "ft"; } + ASSERT_NEVER_REACHED; + } + + Extend(Xml_node const &node) + : + id(node.attribute_value("id", 0ULL)), + tree(string_to_tree(node.attribute_value("tree", Tree_string()))), + num_bytes(node.attribute_value("num_bytes", 0UL)) + { } + + Extend(Operation_id id, Tree tree, Number_of_bytes num_bytes) : id(id), tree(tree), num_bytes(num_bytes) { } + + void generate(Xml_generator &xml) + { + xml.attribute("id", id.value); + xml.attribute("tree", tree_to_string(tree)); + xml.attribute("num_bytes", num_bytes); + } + }; + + struct Rekey + { + Operation_id id; + + Rekey(Xml_node const &node) : id(node.attribute_value("id", 0ULL)) { } + + Rekey(Operation_id id) : id(id) { } + + void generate(Xml_generator &xml) { xml.attribute("id", id.value); } + }; + + Version_string version { }; + Passphrase passphrase { }; + Number_of_bytes client_fs_size { }; + Number_of_bytes journaling_buf_size { }; + Constructible rekey { }; + Constructible extend { }; + + Ui_config(Xml_node const &node) + : + version(node.attribute_value("version", Version_string())), + passphrase(node.attribute_value("passphrase", Passphrase())), + client_fs_size(node.attribute_value("client_fs_size", Number_of_bytes())), + journaling_buf_size(node.attribute_value("journaling_buf_size", Number_of_bytes())) + { + node.with_optional_sub_node("rekey", [&] (Xml_node const &n) { rekey.construct(n); }); + node.with_optional_sub_node("extend", [&] (Xml_node const &n) { extend.construct(n); }); + } + + Ui_config() { } + + void generate(Xml_generator &xml) + { + xml.attribute("passphrase", passphrase); + xml.attribute("client_fs_size", client_fs_size); + xml.attribute("journaling_buf_size", journaling_buf_size); + if (rekey.constructed()) + xml.node("rekey", [&] { rekey->generate(xml); }); + if (extend.constructed()) + xml.node("extend", [&] { extend->generate(xml); }); + } + + bool passphrase_long_enough() const { return passphrase.length() >= MIN_PASSPHRASE_LENGTH + 1; } + }; + + inline Number_of_blocks tresor_tree_num_blocks(size_t num_lvls, + size_t num_children, + Number_of_leaves num_leaves) + { + Number_of_blocks num_blks { 0 }; + Number_of_blocks num_last_lvl_blks { num_leaves }; + for (size_t lvl_idx { 0 }; lvl_idx < num_lvls; lvl_idx++) { + num_blks += num_last_lvl_blks; + if (num_last_lvl_blks % num_children) { + num_last_lvl_blks = num_last_lvl_blks / num_children + 1; + } else { + num_last_lvl_blks = num_last_lvl_blks / num_children; + } + } + return num_blks; + } + + inline Number_of_blocks tresor_num_blocks(Number_of_blocks num_superblocks, + size_t num_vbd_lvls, + size_t num_vbd_children, + Number_of_leaves num_vbd_leaves, + size_t num_ft_lvls, + size_t num_ft_children, + Number_of_leaves num_ft_leaves) + { + Number_of_blocks const num_vbd_blks { + tresor_tree_num_blocks(num_vbd_lvls, num_vbd_children, num_vbd_leaves) }; + + Number_of_blocks const num_ft_blks { + tresor_tree_num_blocks(num_ft_lvls, num_ft_children, num_ft_leaves) }; + + /* FIXME + * + * This would be the correct way to calculate the number of MT blocks + * but the Tresor still uses an MT the same size as the FT for simplicity + * reasons. As soon as the Tresor does it right we should fix also this path. + * + * size_t const num_mt_leaves { + * num_ft_blks - num_ft_leaves }; + * + * size_t const num_mt_blks { + * _tree_num_blocks( + * num_mt_lvls, + * num_mt_children, + * num_mt_leaves) }; + */ + Number_of_blocks const num_mt_blks { num_ft_blks }; + + return num_superblocks + num_vbd_blks + num_ft_blks + num_mt_blks; + } + + inline Number_of_blocks tresor_tree_num_leaves(uint64_t payload_size) + { + Number_of_blocks num_leaves { payload_size / BLOCK_SIZE }; + if (payload_size % BLOCK_SIZE) { + num_leaves++; + } + return num_leaves; + } +} + +#endif /* _FILE_VAULT__TYPES_H_ */ diff --git a/repos/gems/src/app/file_vault/input.h b/repos/gems/src/app/file_vault/input.h deleted file mode 100644 index c203713bdb..0000000000 --- a/repos/gems/src/app/file_vault/input.h +++ /dev/null @@ -1,251 +0,0 @@ -/* - * \brief Text buffer for a passphrase - * \author Norman Feske - * \author Martin Stein - * \date 2021-03-02 - */ - -/* - * Copyright (C) 2021 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -#ifndef _INPUT_H_ -#define _INPUT_H_ - -/* Genode includes */ -#include -#include -#include - -/* local includes */ -#include - -namespace File_vault { - - class Input_single_line; - class Input_passphrase; - class Input_number_of_bytes; - class Input_number_of_blocks; -} - - -class File_vault::Input_single_line -{ - public: - - enum { MAX_LENGTH = 64 }; - - protected: - - Codepoint _characters[MAX_LENGTH] { }; - - unsigned _length = 0; - - void _print_characters(Output &out) const - { - /* - * FIXME This was copied from gems/src/server/terminal/main.cc - */ - - struct Utf8 { char b0, b1, b2, b3, b4; }; - - auto utf8_from_codepoint = [] (unsigned c) { - - /* extract 'n' bits 'at' bit position of value 'c' */ - auto bits = [c] (unsigned at, unsigned n) { - return (c >> at) & ((1 << n) - 1); }; - - return (c < 2<<7) ? Utf8 { char(bits( 0, 7)), 0, 0, 0, 0 } - : (c < 2<<11) ? Utf8 { char(bits( 6, 5) | 0xc0), - char(bits( 0, 6) | 0x80), 0, 0, 0 } - : (c < 2<<16) ? Utf8 { char(bits(12, 4) | 0xe0), - char(bits( 6, 6) | 0x80), - char(bits( 0, 6) | 0x80), 0, 0 } - : (c < 2<<21) ? Utf8 { char(bits(18, 3) | 0xf0), - char(bits(12, 6) | 0x80), - char(bits( 6, 6) | 0x80), - char(bits( 0, 6) | 0x80), 0 } - : Utf8 { }; - }; - - for (unsigned i = 0; i < _length; i++) { - - Utf8 const utf8 = utf8_from_codepoint(_characters[i].value); - - auto _print = [&] (char c) { - if (c) - Genode::print(out, Char(c)); }; - - _print(utf8.b0); _print(utf8.b1); _print(utf8.b2); - _print(utf8.b3); _print(utf8.b4); - } - } - - public: - - void append_character(Codepoint c) - { - if (_length < MAX_LENGTH) { - _characters[_length] = c; - _length++; - } - } - - void remove_last_character() - { - if (_length > 0) { - _length--; - _characters[_length].value = 0; - } - } - - bool equals(Input_single_line const &other) const - { - if (other._length != _length) { - return false; - } - if (memcmp(other._characters, _characters, _length) != 0) { - return false; - } - return true; - } - - unsigned length() const { return _length; } -}; - - - -class File_vault::Input_passphrase : public Input_single_line -{ - private: - - bool _hide { true }; - - void _print_bullets(Output &out) const - { - char const bullet_utf8[4] { - (char)0xe2, (char)0x80, (char)0xa2, 0 }; - - for (unsigned i = 0; i < _length; i++) - Genode::print(out, bullet_utf8); - } - - public: - - void print(Output &out) const - { - if (_hide) { - _print_bullets(out); - } else { - _print_characters(out); - } - } - - void hide(bool value) - { - _hide = value; - } - - bool hide() const - { - return _hide; - } - - bool appendable_character(Codepoint code) - { - if (!code.valid()) { - return false; - } - bool const is_printable { - code.value >= 0x20 && code.value < 0xf000 }; - - return is_printable; - } - - String plaintext() const - { - String result { }; - - auto write = [&] (char const *str) - { - result = Cstring(str, strlen(str)); - }; - Buffered_output output(write); - - _print_characters(output); - return result; - } -}; - - -class File_vault::Input_number_of_bytes : public Input_single_line -{ - public: - - void print(Output &out) const - { - _print_characters(out); - } - - size_t value() const - { - String<32> const str { *this }; - Number_of_bytes result { 0 }; - ascii_to(str.string(), result); - return result; - } - - bool appendable_character(Codepoint code) - { - if (!code.valid()) { - return false; - } - bool const is_number { - code.value >= 48 && code.value <= 57 }; - - bool const is_unit_prefix { - code.value == 71 || code.value == 75 || code.value == 77 }; - - return is_number || is_unit_prefix; - } -}; - - -class File_vault::Input_number_of_blocks : public Input_single_line -{ - public: - - void print(Output &out) const - { - _print_characters(out); - } - - unsigned long to_unsigned_long() const - { - String<32> const str { *this }; - unsigned long result { 0 }; - ascii_to(str.string(), result); - return result; - } - - bool is_nr_greater_than_zero() const - { - return (size_t)to_unsigned_long() > 0; - } - - bool appendable_character(Codepoint code) - { - if (!code.valid()) { - return false; - } - bool const is_number { - code.value >= 48 && code.value <= 57 }; - - return is_number; - } -}; - -#endif /* _INPUT_H_ */ diff --git a/repos/gems/src/app/file_vault/main.cc b/repos/gems/src/app/file_vault/main.cc index b1d75fe7c2..edc088ee84 100644 --- a/repos/gems/src/app/file_vault/main.cc +++ b/repos/gems/src/app/file_vault/main.cc @@ -14,11 +14,9 @@ /* Genode includes */ #include -#include #include #include #include -#include #include #include #include @@ -27,79 +25,22 @@ #include /* local includes */ -#include #include #include #include -#include -#include #include -#include -#include -#include -#include -namespace File_vault { - - enum { SHOW_CONTROLS_SNAPSHOTS = 0 }; - enum { SHOW_CONTROLS_SECURITY_MASTER_KEY = 0 }; - enum { SHOW_CONTROLS_SECURITY_USER_PASSPHRASE = 0 }; - enum { RENAME_SNAPSHOT_BUFFER_JOURNALING_BUFFER = 1 }; - enum { PASSPHRASE_MIN_NR_OF_CHARS = 8 }; - - class Ui_config; - class Main; -} - -struct File_vault::Ui_config -{ - using Version_string = String<80>; - - Version_string const version { }; - Passphrase const passphrase { }; - Number_of_bytes const client_fs_size { 0 }; - Number_of_bytes const journaling_buf_size { 0 }; - - Ui_config() { } - - Ui_config(Xml_node const &node, - bool verbose) - : - version { node.attribute_value("version", Version_string { }) }, - passphrase { node.attribute_value("passphrase", Passphrase { }) }, - client_fs_size { node.attribute_value("client_fs_size", Number_of_bytes { 0 }) }, - journaling_buf_size { node.attribute_value("journaling_buf_size", Number_of_bytes { 0 }) } - { - if (verbose) - log("ui_config: version \"", version, - "\" passphrase ", passphrase_suitable() ? "<" : " client_fs_size ", client_fs_size, - " journaling_buf_size ", journaling_buf_size); - } - - bool passphrase_suitable() const { return passphrase.length() >= PASSPHRASE_MIN_NR_OF_CHARS + 1; } -}; +namespace File_vault { class Main; } class File_vault::Main : private Sandbox::Local_service_base::Wakeup, - private Sandbox::State_handler, - private Gui::Input_event_handler, - private Dynamic_rom_session::Xml_producer + private Sandbox::State_handler { private: - static constexpr Tree_degree TRESOR_VBD_DEGREE = 64; - static constexpr Tree_level_index TRESOR_VBD_MAX_LVL = 5; - static constexpr Tree_degree TRESOR_FREE_TREE_DEGREE = 64; - static constexpr Tree_level_index TRESOR_FREE_TREE_MAX_LVL = 5; - enum { - MIN_CLIENT_FS_SIZE = 100 * 1024, STATE_STRING_CAPACITY = 64, - TRESOR_BLOCK_SIZE = 4096, - MAIN_FRAME_WIDTH = 46, - TRESOR_NR_OF_SUPERBLOCKS = 8, }; enum Version { INVALID, VERSION_21_05, VERSION_23_05 }; @@ -118,201 +59,11 @@ class File_vault::Main UNLOCK_RUN_TRESOR_INIT_TRUST_ANCHOR, UNLOCK_START_TRESOR_VFS, UNLOCK_DETERMINE_CLIENT_FS_SIZE, - CONTROLS_ROOT, - CONTROLS_SNAPSHOTS, - CONTROLS_DIMENSIONS, - CONTROLS_EXPAND_CLIENT_FS, - CONTROLS_EXPAND_SNAPSHOT_BUF, - CONTROLS_SECURITY, - CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY, - CONTROLS_SECURITY_MASTER_KEY, - CONTROLS_SECURITY_USER_PASSPHRASE, + CONTROLS, LOCK_ISSUE_DEINIT_REQUEST_AT_TRESOR, LOCK_WAIT_TILL_DEINIT_REQUEST_IS_DONE }; - enum class Reported_state - { - INVALID, - UNINITIALIZED, - INITIALIZING, - LOCKED, - UNLOCKING, - UNLOCKED, - LOCKING - }; - - enum class Setup_obtain_params_hover - { - NONE, - PASSPHRASE_INPUT, - PASSPHRASE_SHOW_HIDE_BUTTON, - CLIENT_FS_SIZE_INPUT, - SNAPSHOT_BUFFER_SIZE_INPUT, - START_BUTTON - }; - - enum class Setup_obtain_params_select - { - NONE, - PASSPHRASE_INPUT, - PASSPHRASE_SHOW_HIDE_BUTTON, - CLIENT_FS_SIZE_INPUT, - SNAPSHOT_BUFFER_SIZE_INPUT, - START_BUTTON - }; - - enum class Controls_root_select - { - NONE, - LOCK_BUTTON, - }; - - enum class Controls_root_hover - { - NONE, - SNAPSHOTS_EXPAND_BUTTON, - DIMENSIONS_BUTTON, - SECURITY_EXPAND_BUTTON, - LOCK_BUTTON, - }; - - enum class Controls_snapshots_select - { - NONE, - LOCK_BUTTON, - CREATE_BUTTON, - GENERATION_DISCARD_BUTTON, - }; - - enum class Controls_snapshots_hover - { - NONE, - LOCK_BUTTON, - LEAVE_BUTTON, - CREATE_BUTTON, - GENERATION_LEAVE_BUTTON, - GENERATION_DISCARD_BUTTON, - }; - - enum class Dimensions_select - { - NONE, - EXPAND_CLIENT_FS_EXPAND_BUTTON, - EXPAND_SNAP_BUF_EXPAND_BUTTON, - LOCK_BUTTON, - }; - - enum class Dimensions_hover - { - NONE, - LEAVE_BUTTON, - EXPAND_CLIENT_FS_BUTTON, - EXPAND_SNAPSHOT_BUF_BUTTON, - LOCK_BUTTON, - }; - - enum class Expand_client_fs_select - { - NONE, - CONTINGENT_INPUT, - START_BUTTON, - LOCK_BUTTON, - }; - - enum class Expand_client_fs_hover - { - NONE, - LEAVE_BUTTON, - CONTINGENT_INPUT, - START_BUTTON, - LOCK_BUTTON, - }; - - enum class Expand_snapshot_buf_select - { - NONE, - CONTINGENT_INPUT, - START_BUTTON, - LOCK_BUTTON, - }; - - enum class Expand_snapshot_buf_hover - { - NONE, - LEAVE_BUTTON, - CONTINGENT_INPUT, - START_BUTTON, - LOCK_BUTTON, - }; - - enum class Controls_security_block_encryption_key_select - { - NONE, - REPLACE_BUTTON, - LOCK_BUTTON, - }; - - enum class Controls_security_block_encryption_key_hover - { - NONE, - LEAVE_BUTTON, - REPLACE_BUTTON, - LOCK_BUTTON, - }; - - enum class Controls_security_master_key_select - { - NONE, - LOCK_BUTTON, - }; - - enum class Controls_security_master_key_hover - { - NONE, - LEAVE_BUTTON, - LOCK_BUTTON, - }; - - enum class Controls_security_user_passphrase_select - { - NONE, - LOCK_BUTTON, - }; - - enum class Controls_security_user_passphrase_hover - { - NONE, - LEAVE_BUTTON, - LOCK_BUTTON, - }; - - enum class Controls_security_select - { - NONE, - BLOCK_ENCRYPTION_KEY_EXPAND_BUTTON, - MASTER_KEY_EXPAND_BUTTON, - USER_PASSPHRASE_EXPAND_BUTTON, - LOCK_BUTTON, - }; - - enum class Controls_security_hover - { - NONE, - SECURITY_EXPAND_BUTTON, - BLOCK_ENCRYPTION_KEY_EXPAND_BUTTON, - MASTER_KEY_EXPAND_BUTTON, - USER_PASSPHRASE_EXPAND_BUTTON, - LOCK_BUTTON, - }; - - enum class Resizing_type - { - NONE, - EXPAND_CLIENT_FS, - EXPAND_SNAPSHOT_BUF, - }; - enum class Resizing_state { INACTIVE, @@ -332,44 +83,19 @@ class File_vault::Main IN_PROGRESS_AT_DEVICE, }; - enum class Create_snapshot_state - { - INACTIVE, - ISSUE_REQUEST_AT_DEVICE, - }; - - enum class Discard_snapshot_state - { - INACTIVE, - ISSUE_REQUEST_AT_DEVICE, - }; - - enum User_interface - { - MENU_VIEW, - CONFIG_AND_REPORT, - }; - using Report_service = Sandbox::Local_service; - using Gui_service = Sandbox::Local_service; - using Rom_service = Sandbox::Local_service; using Xml_report_handler = Report::Session_component::Xml_handler
; using State_string = String; - using Snapshot_registry = Registry>; - using Snapshot_pointer = Const_pointer; Env &_env; State _state { State::INVALID }; Heap _heap { _env.ram(), _env.rm() }; Timer::Connection _timer { _env }; Attached_rom_dataspace _config_rom { _env, "config" }; - User_interface _user_interface { _user_interface_from_config(_config_rom.xml()) }; bool _verbose_state { _config_rom.xml().attribute_value("verbose_state", false) }; - bool _verbose_ui_config { _config_rom.xml().attribute_value("verbose_ui_config", false) }; bool _jent_avail { _config_rom.xml().attribute_value("jitterentropy_available", true) }; Root_directory _vfs { _env, _heap, _config_rom.xml().sub_node("vfs") }; Registry _children { }; - Child_state _menu_view { _children, "menu_view", Ram_quota { 4 * 1024 * 1024 }, Cap_quota { 200 } }; Child_state _mke2fs { _children, "mke2fs", Ram_quota { 32 * 1024 * 1024 }, Cap_quota { 500 } }; Child_state _resize2fs { _children, "resize2fs", Ram_quota { 32 * 1024 * 1024 }, Cap_quota { 500 } }; Child_state _tresor_vfs { _children, "tresor_vfs", "vfs", Ram_quota { 32 * 1024 * 1024 }, Cap_quota { 200 } }; @@ -383,131 +109,30 @@ class File_vault::Main Child_state _client_fs_fs_query { _children, "client_fs_fs_query", "fs_query", Ram_quota { 2 * 1024 * 1024 }, Cap_quota { 100 } }; Child_state _tresor_init_trust_anchor { _children, "tresor_init_trust_anchor", Ram_quota { 4 * 1024 * 1024 }, Cap_quota { 300 } }; Child_state _tresor_init { _children, "tresor_init", Ram_quota { 4 * 1024 * 1024 }, Cap_quota { 200 } }; - Child_state _snapshots_fs_query { _children, "snapshots_fs_query", "fs_query", Ram_quota { 2 * 1024 * 1024 }, Cap_quota { 100 } }; Child_state _resizing_fs_tool { _children, "resizing_fs_tool", "fs_tool", Ram_quota { 5 * 1024 * 1024 }, Cap_quota { 200 } }; Child_state _resizing_fs_query { _children, "resizing_fs_query", "fs_query", Ram_quota { 1 * 1024 * 1024 }, Cap_quota { 100 } }; Child_state _rekeying_fs_tool { _children, "rekeying_fs_tool", "fs_tool", Ram_quota { 5 * 1024 * 1024 }, Cap_quota { 200 } }; Child_state _rekeying_fs_query { _children, "rekeying_fs_query", "fs_query", Ram_quota { 1 * 1024 * 1024 }, Cap_quota { 100 } }; Child_state _lock_fs_tool { _children, "lock_fs_tool", "fs_tool", Ram_quota { 6 * 1024 * 1024 }, Cap_quota { 200 } }; Child_state _lock_fs_query { _children, "lock_fs_query", "fs_query", Ram_quota { 2 * 1024 * 1024 }, Cap_quota { 100 } }; - Child_state _create_snap_fs_tool { _children, "create_snap_fs_tool", "fs_tool", Ram_quota { 5 * 1024 * 1024 }, Cap_quota { 200 } }; - Child_state _discard_snap_fs_tool { _children, "discard_snap_fs_tool", "fs_tool", Ram_quota { 5 * 1024 * 1024 }, Cap_quota { 200 } }; Xml_report_handler _fs_query_listing_handler { *this, &Main::_handle_fs_query_listing }; Xml_report_handler _image_fs_query_listing_handler { *this, &Main::_handle_image_fs_query_listing }; Xml_report_handler _client_fs_fs_query_listing_handler { *this, &Main::_handle_client_fs_fs_query_listing }; - Xml_report_handler _snapshots_fs_query_listing_handler { *this, &Main::_handle_snapshots_fs_query_listing }; Xml_report_handler _resizing_fs_query_listing_handler { *this, &Main::_handle_resizing_fs_query_listing }; Xml_report_handler _rekeying_fs_query_listing_handler { *this, &Main::_handle_rekeying_fs_query_listing }; Xml_report_handler _lock_fs_query_listing_handler { *this, &Main::_handle_lock_fs_query_listing }; Sandbox _sandbox { _env, *this }; - Gui_service _gui_service { _sandbox, *this }; - Rom_service _rom_service { _sandbox, *this }; Report_service _report_service { _sandbox, *this }; - Xml_report_handler _hover_handler { *this, &Main::_handle_hover }; - Constructible> _watch_handler { }; - Constructible _clipboard_reporter { }; - Constructible _clipboard_rom { }; - bool _initial_config { true }; - Signal_handler
_config_handler { _env.ep(), *this, &Main::_handle_config }; Signal_handler
_state_handler { _env.ep(), *this, &Main::_handle_state }; - Dynamic_rom_session _dialog { _env.ep(), _env.ram(), _env.rm(), *this }; - Input_passphrase _setup_obtain_params_passphrase { }; - Input_number_of_bytes _client_fs_size_input { }; - Input_number_of_bytes _journaling_buf_size_input { }; - Setup_obtain_params_hover _setup_obtain_params_hover { Setup_obtain_params_hover::NONE }; - Setup_obtain_params_select _setup_obtain_params_select { Setup_obtain_params_select::PASSPHRASE_INPUT }; - Controls_root_hover _controls_root_hover { Controls_root_hover::NONE }; - Controls_root_select _controls_root_select { Controls_root_select::NONE }; - Controls_snapshots_hover _controls_snapshots_hover { Controls_snapshots_hover::NONE }; - Controls_snapshots_select _controls_snapshots_select { Controls_snapshots_select::NONE }; - Dimensions_hover _dimensions_hover { Dimensions_hover::NONE }; - Dimensions_select _dimensions_select { Dimensions_select::NONE }; - Expand_client_fs_hover _expand_client_fs_hover { Expand_client_fs_hover::NONE }; - Expand_client_fs_select _expand_client_fs_select { Expand_client_fs_select::NONE }; - Expand_snapshot_buf_hover _expand_snapshot_buf_hover { Expand_snapshot_buf_hover::NONE }; - Expand_snapshot_buf_select _expand_snapshot_buf_select { Expand_snapshot_buf_select::NONE }; - Controls_security_hover _controls_security_hover { Controls_security_hover::NONE }; - Controls_security_select _controls_security_select { Controls_security_select::NONE }; - - Controls_security_master_key_hover _controls_security_master_key_hover { Controls_security_master_key_hover::NONE }; - Controls_security_master_key_select _controls_security_master_key_select { Controls_security_master_key_select::NONE }; - Controls_security_block_encryption_key_hover _controls_security_block_encryption_key_hover { Controls_security_block_encryption_key_hover::NONE }; - Controls_security_block_encryption_key_select _controls_security_block_encryption_key_select { Controls_security_block_encryption_key_select::NONE }; - Controls_security_user_passphrase_hover _controls_security_user_passphrase_hover { Controls_security_user_passphrase_hover::NONE }; - Controls_security_user_passphrase_select _controls_security_user_passphrase_select { Controls_security_user_passphrase_select::NONE }; - Resizing_state _resizing_state { Resizing_state::INACTIVE }; - Resizing_type _resizing_type { Resizing_type::NONE }; - Input_number_of_bytes _expand_client_fs_contingent { }; - Input_number_of_bytes _expand_snapshot_buf_contingent { }; Rekeying_state _rekeying_state { Rekeying_state::INACTIVE }; - Create_snapshot_state _create_snap_state { Create_snapshot_state::INACTIVE }; - Discard_snapshot_state _discard_snap_state { Discard_snapshot_state::INACTIVE }; - Generation _discard_snap_gen { INVALID_GENERATION }; - Snapshot_registry _snapshots { }; - Snapshot_pointer _snapshots_hover { }; - Snapshot_pointer _snapshots_select { }; - bool _snapshots_expanded { false }; - bool _dimensions_expanded { false }; Timer::One_shot_timeout
_unlock_retry_delay { _timer, *this, &Main::_handle_unlock_retry_delay }; - size_t _tresor_image_size { 0 }; File_path _tresor_image_file_name { "tresor.img" }; - size_t _client_fs_size { 0 }; - bool _nr_of_clients { 0 }; - Constructible _ui_config_rom { }; + Attached_rom_dataspace _ui_config_rom { _env, "ui_config" }; Signal_handler
_ui_config_handler { _env.ep(), *this, &Main::_handle_ui_config }; Constructible _ui_config { }; - Constructible _ui_report { }; - - static User_interface - _user_interface_from_config(Xml_node const &config) - { - using Ui_string = String<32>; - - Ui_string const ui_str { - config.attribute_value("user_interface", Ui_string { }) }; - - if (ui_str == "config_and_report") - return CONFIG_AND_REPORT; - - return MENU_VIEW; - } - - void _gen_menu_view_start_node_if_required(Xml_generator &xml) const - { - if (_user_interface == MENU_VIEW) - gen_menu_view_start_node(xml, _menu_view); - } - - size_t _ui_client_fs_size() const - { - switch (_user_interface) { - case MENU_VIEW: return _client_fs_size_input.value(); - case CONFIG_AND_REPORT: return _ui_config->client_fs_size; - } - class Exception_1 { }; - throw Exception_1 { }; - } - - size_t _ui_journaling_buf_size() const - { - switch (_user_interface) { - case MENU_VIEW: return _journaling_buf_size_input.value(); - case CONFIG_AND_REPORT: return _ui_config->journaling_buf_size; - } - class Exception_1 { }; - throw Exception_1 { }; - } - - Passphrase _ui_setup_obtain_params_passphrase() const - { - switch (_user_interface) { - case MENU_VIEW: return _setup_obtain_params_passphrase.plaintext().string(); - case CONFIG_AND_REPORT: return _ui_config->passphrase; - } - class Exception_1 { }; - throw Exception_1 { }; - } + Ui_report _ui_report { }; + Expanding_reporter _ui_report_reporter { _env, "ui_report", "ui_report" }; static bool _has_name(Xml_node const &node, Node_name const &name) @@ -517,24 +142,19 @@ class File_vault::Main size_t _min_journaling_buf_size() const { - size_t result { _ui_client_fs_size() >> 8 }; + size_t result { _ui_config->client_fs_size >> 8 }; if (result < MIN_CLIENT_FS_SIZE) { result = MIN_CLIENT_FS_SIZE; } return result; } - bool _ui_setup_obtain_params_passphrase_suitable() const - { - return _ui_setup_obtain_params_passphrase().length() >= PASSPHRASE_MIN_NR_OF_CHARS + 1; - } - bool _ui_setup_obtain_params_suitable() const { return - _ui_client_fs_size() >= MIN_CLIENT_FS_SIZE && - _ui_journaling_buf_size() >= _min_journaling_buf_size() && - _ui_setup_obtain_params_passphrase_suitable(); + _ui_config->client_fs_size >= MIN_CLIENT_FS_SIZE && + _ui_config->journaling_buf_size >= _min_journaling_buf_size() && + _ui_config->passphrase_long_enough(); } template @@ -583,18 +203,12 @@ class File_vault::Main void _handle_client_fs_fs_query_listing(Xml_node const &node); - void _handle_snapshots_fs_query_listing(Xml_node const &node); - void _handle_resizing_fs_query_listing(Xml_node const &node); void _handle_rekeying_fs_query_listing(Xml_node const &node); void _handle_lock_fs_query_listing(Xml_node const &node); - void _handle_hover(Xml_node const &node); - - void _handle_config(); - void _handle_ui_config(); void _handle_ui_config_and_report(); @@ -605,45 +219,25 @@ class File_vault::Main void _adapt_to_version(Version version); - Reported_state _reported_state() const; + Ui_report::State _reported_state() const; - static char const *_reported_state_to_string(Reported_state state); + void _generate_ui_report() + { + _ui_report_reporter.generate([&] (Xml_generator &xml) { _ui_report.generate(xml); }); + } void _set_state(State state) { - Reported_state old_reported_state { _reported_state() }; + Ui_report::State old_reported_state { _reported_state() }; _state = state; - Reported_state new_reported_state { _reported_state() }; - - if (_verbose_state) - log("state: ", _state_to_string(_state), " ", old_reported_state != new_reported_state, " ", _user_interface == CONFIG_AND_REPORT); - - if (old_reported_state != new_reported_state && - _user_interface == CONFIG_AND_REPORT) { - - _ui_report->generate([&] (Xml_generator &xml) { - xml.attribute("version", _ui_config->version); - xml.attribute("state", _reported_state_to_string(new_reported_state)); - }); - } + _ui_report.state = _reported_state(); + if (old_reported_state != _ui_report.state) + _generate_ui_report(); } - static Number_of_blocks _tresor_tree_num_leaves(uint64_t payload_size); + bool _rekey_operation_pending() const; - - static uint64_t _tree_nr_of_blocks(size_t nr_of_lvls, - size_t nr_of_children, - uint64_t nr_of_leafs); - - uint64_t _tresor_size() const; - - static uint64_t _tresor_nr_of_blocks(size_t nr_of_superblocks, - size_t nr_of_vbd_lvls, - size_t nr_of_vbd_children, - uint64_t nr_of_vbd_leafs, - size_t nr_of_ft_lvls, - size_t nr_of_ft_children, - uint64_t nr_of_ft_leafs); + bool _extend_operation_pending() const; template static bool listing_file_starts_with(Xml_node const &fs_query_listing, @@ -683,19 +277,6 @@ class File_vault::Main void handle_sandbox_state() override; - /**************************************** - ** Gui::Input_event_handler interface ** - ****************************************/ - - void handle_input_event(Input::Event const &event) override; - - - /*************************************** - ** Dynamic_rom_session::Xml_producer ** - ***************************************/ - - void produce_xml(Xml_generator &xml) override; - public: Main(Env &env); @@ -708,17 +289,10 @@ using namespace File_vault; ** File_vault::Main ** **********************/ -void Main::_handle_config() -{ - _config_rom.update(); - _initial_config = false; -} - - void Main::_handle_ui_config() { - _ui_config_rom->update(); - _ui_config.construct(_ui_config_rom->xml(), _verbose_ui_config); + _ui_config_rom.update(); + _ui_config.construct(_ui_config_rom.xml()); _handle_ui_config_and_report(); } @@ -765,15 +339,15 @@ Main::State Main::_state_and_version_from_string(State_string const &str, if (str == "setup_start_tresor_vfs") { return State::SETUP_START_TRESOR_VFS; } if (str == "setup_format_tresor") { return State::SETUP_FORMAT_TRESOR; } if (str == "setup_determine_client_fs_size") { return State::SETUP_DETERMINE_CLIENT_FS_SIZE; } - if (str == "controls_root") { return State::CONTROLS_ROOT; } - if (str == "controls_snapshots") { return State::CONTROLS_SNAPSHOTS; } - if (str == "controls_dimensions") { return State::CONTROLS_DIMENSIONS; } - if (str == "controls_expand_client_fs") { return State::CONTROLS_EXPAND_CLIENT_FS; } - if (str == "controls_expand_snapshot_buf") { return State::CONTROLS_EXPAND_SNAPSHOT_BUF; } - if (str == "controls_security") { return State::CONTROLS_SECURITY; } - if (str == "controls_security_block_encryption_key") { return State::CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY; } - if (str == "controls_security_master_key") { return State::CONTROLS_SECURITY_MASTER_KEY; } - if (str == "controls_security_user_passphrase") { return State::CONTROLS_SECURITY_USER_PASSPHRASE; } + if (str == "controls") { return State::CONTROLS; } + if (str == "controls_root") { return State::CONTROLS; } + if (str == "controls_dimensions") { return State::CONTROLS; } + if (str == "controls_expand_client_fs") { return State::CONTROLS; } + if (str == "controls_expand_snapshot_buf") { return State::CONTROLS; } + if (str == "controls_security") { return State::CONTROLS; } + if (str == "controls_security_block_encryption_key") { return State::CONTROLS; } + if (str == "controls_security_master_key") { return State::CONTROLS; } + if (str == "controls_security_user_passphrase") { return State::CONTROLS; } if (str == "unlock_obtain_parameters") { return State::UNLOCK_OBTAIN_PARAMETERS; } if (str == "unlock_run_tresor_init_trust_anchor") { return State::UNLOCK_RUN_TRESOR_INIT_TRUST_ANCHOR; } if (str == "unlock_start_tresor_vfs") { return State::UNLOCK_START_TRESOR_VFS; } @@ -800,15 +374,7 @@ Main::State_string Main::_state_to_string(State state) case State::SETUP_START_TRESOR_VFS: return "setup_start_tresor_vfs"; case State::SETUP_FORMAT_TRESOR: return "setup_format_tresor"; case State::SETUP_DETERMINE_CLIENT_FS_SIZE: return "setup_determine_client_fs_size"; - case State::CONTROLS_ROOT: return "controls_root"; - case State::CONTROLS_SNAPSHOTS: return "controls_snapshots"; - case State::CONTROLS_DIMENSIONS: return "controls_dimensions"; - case State::CONTROLS_EXPAND_CLIENT_FS: return "controls_expand_client_fs"; - case State::CONTROLS_EXPAND_SNAPSHOT_BUF: return "controls_expand_snapshot_buf"; - case State::CONTROLS_SECURITY: return "controls_security"; - case State::CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY: return "controls_security_block_encryption_key"; - case State::CONTROLS_SECURITY_MASTER_KEY: return "controls_security_master_key"; - case State::CONTROLS_SECURITY_USER_PASSPHRASE: return "controls_security_user_passphrase"; + case State::CONTROLS: return "controls"; case State::UNLOCK_OBTAIN_PARAMETERS: return "unlock_obtain_parameters"; case State::UNLOCK_RUN_TRESOR_INIT_TRUST_ANCHOR: return "unlock_run_tresor_init_trust_anchor"; case State::UNLOCK_START_TRESOR_VFS: return "unlock_start_tresor_vfs"; @@ -821,48 +387,24 @@ Main::State_string Main::_state_to_string(State state) } -char const *Main::_reported_state_to_string(Reported_state state) -{ - switch (state) { - case Reported_state::INVALID: return "invalid"; - case Reported_state::UNINITIALIZED: return "uninitialized"; - case Reported_state::INITIALIZING: return "initializing"; - case Reported_state::LOCKED: return "locked"; - case Reported_state::UNLOCKING: return "unlocking"; - case Reported_state::UNLOCKED: return "unlocked"; - case Reported_state::LOCKING: return "locking"; - } - class Invalid_state { }; - throw Invalid_state { }; -} - - -Main::Reported_state Main::_reported_state() const +Ui_report::State Main::_reported_state() const { switch (_state) { - case State::INVALID: return Reported_state::INVALID; - case State::SETUP_OBTAIN_PARAMETERS: return Reported_state::UNINITIALIZED; - case State::SETUP_CREATE_TRESOR_IMAGE_FILE: return Reported_state::INITIALIZING; - case State::SETUP_RUN_TRESOR_INIT_TRUST_ANCHOR: return Reported_state::INITIALIZING; - case State::SETUP_RUN_TRESOR_INIT: return Reported_state::INITIALIZING; - case State::SETUP_START_TRESOR_VFS: return Reported_state::INITIALIZING; - case State::SETUP_FORMAT_TRESOR: return Reported_state::INITIALIZING; - case State::SETUP_DETERMINE_CLIENT_FS_SIZE: return Reported_state::INITIALIZING; - case State::CONTROLS_ROOT: return Reported_state::UNLOCKED; - case State::CONTROLS_SNAPSHOTS: return Reported_state::UNLOCKED; - case State::CONTROLS_DIMENSIONS: return Reported_state::UNLOCKED; - case State::CONTROLS_EXPAND_CLIENT_FS: return Reported_state::UNLOCKED; - case State::CONTROLS_EXPAND_SNAPSHOT_BUF: return Reported_state::UNLOCKED; - case State::CONTROLS_SECURITY: return Reported_state::UNLOCKED; - case State::CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY: return Reported_state::UNLOCKED; - case State::CONTROLS_SECURITY_MASTER_KEY: return Reported_state::UNLOCKED; - case State::CONTROLS_SECURITY_USER_PASSPHRASE: return Reported_state::UNLOCKED; - case State::UNLOCK_OBTAIN_PARAMETERS: return Reported_state::LOCKED; - case State::UNLOCK_RUN_TRESOR_INIT_TRUST_ANCHOR: return Reported_state::UNLOCKING; - case State::UNLOCK_START_TRESOR_VFS: return Reported_state::UNLOCKING; - case State::UNLOCK_DETERMINE_CLIENT_FS_SIZE: return Reported_state::UNLOCKING; - case State::LOCK_ISSUE_DEINIT_REQUEST_AT_TRESOR: return Reported_state::LOCKING; - case State::LOCK_WAIT_TILL_DEINIT_REQUEST_IS_DONE: return Reported_state::LOCKING; + case State::INVALID: return Ui_report::INVALID; + case State::SETUP_OBTAIN_PARAMETERS: return Ui_report::UNINITIALIZED; + case State::SETUP_CREATE_TRESOR_IMAGE_FILE: return Ui_report::INITIALIZING; + case State::SETUP_RUN_TRESOR_INIT_TRUST_ANCHOR: return Ui_report::INITIALIZING; + case State::SETUP_RUN_TRESOR_INIT: return Ui_report::INITIALIZING; + case State::SETUP_START_TRESOR_VFS: return Ui_report::INITIALIZING; + case State::SETUP_FORMAT_TRESOR: return Ui_report::INITIALIZING; + case State::SETUP_DETERMINE_CLIENT_FS_SIZE: return Ui_report::INITIALIZING; + case State::CONTROLS: return Ui_report::UNLOCKED; + case State::UNLOCK_OBTAIN_PARAMETERS: return Ui_report::LOCKED; + case State::UNLOCK_RUN_TRESOR_INIT_TRUST_ANCHOR: return Ui_report::UNLOCKING; + case State::UNLOCK_START_TRESOR_VFS: return Ui_report::UNLOCKING; + case State::UNLOCK_DETERMINE_CLIENT_FS_SIZE: return Ui_report::UNLOCKING; + case State::LOCK_ISSUE_DEINIT_REQUEST_AT_TRESOR: return Ui_report::LOCKING; + case State::LOCK_WAIT_TILL_DEINIT_REQUEST_IS_DONE: return Ui_report::LOCKING; } class Invalid_state { }; throw Invalid_state { }; @@ -929,15 +471,7 @@ void Main::_write_to_state_file(State state) void Main::_handle_resizing_fs_query_listing(Xml_node const &node) { switch (_state) { - case State::CONTROLS_ROOT: - case State::CONTROLS_SNAPSHOTS: - case State::CONTROLS_DIMENSIONS: - case State::CONTROLS_EXPAND_CLIENT_FS: - case State::CONTROLS_EXPAND_SNAPSHOT_BUF: - case State::CONTROLS_SECURITY: - case State::CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY: - case State::CONTROLS_SECURITY_MASTER_KEY: - case State::CONTROLS_SECURITY_USER_PASSPHRASE: + case State::CONTROLS: switch (_resizing_state) { case Resizing_state::WAIT_TILL_DEVICE_IS_READY: @@ -947,7 +481,6 @@ void Main::_handle_resizing_fs_query_listing(Xml_node const &node) _resizing_state = Resizing_state::ISSUE_REQUEST_AT_DEVICE; Signal_transmitter(_state_handler).submit(); - } else error("failed to extend: tresor not ready"); @@ -956,42 +489,16 @@ void Main::_handle_resizing_fs_query_listing(Xml_node const &node) case Resizing_state::IN_PROGRESS_AT_DEVICE: if (listing_file_starts_with(node, "extend", String<10>("succeeded"))) { - - switch (_resizing_type) { - case Resizing_type::EXPAND_CLIENT_FS: - - _expand_client_fs_contingent = Input_number_of_bytes { }; - _expand_client_fs_select = Expand_client_fs_select::CONTINGENT_INPUT; - break; - - case Resizing_type::EXPAND_SNAPSHOT_BUF: - - _expand_snapshot_buf_contingent = Input_number_of_bytes { }; - _expand_snapshot_buf_select = Expand_snapshot_buf_select::CONTINGENT_INPUT; - break; - - default: - - class Unexpected_resizing_type { }; - throw Unexpected_resizing_type { }; - break; - } _resizing_state = Resizing_state::DETERMINE_CLIENT_FS_SIZE; Signal_transmitter(_state_handler).submit(); - } else error("failed to extend: operation failed at tresor"); - break; - default: - - break; + default: break; } - default: - - break; + default: break; } } @@ -1002,36 +509,22 @@ void Main::_handle_lock_fs_query_listing(Xml_node const &node) case State::LOCK_WAIT_TILL_DEINIT_REQUEST_IS_DONE: if (listing_file_starts_with(node, "deinitialize", String<10>("succeeded"))) { - _set_state(State::UNLOCK_OBTAIN_PARAMETERS); - _setup_obtain_params_passphrase = Input_passphrase { }; - _setup_obtain_params_select = Setup_obtain_params_select::PASSPHRASE_INPUT; Signal_transmitter(_state_handler).submit(); - } else error("failed to deinitialize: operation failed at tresor"); - break; - default: - - break; + default: break; } } void Main::_handle_rekeying_fs_query_listing(Xml_node const &node) { + bool generate_ui_report = false; switch (_state) { - case State::CONTROLS_ROOT: - case State::CONTROLS_SNAPSHOTS: - case State::CONTROLS_DIMENSIONS: - case State::CONTROLS_EXPAND_CLIENT_FS: - case State::CONTROLS_EXPAND_SNAPSHOT_BUF: - case State::CONTROLS_SECURITY: - case State::CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY: - case State::CONTROLS_SECURITY_MASTER_KEY: - case State::CONTROLS_SECURITY_USER_PASSPHRASE: + case State::CONTROLS: switch (_rekeying_state) { case Rekeying_state::WAIT_TILL_DEVICE_IS_READY: @@ -1051,6 +544,8 @@ void Main::_handle_rekeying_fs_query_listing(Xml_node const &node) if (listing_file_starts_with(node, "rekey", String<10>("succeeded"))) { + _ui_report.rekey->finished = true; + generate_ui_report = true; _rekeying_state = Rekeying_state::INACTIVE; Signal_transmitter(_state_handler).submit(); @@ -1069,96 +564,8 @@ void Main::_handle_rekeying_fs_query_listing(Xml_node const &node) break; } -} - - -void Main::_handle_snapshots_fs_query_listing(Xml_node const &node) -{ - switch (_state) { - case State::CONTROLS_ROOT: - case State::CONTROLS_SNAPSHOTS: - case State::CONTROLS_DIMENSIONS: - case State::CONTROLS_EXPAND_CLIENT_FS: - case State::CONTROLS_EXPAND_SNAPSHOT_BUF: - case State::CONTROLS_SECURITY: - case State::CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY: - case State::CONTROLS_SECURITY_MASTER_KEY: - case State::CONTROLS_SECURITY_USER_PASSPHRASE: - { - bool update_dialog { false }; - node.with_optional_sub_node("dir", [&] (Xml_node const &node_0) { - - _snapshots.for_each([&] (Snapshot const &snap) - { - bool snap_still_exists { false }; - node_0.for_each_sub_node("dir", [&] (Xml_node const &node_1) { - - if (snap_still_exists) { - return; - } - Generation const generation { - node_1.attribute_value( - "name", Generation { INVALID_GENERATION }) }; - - if (generation == INVALID_GENERATION) { - warning("skipping snapshot file with invalid generation number"); - return; - } - if (generation == snap.generation()) { - snap_still_exists = true; - return; - } - }); - if (!snap_still_exists) { - - if (_snapshots_select.valid() && - &_snapshots_select.object() == &snap) { - - _snapshots_select = Snapshot_pointer { }; - } - if (_snapshots_hover.valid() && - &_snapshots_hover.object() == &snap) { - - _snapshots_hover = Snapshot_pointer { }; - } - destroy(&_heap, &const_cast(snap)); - update_dialog = true; - } - }); - - node_0.for_each_sub_node("dir", [&] (Xml_node const &node_1) { - - Generation const generation { - node_1.attribute_value( - "name", Generation { INVALID_GENERATION }) }; - - if (generation == INVALID_GENERATION) { - warning("skipping snapshot file with invalid generation number"); - return; - } - bool snap_already_exists { false }; - _snapshots.for_each([&] (Snapshot const &snap) - { - if (generation == snap.generation()) { - snap_already_exists = true; - } - }); - if (!snap_already_exists) { - new (_heap) Registered(_snapshots, generation); - update_dialog = true; - } - }); - }); - if (update_dialog) { - _dialog.trigger_update(); - } - - break; - } - default: - - break; - } + if (generate_ui_report) + _generate_ui_report(); } @@ -1200,6 +607,7 @@ void Main::_handle_fs_query_listing(Xml_node const &node) void Main::_handle_client_fs_fs_query_listing(Xml_node const &node) { + bool generate_ui_report = false; switch (_state) { case State::SETUP_DETERMINE_CLIENT_FS_SIZE: case State::UNLOCK_DETERMINE_CLIENT_FS_SIZE: @@ -1209,23 +617,16 @@ void Main::_handle_client_fs_fs_query_listing(Xml_node const &node) if (_has_name(node_1, "data")) { - _client_fs_size = node_1.attribute_value("size", (size_t)0); - _set_state(State::CONTROLS_ROOT); + _ui_report.capacity = node_1.attribute_value("size", 0UL); + generate_ui_report = true; + _set_state(State::CONTROLS); Signal_transmitter(_state_handler).submit(); } }); }); break; - case State::CONTROLS_ROOT: - case State::CONTROLS_SNAPSHOTS: - case State::CONTROLS_DIMENSIONS: - case State::CONTROLS_EXPAND_CLIENT_FS: - case State::CONTROLS_EXPAND_SNAPSHOT_BUF: - case State::CONTROLS_SECURITY: - case State::CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY: - case State::CONTROLS_SECURITY_MASTER_KEY: - case State::CONTROLS_SECURITY_USER_PASSPHRASE: + case State::CONTROLS: switch (_resizing_state) { case Resizing_state::DETERMINE_CLIENT_FS_SIZE: @@ -1238,16 +639,18 @@ void Main::_handle_client_fs_fs_query_listing(Xml_node const &node) size_t const size { node_1.attribute_value("size", (size_t)0) }; - if (_client_fs_size != size) { + if (_ui_report.capacity != size) { - _client_fs_size = size; + _ui_report.capacity = size; + generate_ui_report = true; _resizing_state = Resizing_state::RUN_RESIZE2FS; Signal_transmitter(_state_handler).submit(); } else { - _resizing_type = Resizing_type::NONE; _resizing_state = Resizing_state::INACTIVE; + _ui_report.extend->finished = true; + generate_ui_report = true; Signal_transmitter(_state_handler).submit(); } } @@ -1264,23 +667,17 @@ void Main::_handle_client_fs_fs_query_listing(Xml_node const &node) break; } + if (generate_ui_report) + _generate_ui_report(); } void Main::_handle_image_fs_query_listing(Xml_node const &node) { - bool update_dialog { false }; + bool generate_ui_report { false }; switch (_state) { - case State::CONTROLS_ROOT: - case State::CONTROLS_SNAPSHOTS: - case State::CONTROLS_DIMENSIONS: - case State::CONTROLS_EXPAND_CLIENT_FS: - case State::CONTROLS_EXPAND_SNAPSHOT_BUF: - case State::CONTROLS_SECURITY: - case State::CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY: - case State::CONTROLS_SECURITY_MASTER_KEY: - case State::CONTROLS_SECURITY_USER_PASSPHRASE: + case State::CONTROLS: { size_t size { 0 }; node.with_optional_sub_node("dir", [&] (Xml_node const &node_0) { @@ -1290,10 +687,9 @@ void Main::_handle_image_fs_query_listing(Xml_node const &node) } }); }); - if (_tresor_image_size != size) { - - _tresor_image_size = size; - update_dialog = true; + if (_ui_report.image_size != size) { + _ui_report.image_size = size; + generate_ui_report = true; } break; } @@ -1301,26 +697,46 @@ void Main::_handle_image_fs_query_listing(Xml_node const &node) break; } - if (update_dialog) { - _dialog.trigger_update(); - } + if (generate_ui_report) + _generate_ui_report(); } void Main::_handle_state() { _update_sandbox_config(); + _handle_ui_config_and_report(); +} - switch (_user_interface) { - case MENU_VIEW: _dialog.trigger_update(); break; - case CONFIG_AND_REPORT: _handle_ui_config_and_report(); break; - } + +bool Main::_rekey_operation_pending() const +{ + if (!_ui_config->rekey.constructed()) + return false; + + if (!_ui_report.rekey.constructed()) + return true; + + return _ui_report.rekey->id.value != _ui_config->rekey->id.value; +} + + +bool Main::_extend_operation_pending() const +{ + if (!_ui_config->extend.constructed()) + return false; + + if (!_ui_report.extend.constructed()) + return true; + + return _ui_report.extend->id.value != _ui_config->extend->id.value; } void Main::_handle_ui_config_and_report() { bool update_sandbox_config { false }; + bool generate_ui_report { false }; switch (_state) { case State::SETUP_OBTAIN_PARAMETERS: @@ -1334,54 +750,50 @@ void Main::_handle_ui_config_and_report() case State::UNLOCK_OBTAIN_PARAMETERS: - if (_ui_setup_obtain_params_passphrase_suitable()) { + if (_ui_config->passphrase_long_enough()) { _set_state(State::UNLOCK_RUN_TRESOR_INIT_TRUST_ANCHOR); update_sandbox_config = true; } break; - case State::CONTROLS_ROOT: - case State::CONTROLS_SNAPSHOTS: - case State::CONTROLS_DIMENSIONS: - case State::CONTROLS_EXPAND_CLIENT_FS: - case State::CONTROLS_EXPAND_SNAPSHOT_BUF: - case State::CONTROLS_SECURITY: - case State::CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY: - case State::CONTROLS_SECURITY_MASTER_KEY: - case State::CONTROLS_SECURITY_USER_PASSPHRASE: + case State::CONTROLS: - if (!_ui_setup_obtain_params_passphrase_suitable()) { + if (!_ui_config->passphrase_long_enough()) { _set_state(State::LOCK_ISSUE_DEINIT_REQUEST_AT_TRESOR); update_sandbox_config = true; + break; + } + if (_rekeying_state == Rekeying_state::INACTIVE && _rekey_operation_pending()) { + + _ui_report.rekey.construct(_ui_config->rekey->id, false); + _rekeying_state = Rekeying_state::WAIT_TILL_DEVICE_IS_READY; + update_sandbox_config = true; + generate_ui_report = true; + } + if (_resizing_state == Resizing_state::INACTIVE && _extend_operation_pending()) { + _ui_report.extend.construct(_ui_config->extend->id, false); + _resizing_state = Resizing_state::ADAPT_TRESOR_IMAGE_SIZE; + update_sandbox_config = true; } break; default: break; } - if (update_sandbox_config) { + if (generate_ui_report) + _generate_ui_report(); + if (update_sandbox_config) _update_sandbox_config(); - } } -Main::Main(Env &env) -: - Xml_producer { "dialog" }, - _env { env } +Main::Main(Env &env) : _env(env) { - _config_rom.sigh(_config_handler); - _handle_config(); + _ui_config_rom.sigh(_ui_config_handler); _update_sandbox_config(); - - if (_user_interface == CONFIG_AND_REPORT) { - _ui_config_rom.construct(_env, "ui_config"); - _ui_config_rom->sigh(_ui_config_handler); - _ui_report.construct(_env, "ui_report", "ui_report"); - _handle_ui_config(); - _set_state(State::INVALID); - } + _handle_ui_config(); + _set_state(State::INVALID); } @@ -1433,9 +845,7 @@ bool File_vault::Main::_child_succeeded(Xml_node const &sandbox_state, void File_vault::Main::_handle_unlock_retry_delay(Duration) { _set_state(State::UNLOCK_OBTAIN_PARAMETERS); - _ui_config.construct(); - _setup_obtain_params_passphrase = Input_passphrase { }; - _setup_obtain_params_select = Setup_obtain_params_select::PASSPHRASE_INPUT; + _ui_config->passphrase = Passphrase(); Signal_transmitter(_state_handler).submit(); } @@ -1449,17 +859,15 @@ void File_vault::Main::handle_sandbox_state() } }; bool update_sandbox { false }; - bool update_dialog { false }; - bool nr_of_clients { false }; + bool generate_ui_report { false }; + Number_of_clients nr_of_clients { 0 }; sandbox_state.with_xml_node([&] (Xml_node const &sandbox_state) { switch (_state) { case State::SETUP_RUN_TRESOR_INIT_TRUST_ANCHOR: if (_child_succeeded(sandbox_state, _tresor_init_trust_anchor)) { - _set_state(State::SETUP_RUN_TRESOR_INIT); - update_dialog = true; update_sandbox = true; } break; @@ -1469,7 +877,6 @@ void File_vault::Main::handle_sandbox_state() if (_child_succeeded(sandbox_state, _truncate_file)) { _set_state(State::SETUP_RUN_TRESOR_INIT_TRUST_ANCHOR); - update_dialog = true; update_sandbox = true; } break; @@ -1481,7 +888,6 @@ void File_vault::Main::handle_sandbox_state() if (exit_code == 0) { _set_state(State::UNLOCK_START_TRESOR_VFS); - update_dialog = true; update_sandbox = true; } else @@ -1494,7 +900,6 @@ void File_vault::Main::handle_sandbox_state() if (_child_succeeded(sandbox_state, _tresor_init)) { _set_state(State::SETUP_START_TRESOR_VFS); - update_dialog = true; update_sandbox = true; } break; @@ -1504,7 +909,6 @@ void File_vault::Main::handle_sandbox_state() if (_child_succeeded(sandbox_state, _sync_to_tresor_vfs_init)) { _set_state(State::SETUP_FORMAT_TRESOR); - update_dialog = true; update_sandbox = true; } break; @@ -1514,7 +918,6 @@ void File_vault::Main::handle_sandbox_state() if (_child_succeeded(sandbox_state, _sync_to_tresor_vfs_init)) { _set_state(State::UNLOCK_DETERMINE_CLIENT_FS_SIZE); - update_dialog = true; update_sandbox = true; } break; @@ -1525,25 +928,16 @@ void File_vault::Main::handle_sandbox_state() _write_to_state_file(State::UNLOCK_OBTAIN_PARAMETERS); _set_state(State::SETUP_DETERMINE_CLIENT_FS_SIZE); - update_dialog = true; update_sandbox = true; } break; - case State::CONTROLS_ROOT: - case State::CONTROLS_SNAPSHOTS: - case State::CONTROLS_DIMENSIONS: - case State::CONTROLS_EXPAND_CLIENT_FS: - case State::CONTROLS_EXPAND_SNAPSHOT_BUF: - case State::CONTROLS_SECURITY: - case State::CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY: - case State::CONTROLS_SECURITY_MASTER_KEY: - case State::CONTROLS_SECURITY_USER_PASSPHRASE: + case State::CONTROLS: if (_resizing_state == Resizing_state::INACTIVE || - _resizing_type != Resizing_type::EXPAND_CLIENT_FS) + _ui_config->extend->tree != Ui_config::Extend::VIRTUAL_BLOCK_DEVICE) { - nr_of_clients = + nr_of_clients.value = _child_nr_of_provided_sessions( sandbox_state, _rump_vfs, "File_system"); } @@ -1553,7 +947,6 @@ void File_vault::Main::handle_sandbox_state() if (_child_succeeded(sandbox_state, _truncate_file)) { _resizing_state = Resizing_state::WAIT_TILL_DEVICE_IS_READY; - update_dialog = true; update_sandbox = true; } break; @@ -1563,7 +956,6 @@ void File_vault::Main::handle_sandbox_state() if (_child_succeeded(sandbox_state, _resizing_fs_tool)) { _resizing_state = Resizing_state::IN_PROGRESS_AT_DEVICE; - update_dialog = true; update_sandbox = true; } break; @@ -1572,9 +964,9 @@ void File_vault::Main::handle_sandbox_state() if (_child_succeeded(sandbox_state, _resize2fs)) { - _resizing_type = Resizing_type::NONE; _resizing_state = Resizing_state::INACTIVE; - update_dialog = true; + _ui_report.extend->finished = true; + generate_ui_report = true; update_sandbox = true; } break; @@ -1590,39 +982,6 @@ void File_vault::Main::handle_sandbox_state() if (_child_succeeded(sandbox_state, _rekeying_fs_tool)) { _rekeying_state = Rekeying_state::IN_PROGRESS_AT_DEVICE; - update_dialog = true; - update_sandbox = true; - } - break; - - default: - - break; - } - - switch (_create_snap_state) { - case Create_snapshot_state::ISSUE_REQUEST_AT_DEVICE: - - if (_child_succeeded(sandbox_state, _create_snap_fs_tool)) { - - _create_snap_state = Create_snapshot_state::INACTIVE; - update_dialog = true; - update_sandbox = true; - } - break; - - default: - - break; - } - - switch (_discard_snap_state) { - case Discard_snapshot_state::ISSUE_REQUEST_AT_DEVICE: - - if (_child_succeeded(sandbox_state, _discard_snap_fs_tool)) { - - _discard_snap_state = Discard_snapshot_state::INACTIVE; - update_dialog = true; update_sandbox = true; } break; @@ -1638,8 +997,17 @@ void File_vault::Main::handle_sandbox_state() if (_child_succeeded(sandbox_state, _lock_fs_tool)) { + if (_ui_report.rekey.constructed()) { + _ui_report.rekey->finished = true; + _rekeying_state = Rekeying_state::INACTIVE; + generate_ui_report = true; + } + if (_ui_report.extend.constructed()) { + _ui_report.extend->finished = true; + _resizing_state = Resizing_state::INACTIVE; + generate_ui_report = true; + } _set_state(State::LOCK_WAIT_TILL_DEINIT_REQUEST_IS_DONE); - update_dialog = true; update_sandbox = true; } break; @@ -1656,600 +1024,20 @@ void File_vault::Main::handle_sandbox_state() }); }); }); - if (_nr_of_clients != nr_of_clients) { - - _nr_of_clients = nr_of_clients; - update_dialog = true; + if (_ui_report.num_clients.value != nr_of_clients.value) { + _ui_report.num_clients.value = nr_of_clients.value; + generate_ui_report = true; } - if (update_dialog) { - - _dialog.trigger_update(); - } - if (update_sandbox) { - + if (update_sandbox) _update_sandbox_config(); - } -} - -void File_vault::Main::produce_xml(Xml_generator &xml) -{ - switch (_state) { - case State::INVALID: - - gen_info_frame(xml, _jent_avail, "1", "Please wait...", MAIN_FRAME_WIDTH); - break; - - case State::SETUP_OBTAIN_PARAMETERS: - - gen_main_frame(xml, _jent_avail, "1", MAIN_FRAME_WIDTH, [&] (Xml_generator &xml) { - - bool gen_start_button { true }; - bool gen_image_size_info { true }; - gen_input_passphrase( - xml, MAIN_FRAME_WIDTH, - _setup_obtain_params_passphrase, - _setup_obtain_params_select == Setup_obtain_params_select::PASSPHRASE_INPUT, - _setup_obtain_params_hover == Setup_obtain_params_hover::PASSPHRASE_SHOW_HIDE_BUTTON, - _setup_obtain_params_select == Setup_obtain_params_select::PASSPHRASE_SHOW_HIDE_BUTTON); - - if (!_ui_setup_obtain_params_passphrase_suitable()) { - - gen_start_button = false; - gen_info_line(xml, "info_1", "Must have at least 8 characters"); - } - gen_info_line(xml, "pad_1", ""); - gen_titled_text_input( - xml, "Client FS Size", "Client FS size", - _client_fs_size_input, - _setup_obtain_params_select == Setup_obtain_params_select::CLIENT_FS_SIZE_INPUT); - - if (_ui_client_fs_size() < MIN_CLIENT_FS_SIZE) { - - gen_image_size_info = false; - gen_start_button = false; - gen_info_line(xml, "info_2", - String<128> { - "Must be at least ", - Number_of_bytes { MIN_CLIENT_FS_SIZE } }.string()); - - } - gen_info_line(xml, "pad_2", ""); - gen_titled_text_input( - xml, "Snapshot Buffer Size", - RENAME_SNAPSHOT_BUFFER_JOURNALING_BUFFER ? - "Journaling buffer size" : - "Snapshot buffer size", - _journaling_buf_size_input, - _setup_obtain_params_select == Setup_obtain_params_select::SNAPSHOT_BUFFER_SIZE_INPUT); - - if (_ui_journaling_buf_size() < _min_journaling_buf_size()) { - - gen_image_size_info = false; - gen_start_button = false; - gen_info_line(xml, "info_3", - String<128> { - "Must be at least ", - Number_of_bytes { _min_journaling_buf_size() } }.string()); - } - if (gen_image_size_info) { - - gen_info_line(xml, "pad_3", ""); - gen_info_line( - xml, "info_4", - String<256> { "Image size: ", Capacity { _tresor_size() }}.string()); - } - gen_info_line(xml, "pad_4", ""); - if (gen_start_button) { - - gen_action_button_at_bottom( - xml, "ok", "Start", - _setup_obtain_params_hover == Setup_obtain_params_hover::START_BUTTON, - _setup_obtain_params_select == Setup_obtain_params_select::START_BUTTON); - } - }); - break; - - case State::UNLOCK_OBTAIN_PARAMETERS: - - gen_main_frame(xml, _jent_avail, "1", MAIN_FRAME_WIDTH, [&] (Xml_generator &xml) { - - bool gen_start_button { true }; - gen_input_passphrase( - xml, MAIN_FRAME_WIDTH, - _setup_obtain_params_passphrase, - _setup_obtain_params_select == Setup_obtain_params_select::PASSPHRASE_INPUT, - _setup_obtain_params_hover == Setup_obtain_params_hover::PASSPHRASE_SHOW_HIDE_BUTTON, - _setup_obtain_params_select == Setup_obtain_params_select::PASSPHRASE_SHOW_HIDE_BUTTON); - - if (!_ui_setup_obtain_params_passphrase_suitable()) { - - gen_start_button = false; - } - gen_info_line(xml, "pad_2", ""); - if (gen_start_button) { - - gen_action_button_at_bottom( - xml, "ok", "Unlock", - _setup_obtain_params_hover == Setup_obtain_params_hover::START_BUTTON, - _setup_obtain_params_select == Setup_obtain_params_select::START_BUTTON); - } - }); - break; - - case State::SETUP_RUN_TRESOR_INIT_TRUST_ANCHOR: - case State::SETUP_CREATE_TRESOR_IMAGE_FILE: - case State::SETUP_RUN_TRESOR_INIT: - case State::SETUP_START_TRESOR_VFS: - case State::SETUP_FORMAT_TRESOR: - case State::SETUP_DETERMINE_CLIENT_FS_SIZE: - case State::UNLOCK_RUN_TRESOR_INIT_TRUST_ANCHOR: - case State::UNLOCK_START_TRESOR_VFS: - case State::UNLOCK_DETERMINE_CLIENT_FS_SIZE: - - gen_info_frame(xml, _jent_avail, "1", "Please wait...", MAIN_FRAME_WIDTH); - break; - - case State::CONTROLS_ROOT: - - gen_controls_frame(xml, _jent_avail, "app", [&] (Xml_generator &xml) { - - xml.node("frame", [&] () { - - xml.node("vbox", [&] () { - - if (SHOW_CONTROLS_SNAPSHOTS) { - - gen_closed_menu( - xml, "Snapshots", "", - _controls_root_hover == Controls_root_hover::SNAPSHOTS_EXPAND_BUTTON); - } - gen_closed_menu( - xml, "Dimensions", "", - _controls_root_hover == Controls_root_hover::DIMENSIONS_BUTTON); - - gen_closed_menu( - xml, "Security", "", - _controls_root_hover == Controls_root_hover::SECURITY_EXPAND_BUTTON); - }); - }); - gen_global_controls( - xml, MAIN_FRAME_WIDTH, _tresor_image_size, _client_fs_size, _nr_of_clients, - _controls_root_hover == Controls_root_hover::LOCK_BUTTON, - _controls_root_select == Controls_root_select::LOCK_BUTTON); - }); - break; - - case State::CONTROLS_SNAPSHOTS: - - gen_controls_frame(xml, _jent_avail, "app", [&] (Xml_generator &xml) { - - xml.node("frame", [&] () { - - xml.node("vbox", [&] () { - - if (_snapshots_select.valid()) { - - Snapshot const &snap { _snapshots_select.object() }; - String<64> const snap_str { - "Generation ", snap.generation() }; - - gen_opened_menu( - xml, snap_str.string(), "", - _controls_snapshots_hover == Controls_snapshots_hover::GENERATION_LEAVE_BUTTON, - [&] (Xml_generator &xml) - { - gen_info_line(xml, "pad_1", ""); - switch(_discard_snap_state) { - case Discard_snapshot_state::INACTIVE: - - gen_action_button(xml, "Discard", "Discard", - _controls_snapshots_hover == Controls_snapshots_hover::GENERATION_DISCARD_BUTTON, - _controls_snapshots_select == Controls_snapshots_select::GENERATION_DISCARD_BUTTON); - - break; - - case Discard_snapshot_state::ISSUE_REQUEST_AT_DEVICE: - - gen_action_button(xml, "Inactive Discard", "...", - _controls_snapshots_hover == Controls_snapshots_hover::GENERATION_DISCARD_BUTTON, - false); - - break; - } - }); - } else { - - gen_opened_menu( - xml, "Snapshots", "", - _controls_snapshots_hover == Controls_snapshots_hover::LEAVE_BUTTON, - [&] (Xml_generator &xml) - { - xml.node("vbox", [&] () { - xml.attribute("name", "Generations"); - - _snapshots.for_each([&] (Snapshot const &snap) { - - bool const hovered { - _snapshots_hover.valid() && - _snapshots_hover.object().generation() == snap.generation() }; - - String<64> const snap_str { - "Generation ", snap.generation() }; - - Generation_string const gen_str { snap.generation() }; - - gen_multiple_choice_entry( - xml, gen_str.string(), snap_str.string(), hovered, - false); - }); - }); - gen_info_line(xml, "pad_1", ""); - switch(_create_snap_state) { - case Create_snapshot_state::INACTIVE: - - gen_action_button(xml, "Create", "Create", - _controls_snapshots_hover == Controls_snapshots_hover::CREATE_BUTTON, - _controls_snapshots_select == Controls_snapshots_select::CREATE_BUTTON); - break; - - case Create_snapshot_state::ISSUE_REQUEST_AT_DEVICE: - - gen_action_button(xml, "Inactive Create", "...", - _controls_snapshots_hover == Controls_snapshots_hover::CREATE_BUTTON, - false); - - break; - } - }); - } - }); - }); - gen_global_controls( - xml, MAIN_FRAME_WIDTH, _tresor_image_size, _client_fs_size, _nr_of_clients, - _controls_snapshots_hover == Controls_snapshots_hover::LOCK_BUTTON, - _controls_snapshots_select == Controls_snapshots_select::LOCK_BUTTON); - }); - break; - - case State::CONTROLS_DIMENSIONS: - - gen_controls_frame(xml, _jent_avail, "app", [&] (Xml_generator &xml) { - - xml.node("frame", [&] () { - - gen_opened_menu( - xml, "Dimensions", "", - _dimensions_hover == Dimensions_hover::LEAVE_BUTTON, - [&] (Xml_generator &xml) - { - gen_closed_menu( - xml, "Expand Client FS", "", - _dimensions_hover == Dimensions_hover::EXPAND_CLIENT_FS_BUTTON); - - gen_closed_menu( - xml, - RENAME_SNAPSHOT_BUFFER_JOURNALING_BUFFER ? - "Expand Journaling Buffer" : - "Expand Snapshot Buffer", - "", - _dimensions_hover == Dimensions_hover::EXPAND_SNAPSHOT_BUF_BUTTON); - }); - }); - gen_global_controls( - xml, MAIN_FRAME_WIDTH, _tresor_image_size, _client_fs_size, _nr_of_clients, - _dimensions_hover == Dimensions_hover::LOCK_BUTTON, - _dimensions_select == Dimensions_select::LOCK_BUTTON); - }); - break; - - case State::CONTROLS_EXPAND_CLIENT_FS: - - gen_controls_frame(xml, _jent_avail, "app", [&] (Xml_generator &xml) { - - xml.node("frame", [&] () { - - xml.node("vbox", [&] () { - - gen_opened_menu( - xml, "Expand Client FS", "", - _expand_client_fs_hover == Expand_client_fs_hover::LEAVE_BUTTON, - [&] (Xml_generator &xml) - { - gen_info_line(xml, "pad_1", ""); - switch (_resizing_state) { - case Resizing_state::INACTIVE: - { - if (_nr_of_clients > 0) { - - gen_centered_info_line(xml, "Info 1", "Not possible while in use!"); - gen_info_line(xml, "Padding 1", ""); - - } else { - - gen_titled_text_input( - xml, "Contingent", "Contingent", - _expand_client_fs_contingent, - _expand_client_fs_select == Expand_client_fs_select::CONTINGENT_INPUT); - - bool gen_start_button { true }; - size_t const bytes { - _expand_client_fs_contingent.value() }; - - size_t const effective_bytes { - bytes - (bytes % Tresor::BLOCK_SIZE) }; - - if (effective_bytes > 0) { - - gen_info_line( - xml, "inf_2", - String<128> { - "New image size: ", - Capacity { _tresor_image_size + effective_bytes } - }.string()); - - } else { - - gen_info_line(xml, "info_1", - String<128> { - "Must be at least ", - Number_of_bytes { Tresor::BLOCK_SIZE } }.string()); - - gen_start_button = false; - } - gen_info_line(xml, "pad_2", ""); - if (gen_start_button) { - - gen_action_button_at_bottom( - xml, "Start", - _expand_client_fs_hover == Expand_client_fs_hover::START_BUTTON, - _expand_client_fs_select == Expand_client_fs_select::START_BUTTON); - } - } - break; - } - case Resizing_state::ADAPT_TRESOR_IMAGE_SIZE: - case Resizing_state::WAIT_TILL_DEVICE_IS_READY: - case Resizing_state::ISSUE_REQUEST_AT_DEVICE: - case Resizing_state::IN_PROGRESS_AT_DEVICE: - case Resizing_state::DETERMINE_CLIENT_FS_SIZE: - case Resizing_state::RUN_RESIZE2FS: - - gen_centered_info_line(xml, "inf", "Please wait..."); - gen_info_line(xml, "pad_2", ""); - break; - } - }); - }); - }); - gen_global_controls( - xml, MAIN_FRAME_WIDTH, _tresor_image_size, _client_fs_size, _nr_of_clients, - _expand_client_fs_hover == Expand_client_fs_hover::LOCK_BUTTON, - _expand_client_fs_select == Expand_client_fs_select::LOCK_BUTTON); - }); - break; - - case State::CONTROLS_EXPAND_SNAPSHOT_BUF: - - gen_controls_frame(xml, _jent_avail, "app", [&] (Xml_generator &xml) { - - xml.node("frame", [&] () { - - xml.node("vbox", [&] () { - - gen_opened_menu( - xml, - RENAME_SNAPSHOT_BUFFER_JOURNALING_BUFFER ? - "Expand Journaling Buffer" : - "Expand Snapshot Buffer", - "", - _expand_snapshot_buf_hover == Expand_snapshot_buf_hover::LEAVE_BUTTON, - [&] (Xml_generator &xml) - { - gen_info_line(xml, "pad_1", ""); - switch (_resizing_state) { - case Resizing_state::INACTIVE: - { - gen_titled_text_input( - xml, "Contingent", "Contingent", - _expand_snapshot_buf_contingent, - _expand_snapshot_buf_select == Expand_snapshot_buf_select::CONTINGENT_INPUT); - - bool gen_start_button { true }; - size_t const bytes { - _expand_snapshot_buf_contingent.value() }; - - size_t const effective_bytes { - bytes - (bytes % TRESOR_BLOCK_SIZE) }; - - if (effective_bytes > 0) { - - gen_info_line( - xml, "inf_2", - String<128> { - "New image size: ", - Capacity { _tresor_image_size + effective_bytes } - }.string()); - - } else { - - gen_start_button = false; - gen_info_line(xml, "info_1", - String<128> { - "Must be at least ", - Number_of_bytes { TRESOR_BLOCK_SIZE } }.string()); - } - gen_info_line(xml, "pad_2", ""); - if (gen_start_button) { - - gen_action_button_at_bottom( - xml, "Start", - _expand_snapshot_buf_hover == Expand_snapshot_buf_hover::START_BUTTON, - _expand_snapshot_buf_select == Expand_snapshot_buf_select::START_BUTTON); - } - break; - } - case Resizing_state::ADAPT_TRESOR_IMAGE_SIZE: - case Resizing_state::WAIT_TILL_DEVICE_IS_READY: - case Resizing_state::ISSUE_REQUEST_AT_DEVICE: - case Resizing_state::IN_PROGRESS_AT_DEVICE: - case Resizing_state::DETERMINE_CLIENT_FS_SIZE: - case Resizing_state::RUN_RESIZE2FS: - - gen_centered_info_line(xml, "inf", "Please wait..."); - gen_info_line(xml, "pad_2", ""); - break; - } - }); - }); - }); - gen_global_controls( - xml, MAIN_FRAME_WIDTH, _tresor_image_size, _client_fs_size, _nr_of_clients, - _expand_snapshot_buf_hover == Expand_snapshot_buf_hover::LOCK_BUTTON, - _expand_snapshot_buf_select == Expand_snapshot_buf_select::LOCK_BUTTON); - }); - break; - - case State::CONTROLS_SECURITY: - - gen_controls_frame(xml, _jent_avail, "app", [&] (Xml_generator &xml) { - - xml.node("frame", [&] () { - - gen_opened_menu( - xml, "Security", "", - _controls_security_hover == Controls_security_hover::SECURITY_EXPAND_BUTTON, - [&] (Xml_generator &xml) - { - gen_closed_menu( - xml, "Block Encryption Key", "", - _controls_security_hover == Controls_security_hover::BLOCK_ENCRYPTION_KEY_EXPAND_BUTTON); - - if (SHOW_CONTROLS_SECURITY_MASTER_KEY) { - - gen_closed_menu( - xml, "Master Key", "", - _controls_security_hover == Controls_security_hover::MASTER_KEY_EXPAND_BUTTON); - } - if (SHOW_CONTROLS_SECURITY_USER_PASSPHRASE) { - - gen_closed_menu( - xml, "User Passphrase", "", - _controls_security_hover == Controls_security_hover::USER_PASSPHRASE_EXPAND_BUTTON); - } - }); - }); - gen_global_controls( - xml, MAIN_FRAME_WIDTH, _tresor_image_size, _client_fs_size, _nr_of_clients, - _controls_security_hover == Controls_security_hover::LOCK_BUTTON, - _controls_security_select == Controls_security_select::LOCK_BUTTON); - }); - break; - - case State::CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY: - - gen_controls_frame(xml, _jent_avail, "app", [&] (Xml_generator &xml) { - - xml.node("frame", [&] () { - - gen_opened_menu( - xml, "Block Encryption Key", "", - _controls_security_block_encryption_key_hover == Controls_security_block_encryption_key_hover::LEAVE_BUTTON, - [&] (Xml_generator &xml) - { - gen_info_line(xml, "pad_1", ""); - switch(_rekeying_state) { - case Rekeying_state::INACTIVE: - - gen_action_button(xml, "Rekey", "Replace", - _controls_security_block_encryption_key_hover == Controls_security_block_encryption_key_hover::REPLACE_BUTTON, - _controls_security_block_encryption_key_select == Controls_security_block_encryption_key_select::REPLACE_BUTTON); - - break; - - case Rekeying_state::WAIT_TILL_DEVICE_IS_READY: - case Rekeying_state::ISSUE_REQUEST_AT_DEVICE: - case Rekeying_state::IN_PROGRESS_AT_DEVICE: - - gen_centered_info_line(xml, "inf", "Please wait..."); - gen_info_line(xml, "pad_2", ""); - break; - } - gen_info_line(xml, "pad_1", ""); - }); - }); - gen_global_controls( - xml, MAIN_FRAME_WIDTH, _tresor_image_size, _client_fs_size, _nr_of_clients, - _controls_security_block_encryption_key_hover == Controls_security_block_encryption_key_hover::LOCK_BUTTON, - _controls_security_block_encryption_key_select == Controls_security_block_encryption_key_select::LOCK_BUTTON); - }); - break; - - case State::CONTROLS_SECURITY_MASTER_KEY: - - gen_controls_frame(xml, _jent_avail, "app", [&] (Xml_generator &xml) { - - xml.node("frame", [&] () { - - gen_opened_menu( - xml, "Master Key", "", - _controls_security_master_key_hover == Controls_security_master_key_hover::LEAVE_BUTTON, - [&] (Xml_generator &xml) - { - gen_info_line(xml, "pad_1", ""); - gen_info_line(xml, "inf_1", "The master key cannot be replaced by now."); - gen_info_line(xml, "pad_2", ""); - }); - }); - gen_global_controls( - xml, MAIN_FRAME_WIDTH, _tresor_image_size, _client_fs_size, _nr_of_clients, - _controls_security_master_key_hover == Controls_security_master_key_hover::LOCK_BUTTON, - _controls_security_master_key_select == Controls_security_master_key_select::LOCK_BUTTON); - }); - break; - - case State::CONTROLS_SECURITY_USER_PASSPHRASE: - - gen_controls_frame(xml, _jent_avail, "app", [&] (Xml_generator &xml) { - - xml.node("frame", [&] () { - - gen_opened_menu( - xml, "User Passphrase", "", - _controls_security_user_passphrase_hover == Controls_security_user_passphrase_hover::LEAVE_BUTTON, - [&] (Xml_generator &xml) - { - gen_info_line(xml, "pad_1", ""); - gen_info_line(xml, "inf_1", "The user passphrase cannot be replaced by now."); - gen_info_line(xml, "pad_2", ""); - }); - }); - gen_global_controls( - xml, MAIN_FRAME_WIDTH, _tresor_image_size, _client_fs_size, _nr_of_clients, - _controls_security_user_passphrase_hover == Controls_security_user_passphrase_hover::LOCK_BUTTON, - _controls_security_user_passphrase_select == Controls_security_user_passphrase_select::LOCK_BUTTON); - }); - break; - - case State::LOCK_ISSUE_DEINIT_REQUEST_AT_TRESOR: - case State::LOCK_WAIT_TILL_DEINIT_REQUEST_IS_DONE: - - gen_info_frame(xml, _jent_avail, "1", "Please wait...", MAIN_FRAME_WIDTH); - break; - } + if (generate_ui_report) + _generate_ui_report(); } void File_vault::Main::wakeup_local_service() { - _rom_service.for_each_requested_session([&] (Rom_service::Request &request) { - - if (request.label == "menu_view -> dialog") - request.deliver_session(_dialog); - else - request.deny(); - }); - _report_service.for_each_requested_session([&] (Report_service::Request &request) { if (request.label == "fs_query -> listing") { @@ -2279,15 +1067,6 @@ void File_vault::Main::wakeup_local_service() request.deliver_session(session); - } else if (request.label == "snapshots_fs_query -> listing") { - - Report::Session_component &session { *new (_heap) - Report::Session_component( - _env, _snapshots_fs_query_listing_handler, _env.ep(), - request.resources, "", request.diag) }; - - request.deliver_session(session); - } else if (request.label == "resizing_fs_query -> listing") { Report::Session_component &session { *new (_heap) @@ -2321,53 +1100,11 @@ void File_vault::Main::wakeup_local_service() } }); - _report_service.for_each_requested_session([&] (Report_service::Request &request) { - - if (request.label == "menu_view -> hover") { - Report::Session_component &session = *new (_heap) - Report::Session_component(_env, _hover_handler, - _env.ep(), - request.resources, "", request.diag); - request.deliver_session(session); - } - }); - _report_service.for_each_session_to_close([&] (Report::Session_component &session) { destroy(_heap, &session); return Report_service::Close_response::CLOSED; }); - - _gui_service.for_each_requested_session([&] (Gui_service::Request &request) { - - Gui::Session_component &session = *new (_heap) - Gui::Session_component(_env, *this, _env.ep(), - request.resources, "", request.diag); - - request.deliver_session(session); - }); - - _gui_service.for_each_upgraded_session([&] (Gui::Session_component &session, - Session::Resources const &amount) { - session.upgrade(amount); - return Gui_service::Upgrade_response::CONFIRMED; - }); - - _gui_service.for_each_session_to_close([&] (Gui::Session_component &session) { - - destroy(_heap, &session); - return Gui_service::Close_response::CLOSED; - }); -} - - -Number_of_blocks Main::_tresor_tree_num_leaves(uint64_t payload_size) -{ - Number_of_blocks nr_of_leaves { payload_size / TRESOR_BLOCK_SIZE }; - if (payload_size % TRESOR_BLOCK_SIZE) { - nr_of_leaves++; - } - return nr_of_leaves; } @@ -2377,46 +1114,40 @@ void File_vault::Main::_generate_sandbox_config(Xml_generator &xml) const case State::INVALID: gen_parent_provides_and_report_nodes(xml); - _gen_menu_view_start_node_if_required(xml); gen_fs_query_start_node(xml, _fs_query); break; case State::SETUP_OBTAIN_PARAMETERS: gen_parent_provides_and_report_nodes(xml); - _gen_menu_view_start_node_if_required(xml); break; case State::UNLOCK_OBTAIN_PARAMETERS: gen_parent_provides_and_report_nodes(xml); - _gen_menu_view_start_node_if_required(xml); break; case State::SETUP_RUN_TRESOR_INIT_TRUST_ANCHOR: gen_parent_provides_and_report_nodes(xml); - _gen_menu_view_start_node_if_required(xml); gen_tresor_trust_anchor_vfs_start_node(xml, _tresor_trust_anchor_vfs, _jent_avail); gen_tresor_init_trust_anchor_start_node( - xml, _tresor_init_trust_anchor, _ui_setup_obtain_params_passphrase()); + xml, _tresor_init_trust_anchor, _ui_config->passphrase); break; case State::UNLOCK_RUN_TRESOR_INIT_TRUST_ANCHOR: gen_parent_provides_and_report_nodes(xml); - _gen_menu_view_start_node_if_required(xml); gen_tresor_trust_anchor_vfs_start_node(xml, _tresor_trust_anchor_vfs, _jent_avail); gen_tresor_init_trust_anchor_start_node( - xml, _tresor_init_trust_anchor, _ui_setup_obtain_params_passphrase()); + xml, _tresor_init_trust_anchor, _ui_config->passphrase); break; case State::UNLOCK_START_TRESOR_VFS: gen_parent_provides_and_report_nodes(xml); - _gen_menu_view_start_node_if_required(xml); gen_tresor_trust_anchor_vfs_start_node(xml, _tresor_trust_anchor_vfs, _jent_avail); gen_tresor_vfs_start_node(xml, _tresor_vfs, _tresor_image_file_name); gen_sync_to_tresor_vfs_init_start_node(xml, _sync_to_tresor_vfs_init); @@ -2426,7 +1157,6 @@ void File_vault::Main::_generate_sandbox_config(Xml_generator &xml) const case State::UNLOCK_DETERMINE_CLIENT_FS_SIZE: gen_parent_provides_and_report_nodes(xml); - _gen_menu_view_start_node_if_required(xml); gen_tresor_trust_anchor_vfs_start_node(xml, _tresor_trust_anchor_vfs, _jent_avail); gen_tresor_vfs_start_node(xml, _tresor_vfs, _tresor_image_file_name); gen_client_fs_fs_query_start_node(xml, _client_fs_fs_query); @@ -2435,31 +1165,29 @@ void File_vault::Main::_generate_sandbox_config(Xml_generator &xml) const case State::SETUP_CREATE_TRESOR_IMAGE_FILE: gen_parent_provides_and_report_nodes(xml); - _gen_menu_view_start_node_if_required(xml); gen_tresor_trust_anchor_vfs_start_node(xml, _tresor_trust_anchor_vfs, _jent_avail); gen_truncate_file_start_node( xml, _truncate_file, File_path { "/tresor/", _tresor_image_file_name }.string(), - TRESOR_BLOCK_SIZE * - _tresor_nr_of_blocks( - TRESOR_NR_OF_SUPERBLOCKS, + BLOCK_SIZE * + tresor_num_blocks( + NR_OF_SUPERBLOCK_SLOTS, TRESOR_VBD_MAX_LVL + 1, TRESOR_VBD_DEGREE, - _tresor_tree_num_leaves(_ui_client_fs_size()), + tresor_tree_num_leaves(_ui_config->client_fs_size), TRESOR_FREE_TREE_MAX_LVL + 1, TRESOR_FREE_TREE_DEGREE, - _tresor_tree_num_leaves(_ui_journaling_buf_size()))); + tresor_tree_num_leaves(_ui_config->journaling_buf_size))); break; case State::SETUP_RUN_TRESOR_INIT: { Tresor::Superblock_configuration sb_config { - Tree_configuration { TRESOR_VBD_MAX_LVL, TRESOR_VBD_DEGREE, _tresor_tree_num_leaves(_ui_client_fs_size()) }, - Tree_configuration { TRESOR_FREE_TREE_MAX_LVL, TRESOR_FREE_TREE_DEGREE, _tresor_tree_num_leaves(_ui_journaling_buf_size()) } + Tree_configuration { TRESOR_VBD_MAX_LVL, TRESOR_VBD_DEGREE, tresor_tree_num_leaves(_ui_config->client_fs_size) }, + Tree_configuration { TRESOR_FREE_TREE_MAX_LVL, TRESOR_FREE_TREE_DEGREE, tresor_tree_num_leaves(_ui_config->journaling_buf_size) } }; gen_parent_provides_and_report_nodes(xml); - _gen_menu_view_start_node_if_required(xml); gen_tresor_trust_anchor_vfs_start_node(xml, _tresor_trust_anchor_vfs, _jent_avail); gen_tresor_init_start_node(xml, _tresor_init, sb_config); break; @@ -2467,7 +1195,6 @@ void File_vault::Main::_generate_sandbox_config(Xml_generator &xml) const case State::SETUP_START_TRESOR_VFS: gen_parent_provides_and_report_nodes(xml); - _gen_menu_view_start_node_if_required(xml); gen_tresor_trust_anchor_vfs_start_node(xml, _tresor_trust_anchor_vfs, _jent_avail); gen_tresor_vfs_start_node(xml, _tresor_vfs, _tresor_image_file_name); gen_sync_to_tresor_vfs_init_start_node(xml, _sync_to_tresor_vfs_init); @@ -2476,75 +1203,47 @@ void File_vault::Main::_generate_sandbox_config(Xml_generator &xml) const case State::SETUP_FORMAT_TRESOR: gen_parent_provides_and_report_nodes(xml); - _gen_menu_view_start_node_if_required(xml); gen_tresor_trust_anchor_vfs_start_node(xml, _tresor_trust_anchor_vfs, _jent_avail); gen_tresor_vfs_start_node(xml, _tresor_vfs, _tresor_image_file_name); gen_tresor_vfs_block_start_node(xml, _tresor_vfs_block); gen_mke2fs_start_node(xml, _mke2fs); break; - case State::CONTROLS_ROOT: - case State::CONTROLS_SNAPSHOTS: - case State::CONTROLS_DIMENSIONS: - case State::CONTROLS_EXPAND_CLIENT_FS: - case State::CONTROLS_EXPAND_SNAPSHOT_BUF: - case State::CONTROLS_SECURITY: - case State::CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY: - case State::CONTROLS_SECURITY_MASTER_KEY: - case State::CONTROLS_SECURITY_USER_PASSPHRASE: + case State::CONTROLS: { gen_parent_provides_and_report_nodes(xml); - _gen_menu_view_start_node_if_required(xml); gen_tresor_trust_anchor_vfs_start_node(xml, _tresor_trust_anchor_vfs, _jent_avail); gen_tresor_vfs_start_node(xml, _tresor_vfs, _tresor_image_file_name); gen_tresor_vfs_block_start_node(xml, _tresor_vfs_block); - gen_snapshots_fs_query_start_node(xml, _snapshots_fs_query); gen_image_fs_query_start_node(xml, _image_fs_query); switch(_resizing_state) { - case Resizing_state::INACTIVE: - - break; - + case Resizing_state::INACTIVE: break; case Resizing_state::ADAPT_TRESOR_IMAGE_SIZE: - switch (_resizing_type) { - case Resizing_type::EXPAND_CLIENT_FS: + switch (_ui_config->extend->tree) { + case Ui_config::Extend::VIRTUAL_BLOCK_DEVICE: { - size_t const bytes { - _expand_client_fs_contingent.value() }; - - size_t const effective_bytes { - bytes - (bytes % TRESOR_BLOCK_SIZE) }; - + size_t const bytes { _ui_config->extend->num_bytes }; + size_t const effective_bytes { bytes - (bytes % BLOCK_SIZE) }; gen_truncate_file_start_node( xml, _truncate_file, File_path { "/tresor/", _tresor_image_file_name }.string(), - _tresor_image_size + effective_bytes); + _ui_report.image_size + effective_bytes); break; } - case Resizing_type::EXPAND_SNAPSHOT_BUF: + case Ui_config::Extend::FREE_TREE: { - size_t const bytes { - _expand_snapshot_buf_contingent.value() }; - - size_t const effective_bytes { - bytes - (bytes % TRESOR_BLOCK_SIZE) }; - + size_t const bytes { _ui_config->extend->num_bytes }; + size_t const effective_bytes { bytes - (bytes % BLOCK_SIZE) }; gen_truncate_file_start_node( xml, _truncate_file, File_path { "/tresor/", _tresor_image_file_name }.string(), - _tresor_image_size + effective_bytes); + _ui_report.image_size + effective_bytes); break; - } - default: - - class Unexpected_resizing_type { }; - throw Unexpected_resizing_type { }; - break; - } + } } break; case Resizing_state::WAIT_TILL_DEVICE_IS_READY: @@ -2554,27 +1253,19 @@ void File_vault::Main::_generate_sandbox_config(Xml_generator &xml) const case Resizing_state::ISSUE_REQUEST_AT_DEVICE: - switch (_resizing_type) { - case Resizing_type::EXPAND_CLIENT_FS: + switch (_ui_config->extend->tree) { + case Ui_config::Extend::VIRTUAL_BLOCK_DEVICE: gen_resizing_fs_tool_start_node( xml, _resizing_fs_tool, "vbd", - _expand_client_fs_contingent.value() / TRESOR_BLOCK_SIZE); - + _ui_config->extend->num_bytes / BLOCK_SIZE); break; - case Resizing_type::EXPAND_SNAPSHOT_BUF: + case Ui_config::Extend::FREE_TREE: gen_resizing_fs_tool_start_node( xml, _resizing_fs_tool, "ft", - _expand_snapshot_buf_contingent.value() / TRESOR_BLOCK_SIZE); - - break; - - default: - - class Unexpected_resizing_type { }; - throw Unexpected_resizing_type { }; + _ui_config->extend->num_bytes / BLOCK_SIZE); break; } break; @@ -2615,31 +1306,8 @@ void File_vault::Main::_generate_sandbox_config(Xml_generator &xml) const gen_rekeying_fs_query_start_node(xml, _rekeying_fs_query); break; } - - switch(_create_snap_state) { - case Create_snapshot_state::INACTIVE: - - break; - - case Create_snapshot_state::ISSUE_REQUEST_AT_DEVICE: - - gen_create_snap_fs_tool_start_node(xml, _create_snap_fs_tool); - break; - } - - switch(_discard_snap_state) { - case Discard_snapshot_state::INACTIVE: - - break; - - case Discard_snapshot_state::ISSUE_REQUEST_AT_DEVICE: - - gen_discard_snap_fs_tool_start_node(xml, _discard_snap_fs_tool, _discard_snap_gen); - break; - } - if (_resizing_state == Resizing_state::INACTIVE || - _resizing_type != Resizing_type::EXPAND_CLIENT_FS) { + _ui_config->extend->tree != Ui_config::Extend::VIRTUAL_BLOCK_DEVICE) { gen_policy_for_child_service(xml, "File_system", _rump_vfs); gen_rump_vfs_start_node(xml, _rump_vfs); @@ -2650,11 +1318,9 @@ void File_vault::Main::_generate_sandbox_config(Xml_generator &xml) const gen_parent_provides_and_report_nodes(xml); gen_policy_for_child_service(xml, "File_system", _rump_vfs); - _gen_menu_view_start_node_if_required(xml); gen_tresor_trust_anchor_vfs_start_node(xml, _tresor_trust_anchor_vfs, _jent_avail); gen_tresor_vfs_start_node(xml, _tresor_vfs, _tresor_image_file_name); gen_tresor_vfs_block_start_node(xml, _tresor_vfs_block); - gen_snapshots_fs_query_start_node(xml, _snapshots_fs_query); gen_lock_fs_tool_start_node(xml, _lock_fs_tool); break; @@ -2662,1761 +1328,13 @@ void File_vault::Main::_generate_sandbox_config(Xml_generator &xml) const gen_parent_provides_and_report_nodes(xml); gen_policy_for_child_service(xml, "File_system", _rump_vfs); - _gen_menu_view_start_node_if_required(xml); gen_tresor_trust_anchor_vfs_start_node(xml, _tresor_trust_anchor_vfs, _jent_avail); gen_tresor_vfs_start_node(xml, _tresor_vfs, _tresor_image_file_name); gen_tresor_vfs_block_start_node(xml, _tresor_vfs_block); - gen_snapshots_fs_query_start_node(xml, _snapshots_fs_query); gen_lock_fs_query_start_node(xml, _lock_fs_query); break; } } -uint64_t Main::_tree_nr_of_blocks(size_t nr_of_lvls, - size_t nr_of_children, - uint64_t nr_of_leafs) -{ - uint64_t nr_of_blks { 0 }; - uint64_t nr_of_last_lvl_blks { nr_of_leafs }; - for (size_t lvl_idx { 0 }; lvl_idx < nr_of_lvls; lvl_idx++) { - nr_of_blks += nr_of_last_lvl_blks; - if (nr_of_last_lvl_blks % nr_of_children) { - nr_of_last_lvl_blks = nr_of_last_lvl_blks / nr_of_children + 1; - } else { - nr_of_last_lvl_blks = nr_of_last_lvl_blks / nr_of_children; - } - } - return nr_of_blks; -} - - -uint64_t Main::_tresor_size() const -{ - return - _tresor_nr_of_blocks( - TRESOR_NR_OF_SUPERBLOCKS, - TRESOR_VBD_MAX_LVL + 1, - TRESOR_VBD_DEGREE, - _tresor_tree_num_leaves(_ui_client_fs_size()), - TRESOR_FREE_TREE_MAX_LVL + 1, - TRESOR_FREE_TREE_DEGREE, - _tresor_tree_num_leaves(_ui_journaling_buf_size())) - * TRESOR_BLOCK_SIZE; -} - - -uint64_t Main::_tresor_nr_of_blocks(size_t nr_of_superblocks, - size_t nr_of_vbd_lvls, - size_t nr_of_vbd_children, - uint64_t nr_of_vbd_leafs, - size_t nr_of_ft_lvls, - size_t nr_of_ft_children, - uint64_t nr_of_ft_leafs) -{ - uint64_t const nr_of_vbd_blks { - _tree_nr_of_blocks( - nr_of_vbd_lvls, - nr_of_vbd_children, - nr_of_vbd_leafs) }; - - uint64_t const nr_of_ft_blks { - _tree_nr_of_blocks( - nr_of_ft_lvls, - nr_of_ft_children, - nr_of_ft_leafs) }; - - /* FIXME - * - * This would be the correct way to calculate the number of MT blocks - * but the Tresor still uses an MT the same size as the FT for simplicity - * reasons. As soon as the Tresor does it right we should fix also this path. - * - * size_t const nr_of_mt_leafs { - * nr_of_ft_blks - nr_of_ft_leafs }; - * - * size_t const nr_of_mt_blks { - * _tree_nr_of_blocks( - * nr_of_mt_lvls, - * nr_of_mt_children, - * nr_of_mt_leafs) }; - */ - uint64_t const nr_of_mt_blks { nr_of_ft_blks }; - - return - nr_of_superblocks + - nr_of_vbd_blks + - nr_of_ft_blks + - nr_of_mt_blks; -} - - -void File_vault::Main::handle_input_event(Input::Event const &event) -{ - bool update_dialog { false }; - bool update_sandbox_config { false }; - - switch (_state) { - case State::SETUP_OBTAIN_PARAMETERS: - - event.handle_press([&] (Input::Keycode key, Codepoint code) { - - if (key == Input::BTN_LEFT) { - - Setup_obtain_params_select const prev_select { _setup_obtain_params_select }; - Setup_obtain_params_select next_select { Setup_obtain_params_select::NONE }; - - switch (_setup_obtain_params_hover) { - case Setup_obtain_params_hover::START_BUTTON: - - next_select = Setup_obtain_params_select::START_BUTTON; - break; - - case Setup_obtain_params_hover::PASSPHRASE_SHOW_HIDE_BUTTON: - - next_select = Setup_obtain_params_select::PASSPHRASE_SHOW_HIDE_BUTTON; - break; - - case Setup_obtain_params_hover::PASSPHRASE_INPUT: - - next_select = Setup_obtain_params_select::PASSPHRASE_INPUT; - break; - - case Setup_obtain_params_hover::CLIENT_FS_SIZE_INPUT: - - next_select = Setup_obtain_params_select::CLIENT_FS_SIZE_INPUT; - break; - - case Setup_obtain_params_hover::SNAPSHOT_BUFFER_SIZE_INPUT: - - next_select = Setup_obtain_params_select::SNAPSHOT_BUFFER_SIZE_INPUT; - break; - - case Setup_obtain_params_hover::NONE: - - next_select = Setup_obtain_params_select::NONE; - break; - } - if (next_select != prev_select) { - - _setup_obtain_params_select = next_select; - update_dialog = true; - } - - } else if (key == Input::KEY_ENTER) { - - if (_ui_setup_obtain_params_suitable() && - _setup_obtain_params_select != Setup_obtain_params_select::START_BUTTON) { - - _setup_obtain_params_select = Setup_obtain_params_select::START_BUTTON; - update_dialog = true; - } - - } else if (key == Input::KEY_TAB) { - - switch (_setup_obtain_params_select) { - case Setup_obtain_params_select::PASSPHRASE_INPUT: - - _setup_obtain_params_select = Setup_obtain_params_select::CLIENT_FS_SIZE_INPUT; - update_dialog = true; - break; - - case Setup_obtain_params_select::CLIENT_FS_SIZE_INPUT: - - _setup_obtain_params_select = Setup_obtain_params_select::SNAPSHOT_BUFFER_SIZE_INPUT; - update_dialog = true; - break; - - case Setup_obtain_params_select::SNAPSHOT_BUFFER_SIZE_INPUT: - - _setup_obtain_params_select = Setup_obtain_params_select::PASSPHRASE_INPUT; - update_dialog = true; - break; - - default: - - break; - } - - } else { - - if (_setup_obtain_params_select == Setup_obtain_params_select::PASSPHRASE_INPUT) { - - if (_setup_obtain_params_passphrase.appendable_character(code)) { - - _setup_obtain_params_passphrase.append_character(code); - update_dialog = true; - - } else if (code.value == CODEPOINT_BACKSPACE) { - - _setup_obtain_params_passphrase.remove_last_character(); - update_dialog = true; - } - - } else if (_setup_obtain_params_select == Setup_obtain_params_select::CLIENT_FS_SIZE_INPUT) { - - if (_client_fs_size_input.appendable_character(code)) { - - _client_fs_size_input.append_character(code); - update_dialog = true; - - } else if (code.value == CODEPOINT_BACKSPACE) { - - _client_fs_size_input.remove_last_character(); - update_dialog = true; - - } - } else if (_setup_obtain_params_select == Setup_obtain_params_select::SNAPSHOT_BUFFER_SIZE_INPUT) { - - if (_journaling_buf_size_input.appendable_character(code)) { - - _journaling_buf_size_input.append_character(code); - update_dialog = true; - - } else if (code.value == CODEPOINT_BACKSPACE) { - - _journaling_buf_size_input.remove_last_character(); - update_dialog = true; - - } - } else if (_setup_obtain_params_select == Setup_obtain_params_select::SNAPSHOT_BUFFER_SIZE_INPUT) { - - if (_journaling_buf_size_input.appendable_character(code)) { - - _journaling_buf_size_input.append_character(code); - update_dialog = true; - - } else if (code.value == CODEPOINT_BACKSPACE) { - - _journaling_buf_size_input.remove_last_character(); - update_dialog = true; - - } - } - } - }); - event.handle_release([&] (Input::Keycode key) { - - if (key == Input::BTN_LEFT || - key == Input::KEY_ENTER) { - - switch (_setup_obtain_params_select) { - case Setup_obtain_params_select::PASSPHRASE_SHOW_HIDE_BUTTON: - - if (_setup_obtain_params_passphrase.hide()) { - _setup_obtain_params_passphrase.hide(false); - } else { - _setup_obtain_params_passphrase.hide(true); - } - _setup_obtain_params_select = Setup_obtain_params_select::PASSPHRASE_INPUT; - update_dialog = true; - break; - - case Setup_obtain_params_select::START_BUTTON: - - if(_ui_setup_obtain_params_suitable()) { - _setup_obtain_params_select = Setup_obtain_params_select::NONE; - _set_state(State::SETUP_CREATE_TRESOR_IMAGE_FILE); - update_sandbox_config = true; - update_dialog = true; - } - break; - - default: - - break; - } - } - }); - break; - - case State::UNLOCK_OBTAIN_PARAMETERS: - - event.handle_press([&] (Input::Keycode key, Codepoint code) { - - if (key == Input::BTN_LEFT) { - - Setup_obtain_params_select const prev_select { _setup_obtain_params_select }; - Setup_obtain_params_select next_select { Setup_obtain_params_select::NONE }; - - switch (_setup_obtain_params_hover) { - case Setup_obtain_params_hover::PASSPHRASE_SHOW_HIDE_BUTTON: - - next_select = Setup_obtain_params_select::PASSPHRASE_SHOW_HIDE_BUTTON; - break; - - case Setup_obtain_params_hover::START_BUTTON: - - next_select = Setup_obtain_params_select::START_BUTTON; - break; - - case Setup_obtain_params_hover::PASSPHRASE_INPUT: - - next_select = Setup_obtain_params_select::PASSPHRASE_INPUT; - break; - - case Setup_obtain_params_hover::CLIENT_FS_SIZE_INPUT: - - class Unexpected_hover_1 { }; - throw Unexpected_hover_1 { }; - - case Setup_obtain_params_hover::SNAPSHOT_BUFFER_SIZE_INPUT: - - class Unexpected_hover_2 { }; - throw Unexpected_hover_2 { }; - - case Setup_obtain_params_hover::NONE: - - next_select = Setup_obtain_params_select::NONE; - break; - } - if (next_select != prev_select) { - - _setup_obtain_params_select = next_select; - update_dialog = true; - } - - } else if (key == Input::KEY_ENTER) { - - if (_ui_setup_obtain_params_passphrase_suitable() && - _setup_obtain_params_select != Setup_obtain_params_select::START_BUTTON) { - - _setup_obtain_params_select = Setup_obtain_params_select::START_BUTTON; - update_dialog = true; - } - - } else { - - if (_setup_obtain_params_select == Setup_obtain_params_select::PASSPHRASE_INPUT) { - - if (_setup_obtain_params_passphrase.appendable_character(code)) { - - _setup_obtain_params_passphrase.append_character(code); - update_dialog = true; - - } else if (code.value == CODEPOINT_BACKSPACE) { - - _setup_obtain_params_passphrase.remove_last_character(); - update_dialog = true; - } - } - } - }); - event.handle_release([&] (Input::Keycode key) { - - if (key == Input::BTN_LEFT || - key == Input::KEY_ENTER) { - - switch (_setup_obtain_params_select) { - case Setup_obtain_params_select::PASSPHRASE_SHOW_HIDE_BUTTON: - - if (_setup_obtain_params_passphrase.hide()) { - _setup_obtain_params_passphrase.hide(false); - } else { - _setup_obtain_params_passphrase.hide(true); - } - _setup_obtain_params_select = Setup_obtain_params_select::PASSPHRASE_INPUT; - update_dialog = true; - break; - - case Setup_obtain_params_select::START_BUTTON: - - if (_ui_setup_obtain_params_passphrase_suitable()) { - - _setup_obtain_params_select = Setup_obtain_params_select::NONE; - _set_state(State::UNLOCK_RUN_TRESOR_INIT_TRUST_ANCHOR); - update_sandbox_config = true; - update_dialog = true; - } - break; - - default: - - break; - } - } - }); - break; - - case State::CONTROLS_ROOT: - - event.handle_press([&] (Input::Keycode key, Codepoint) { - - if (key == Input::BTN_LEFT) { - - Controls_root_select const prev_select { _controls_root_select }; - Controls_root_select next_select { Controls_root_select::NONE }; - - switch (_controls_root_hover) { - case Controls_root_hover::SNAPSHOTS_EXPAND_BUTTON: - - _set_state(State::CONTROLS_SNAPSHOTS); - update_dialog = true; - break; - - case Controls_root_hover::DIMENSIONS_BUTTON: - - _set_state(State::CONTROLS_DIMENSIONS); - update_dialog = true; - break; - - case Controls_root_hover::SECURITY_EXPAND_BUTTON: - - _set_state(State::CONTROLS_SECURITY); - update_dialog = true; - break; - - case Controls_root_hover::LOCK_BUTTON: - - next_select = Controls_root_select::LOCK_BUTTON; - break; - - case Controls_root_hover::NONE: - - next_select = Controls_root_select::NONE; - break; - } - if (next_select != prev_select) { - - _controls_root_select = next_select; - update_dialog = true; - } - } - }); - event.handle_release([&] (Input::Keycode key) { - - if (key == Input::BTN_LEFT) { - - switch (_controls_root_select) { - case Controls_root_select::LOCK_BUTTON: - - _controls_root_select = Controls_root_select::NONE; - _set_state(State::LOCK_ISSUE_DEINIT_REQUEST_AT_TRESOR); - - update_sandbox_config = true; - update_dialog = true; - break; - - default: - - break; - } - } - }); - break; - - case State::CONTROLS_SNAPSHOTS: - - event.handle_press([&] (Input::Keycode key, Codepoint) { - - if (key == Input::BTN_LEFT) { - - Controls_snapshots_select const prev_select { _controls_snapshots_select }; - Controls_snapshots_select next_select { Controls_snapshots_select::NONE }; - - switch (_controls_snapshots_hover) { - case Controls_snapshots_hover::LEAVE_BUTTON: - - _set_state(State::CONTROLS_ROOT); - update_dialog = true; - break; - - case Controls_snapshots_hover::LOCK_BUTTON: - - next_select = Controls_snapshots_select::LOCK_BUTTON; - break; - - case Controls_snapshots_hover::CREATE_BUTTON: - - next_select = Controls_snapshots_select::CREATE_BUTTON; - break; - - case Controls_snapshots_hover::GENERATION_DISCARD_BUTTON: - - next_select = Controls_snapshots_select::GENERATION_DISCARD_BUTTON; - break; - - case Controls_snapshots_hover::GENERATION_LEAVE_BUTTON: - - _snapshots_select = Snapshot_pointer { }; - update_dialog = true; - break; - - case Controls_snapshots_hover::NONE: - - next_select = Controls_snapshots_select::NONE; - break; - } - if (_snapshots_hover.valid()) { - - if (_snapshots_hover != _snapshots_select) { - - _snapshots_select = _snapshots_hover; - update_dialog = true; - } else { - - _snapshots_select = Snapshot_pointer { }; - update_dialog = true; - } - } - if (next_select != prev_select) { - - _controls_snapshots_select = next_select; - update_dialog = true; - } - } - }); - event.handle_release([&] (Input::Keycode key) { - - if (key == Input::BTN_LEFT) { - - switch (_controls_snapshots_select) { - case Controls_snapshots_select::LOCK_BUTTON: - - _controls_snapshots_select = Controls_snapshots_select::NONE; - _set_state(State::LOCK_ISSUE_DEINIT_REQUEST_AT_TRESOR); - - update_sandbox_config = true; - update_dialog = true; - break; - - case Controls_snapshots_select::CREATE_BUTTON: - - _controls_snapshots_select = Controls_snapshots_select::NONE; - _create_snap_state = Create_snapshot_state::ISSUE_REQUEST_AT_DEVICE; - - update_sandbox_config = true; - update_dialog = true; - break; - - case Controls_snapshots_select::GENERATION_DISCARD_BUTTON: - - _controls_snapshots_select = Controls_snapshots_select::NONE; - - if (_snapshots_select.valid()) { - _discard_snap_state = Discard_snapshot_state::ISSUE_REQUEST_AT_DEVICE; - _discard_snap_gen = _snapshots_select.object().generation(); - } - update_sandbox_config = true; - update_dialog = true; - break; - - default: - - break; - } - } - }); - break; - - case State::CONTROLS_DIMENSIONS: - - event.handle_press([&] (Input::Keycode key, Codepoint) { - - if (key == Input::BTN_LEFT) { - - Dimensions_select const prev_select { _dimensions_select }; - Dimensions_select next_select { Dimensions_select::NONE }; - - switch (_dimensions_hover) { - case Dimensions_hover::LEAVE_BUTTON: - - _set_state(State::CONTROLS_ROOT); - update_dialog = true; - break; - - case Dimensions_hover::EXPAND_CLIENT_FS_BUTTON: - - _set_state(State::CONTROLS_EXPAND_CLIENT_FS); - _expand_client_fs_select = Expand_client_fs_select::CONTINGENT_INPUT; - update_dialog = true; - break; - - case Dimensions_hover::EXPAND_SNAPSHOT_BUF_BUTTON: - - _set_state(State::CONTROLS_EXPAND_SNAPSHOT_BUF); - _expand_snapshot_buf_select = Expand_snapshot_buf_select::CONTINGENT_INPUT; - update_dialog = true; - break; - - case Dimensions_hover::LOCK_BUTTON: - - next_select = Dimensions_select::LOCK_BUTTON; - break; - - case Dimensions_hover::NONE: - - next_select = Dimensions_select::NONE; - break; - } - if (next_select != prev_select) { - - _dimensions_select = next_select; - update_dialog = true; - } - } - }); - event.handle_release([&] (Input::Keycode key) { - - if (key == Input::BTN_LEFT) { - - switch (_dimensions_select) { - case Dimensions_select::LOCK_BUTTON: - - _dimensions_select = Dimensions_select::NONE; - _set_state(State::LOCK_ISSUE_DEINIT_REQUEST_AT_TRESOR); - - update_sandbox_config = true; - update_dialog = true; - break; - - default: - - break; - } - } - }); - break; - - case State::CONTROLS_EXPAND_CLIENT_FS: - - if (_nr_of_clients > 0) { - - event.handle_press([&] (Input::Keycode key, Codepoint) { - - if (key == Input::BTN_LEFT) { - - Expand_client_fs_select const prev_select { _expand_client_fs_select }; - Expand_client_fs_select next_select { Expand_client_fs_select::NONE }; - - switch (_expand_client_fs_hover) { - case Expand_client_fs_hover::LEAVE_BUTTON: - - _set_state(State::CONTROLS_DIMENSIONS); - update_dialog = true; - break; - - case Expand_client_fs_hover::LOCK_BUTTON: - - next_select = Expand_client_fs_select::LOCK_BUTTON; - break; - - case Expand_client_fs_hover::START_BUTTON: - case Expand_client_fs_hover::CONTINGENT_INPUT: - - break; - - case Expand_client_fs_hover::NONE: - - next_select = Expand_client_fs_select::NONE; - break; - } - if (next_select != prev_select) { - - _expand_client_fs_select = next_select; - update_dialog = true; - } - - } - }); - event.handle_release([&] (Input::Keycode key) { - - if (key == Input::BTN_LEFT || - key == Input::KEY_ENTER) { - - switch (_expand_client_fs_select) { - case Expand_client_fs_select::START_BUTTON: - - break; - - case Expand_client_fs_select::LOCK_BUTTON: - - _expand_client_fs_select = Expand_client_fs_select::NONE; - _set_state(State::LOCK_ISSUE_DEINIT_REQUEST_AT_TRESOR); - - update_sandbox_config = true; - update_dialog = true; - break; - - default: - - break; - } - } - }); - - } else { - - event.handle_press([&] (Input::Keycode key, Codepoint code) { - - if (key == Input::BTN_LEFT) { - - Expand_client_fs_select const prev_select { _expand_client_fs_select }; - Expand_client_fs_select next_select { Expand_client_fs_select::NONE }; - - switch (_expand_client_fs_hover) { - case Expand_client_fs_hover::LEAVE_BUTTON: - - _set_state(State::CONTROLS_DIMENSIONS); - update_dialog = true; - break; - - case Expand_client_fs_hover::LOCK_BUTTON: - - next_select = Expand_client_fs_select::LOCK_BUTTON; - break; - - case Expand_client_fs_hover::START_BUTTON: - - next_select = Expand_client_fs_select::START_BUTTON; - break; - - case Expand_client_fs_hover::CONTINGENT_INPUT: - - next_select = Expand_client_fs_select::CONTINGENT_INPUT; - break; - - case Expand_client_fs_hover::NONE: - - next_select = Expand_client_fs_select::NONE; - break; - } - if (next_select != prev_select) { - - _expand_client_fs_select = next_select; - update_dialog = true; - } - - } else if (key == Input::KEY_ENTER) { - - size_t const bytes { - _expand_client_fs_contingent.value() }; - - size_t const effective_bytes { - bytes - (bytes % TRESOR_BLOCK_SIZE) }; - - if (effective_bytes > 0) { - - _expand_client_fs_select = Expand_client_fs_select::START_BUTTON; - update_dialog = true; - } - } else { - - if (_expand_client_fs_select == Expand_client_fs_select::CONTINGENT_INPUT) { - - if (_expand_client_fs_contingent.appendable_character(code)) { - - _expand_client_fs_contingent.append_character(code); - update_dialog = true; - - } else if (code.value == CODEPOINT_BACKSPACE) { - - _expand_client_fs_contingent.remove_last_character(); - update_dialog = true; - } - } - } - }); - event.handle_release([&] (Input::Keycode key) { - - if (key == Input::BTN_LEFT || - key == Input::KEY_ENTER) { - - switch (_expand_client_fs_select) { - case Expand_client_fs_select::START_BUTTON: - - _expand_client_fs_select = Expand_client_fs_select::NONE; - _resizing_type = Resizing_type::EXPAND_CLIENT_FS; - _resizing_state = Resizing_state::ADAPT_TRESOR_IMAGE_SIZE; - update_sandbox_config = true; - update_dialog = true; - - break; - - case Expand_client_fs_select::LOCK_BUTTON: - - _expand_client_fs_select = Expand_client_fs_select::NONE; - _set_state(State::LOCK_ISSUE_DEINIT_REQUEST_AT_TRESOR); - - update_sandbox_config = true; - update_dialog = true; - break; - - default: - - break; - } - } - }); - } - break; - - case State::CONTROLS_EXPAND_SNAPSHOT_BUF: - - event.handle_press([&] (Input::Keycode key, Codepoint code) { - - if (key == Input::BTN_LEFT) { - - Expand_snapshot_buf_select const prev_select { _expand_snapshot_buf_select }; - Expand_snapshot_buf_select next_select { Expand_snapshot_buf_select::NONE }; - - switch (_expand_snapshot_buf_hover) { - case Expand_snapshot_buf_hover::LEAVE_BUTTON: - - _set_state(State::CONTROLS_DIMENSIONS); - update_dialog = true; - break; - - case Expand_snapshot_buf_hover::LOCK_BUTTON: - - next_select = Expand_snapshot_buf_select::LOCK_BUTTON; - break; - - case Expand_snapshot_buf_hover::START_BUTTON: - - next_select = Expand_snapshot_buf_select::START_BUTTON; - break; - - case Expand_snapshot_buf_hover::CONTINGENT_INPUT: - - next_select = Expand_snapshot_buf_select::CONTINGENT_INPUT; - break; - - case Expand_snapshot_buf_hover::NONE: - - next_select = Expand_snapshot_buf_select::NONE; - break; - } - if (next_select != prev_select) { - - _expand_snapshot_buf_select = next_select; - update_dialog = true; - } - - } else if (key == Input::KEY_ENTER) { - - size_t const bytes { - _expand_snapshot_buf_contingent.value() }; - - size_t const effective_bytes { - bytes - (bytes % TRESOR_BLOCK_SIZE) }; - - if (effective_bytes > 0) { - - _expand_snapshot_buf_select = Expand_snapshot_buf_select::START_BUTTON; - update_dialog = true; - } - } else { - - if (_expand_snapshot_buf_select == Expand_snapshot_buf_select::CONTINGENT_INPUT) { - - if (_expand_snapshot_buf_contingent.appendable_character(code)) { - - _expand_snapshot_buf_contingent.append_character(code); - update_dialog = true; - - } else if (code.value == CODEPOINT_BACKSPACE) { - - _expand_snapshot_buf_contingent.remove_last_character(); - update_dialog = true; - } - } - } - }); - event.handle_release([&] (Input::Keycode key) { - - if (key == Input::BTN_LEFT || - key == Input::KEY_ENTER) { - - switch (_expand_snapshot_buf_select) { - case Expand_snapshot_buf_select::START_BUTTON: - - _expand_snapshot_buf_select = Expand_snapshot_buf_select::NONE; - _resizing_type = Resizing_type::EXPAND_SNAPSHOT_BUF; - _resizing_state = Resizing_state::ADAPT_TRESOR_IMAGE_SIZE; - - update_sandbox_config = true; - update_dialog = true; - break; - - case Expand_snapshot_buf_select::LOCK_BUTTON: - - _expand_snapshot_buf_select = Expand_snapshot_buf_select::NONE; - _set_state(State::LOCK_ISSUE_DEINIT_REQUEST_AT_TRESOR); - - update_sandbox_config = true; - update_dialog = true; - break; - - default: - - break; - } - } - }); - break; - - case State::CONTROLS_SECURITY: - - event.handle_press([&] (Input::Keycode key, Codepoint) { - - if (key == Input::BTN_LEFT) { - - Controls_security_select const prev_select { _controls_security_select }; - Controls_security_select next_select { Controls_security_select::NONE }; - - switch (_controls_security_hover) { - case Controls_security_hover::SECURITY_EXPAND_BUTTON: - - _set_state(State::CONTROLS_ROOT); - update_dialog = true; - break; - - case Controls_security_hover::BLOCK_ENCRYPTION_KEY_EXPAND_BUTTON: - - _set_state(State::CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY); - update_dialog = true; - break; - - case Controls_security_hover::MASTER_KEY_EXPAND_BUTTON: - - _set_state(State::CONTROLS_SECURITY_MASTER_KEY); - update_dialog = true; - break; - - case Controls_security_hover::USER_PASSPHRASE_EXPAND_BUTTON: - - _set_state(State::CONTROLS_SECURITY_USER_PASSPHRASE); - update_dialog = true; - break; - - case Controls_security_hover::LOCK_BUTTON: - - next_select = Controls_security_select::LOCK_BUTTON; - break; - - case Controls_security_hover::NONE: - - next_select = Controls_security_select::NONE; - break; - } - if (next_select != prev_select) { - - _controls_security_select = next_select; - update_dialog = true; - } - } - }); - event.handle_release([&] (Input::Keycode key) { - - if (key == Input::BTN_LEFT) { - - switch (_controls_security_select) { - case Controls_security_select::LOCK_BUTTON: - - _controls_security_select = Controls_security_select::NONE; - _set_state(State::LOCK_ISSUE_DEINIT_REQUEST_AT_TRESOR); - - update_sandbox_config = true; - update_dialog = true; - break; - - default: - - break; - } - } - }); - break; - - case State::CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY: - - event.handle_press([&] (Input::Keycode key, Codepoint) { - - if (key == Input::BTN_LEFT) { - - Controls_security_block_encryption_key_select const prev_select { _controls_security_block_encryption_key_select }; - Controls_security_block_encryption_key_select next_select { Controls_security_block_encryption_key_select::NONE }; - - switch (_controls_security_block_encryption_key_hover) { - case Controls_security_block_encryption_key_hover::LEAVE_BUTTON: - - _set_state(State::CONTROLS_SECURITY); - update_dialog = true; - break; - - case Controls_security_block_encryption_key_hover::REPLACE_BUTTON: - - next_select = Controls_security_block_encryption_key_select::REPLACE_BUTTON; - break; - - case Controls_security_block_encryption_key_hover::LOCK_BUTTON: - - next_select = Controls_security_block_encryption_key_select::LOCK_BUTTON; - break; - - case Controls_security_block_encryption_key_hover::NONE: - - next_select = Controls_security_block_encryption_key_select::NONE; - break; - } - if (next_select != prev_select) { - - _controls_security_block_encryption_key_select = next_select; - update_dialog = true; - } - } - }); - event.handle_release([&] (Input::Keycode key) { - - if (key == Input::BTN_LEFT) { - - switch (_controls_security_block_encryption_key_select) { - case Controls_security_block_encryption_key_select::REPLACE_BUTTON: - - _controls_security_block_encryption_key_select = Controls_security_block_encryption_key_select::NONE; - _rekeying_state = Rekeying_state::WAIT_TILL_DEVICE_IS_READY; - - update_sandbox_config = true; - update_dialog = true; - break; - - case Controls_security_block_encryption_key_select::LOCK_BUTTON: - - _controls_security_block_encryption_key_select = Controls_security_block_encryption_key_select::NONE; - _set_state(State::LOCK_ISSUE_DEINIT_REQUEST_AT_TRESOR); - - update_sandbox_config = true; - update_dialog = true; - break; - - default: - - break; - } - } - }); - break; - - case State::CONTROLS_SECURITY_MASTER_KEY: - - event.handle_press([&] (Input::Keycode key, Codepoint) { - - if (key == Input::BTN_LEFT) { - - Controls_security_master_key_select const prev_select { _controls_security_master_key_select }; - Controls_security_master_key_select next_select { Controls_security_master_key_select::NONE }; - - switch (_controls_security_master_key_hover) { - case Controls_security_master_key_hover::LEAVE_BUTTON: - - _set_state(State::CONTROLS_SECURITY); - update_dialog = true; - break; - - case Controls_security_master_key_hover::LOCK_BUTTON: - - next_select = Controls_security_master_key_select::LOCK_BUTTON; - break; - - case Controls_security_master_key_hover::NONE: - - next_select = Controls_security_master_key_select::NONE; - break; - } - if (next_select != prev_select) { - - _controls_security_master_key_select = next_select; - update_dialog = true; - } - } - }); - event.handle_release([&] (Input::Keycode key) { - - if (key == Input::BTN_LEFT) { - - switch (_controls_security_master_key_select) { - case Controls_security_master_key_select::LOCK_BUTTON: - - _controls_security_master_key_select = Controls_security_master_key_select::NONE; - _set_state(State::LOCK_ISSUE_DEINIT_REQUEST_AT_TRESOR); - - update_sandbox_config = true; - update_dialog = true; - break; - - default: - - break; - } - } - }); - break; - - case State::CONTROLS_SECURITY_USER_PASSPHRASE: - - event.handle_press([&] (Input::Keycode key, Codepoint) { - - if (key == Input::BTN_LEFT) { - - Controls_security_user_passphrase_select const prev_select { _controls_security_user_passphrase_select }; - Controls_security_user_passphrase_select next_select { Controls_security_user_passphrase_select::NONE }; - - switch (_controls_security_user_passphrase_hover) { - case Controls_security_user_passphrase_hover::LEAVE_BUTTON: - - _set_state(State::CONTROLS_SECURITY); - update_dialog = true; - break; - - case Controls_security_user_passphrase_hover::LOCK_BUTTON: - - next_select = Controls_security_user_passphrase_select::LOCK_BUTTON; - break; - - case Controls_security_user_passphrase_hover::NONE: - - next_select = Controls_security_user_passphrase_select::NONE; - break; - } - if (next_select != prev_select) { - - _controls_security_user_passphrase_select = next_select; - update_dialog = true; - } - } - }); - event.handle_release([&] (Input::Keycode key) { - - if (key == Input::BTN_LEFT) { - - switch (_controls_security_user_passphrase_select) { - case Controls_security_user_passphrase_select::LOCK_BUTTON: - - _controls_security_user_passphrase_select = Controls_security_user_passphrase_select::NONE; - _set_state(State::LOCK_ISSUE_DEINIT_REQUEST_AT_TRESOR); - - update_sandbox_config = true; - update_dialog = true; - break; - - default: - - break; - } - } - }); - break; - - default: - - break; - } - if (update_sandbox_config) { - _update_sandbox_config(); - } - if (update_dialog) { - _dialog.trigger_update(); - } -} - - -void File_vault::Main::_handle_hover(Xml_node const &node) -{ - bool update_dialog { false }; - - switch (_state) { - case State::SETUP_OBTAIN_PARAMETERS: - { - Setup_obtain_params_hover const prev_hover { _setup_obtain_params_hover }; - Setup_obtain_params_hover next_hover { Setup_obtain_params_hover::NONE }; - - node.with_optional_sub_node("dialog", [&] (Xml_node const &node_0) { - node_0.with_optional_sub_node("frame", [&] (Xml_node const &node_1) { - node_1.with_optional_sub_node("vbox", [&] (Xml_node const &node_2) { - - node_2.with_optional_sub_node("float", [&] (Xml_node const &node_3) { - if (_has_name(node_3, "ok")) { - next_hover = Setup_obtain_params_hover::START_BUTTON; - } - }); - node_2.with_optional_sub_node("hbox", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("frame", [&] (Xml_node const &node_4) { - - if (_has_name(node_4, "Passphrase")) { - next_hover = Setup_obtain_params_hover::PASSPHRASE_INPUT; - } - }); - node_3.with_optional_sub_node("float", [&] (Xml_node const &node_4) { - node_4.with_optional_sub_node("button", [&] (Xml_node const &node_5) { - - if (_has_name(node_5, "Show Hide")) { - next_hover = Setup_obtain_params_hover::PASSPHRASE_SHOW_HIDE_BUTTON; - } - }); - }); - }); - node_2.with_optional_sub_node("frame", [&] (Xml_node const &node_3) { - - if (_has_name(node_3, "Client FS Size")) { - next_hover = Setup_obtain_params_hover::CLIENT_FS_SIZE_INPUT; - - } if (_has_name(node_3, "Snapshot Buffer Size")) { - next_hover = Setup_obtain_params_hover::SNAPSHOT_BUFFER_SIZE_INPUT; - } - }); - }); - }); - }); - if (next_hover != prev_hover) { - - _setup_obtain_params_hover = next_hover; - update_dialog = true; - } - break; - } - case State::UNLOCK_OBTAIN_PARAMETERS: - { - Setup_obtain_params_hover const prev_hover { _setup_obtain_params_hover }; - Setup_obtain_params_hover next_hover { Setup_obtain_params_hover::NONE }; - - node.with_optional_sub_node("dialog", [&] (Xml_node const &node_0) { - node_0.with_optional_sub_node("frame", [&] (Xml_node const &node_1) { - node_1.with_optional_sub_node("vbox", [&] (Xml_node const &node_2) { - - node_2.with_optional_sub_node("float", [&] (Xml_node const &node_3) { - if (_has_name(node_3, "ok")) { - next_hover = Setup_obtain_params_hover::START_BUTTON; - } - }); - node_2.with_optional_sub_node("hbox", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("frame", [&] (Xml_node const &node_4) { - - if (_has_name(node_4, "Passphrase")) { - next_hover = Setup_obtain_params_hover::PASSPHRASE_INPUT; - } - }); - node_3.with_optional_sub_node("float", [&] (Xml_node const &node_4) { - node_4.with_optional_sub_node("button", [&] (Xml_node const &node_5) { - - if (_has_name(node_5, "Show Hide")) { - next_hover = Setup_obtain_params_hover::PASSPHRASE_SHOW_HIDE_BUTTON; - } - }); - }); - }); - }); - }); - }); - if (next_hover != prev_hover) { - - _setup_obtain_params_hover = next_hover; - update_dialog = true; - } - break; - } - case State::CONTROLS_ROOT: - { - Controls_root_hover const prev_hover { _controls_root_hover }; - Controls_root_hover next_hover { Controls_root_hover::NONE }; - - node.with_optional_sub_node("dialog", [&] (Xml_node const &node_0) { - node_0.with_optional_sub_node("frame", [&] (Xml_node const &node_1) { - node_1.with_optional_sub_node("vbox", [&] (Xml_node const &node_2) { - node_2.with_optional_sub_node("hbox", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("button", [&] (Xml_node const &node_4) { - - if (_has_name(node_4, "Lock")) { - - next_hover = Controls_root_hover::LOCK_BUTTON; - - } - }); - }); - node_2.with_optional_sub_node("frame", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("vbox", [&] (Xml_node const &node_4) { - node_4.with_optional_sub_node("vbox", [&] (Xml_node const &node_5) { - - if (_has_name(node_5, "Snapshots")) { - - next_hover = Controls_root_hover::SNAPSHOTS_EXPAND_BUTTON; - - } else if (_has_name(node_5, "Dimensions")) { - - next_hover = Controls_root_hover::DIMENSIONS_BUTTON; - - } else if (_has_name(node_5, "Security")) { - - next_hover = Controls_root_hover::SECURITY_EXPAND_BUTTON; - } - }); - }); - }); - }); - }); - }); - if (next_hover != prev_hover) { - - _controls_root_hover = next_hover; - update_dialog = true; - } - break; - } - case State::CONTROLS_SNAPSHOTS: - { - Controls_snapshots_hover const prev_hover { _controls_snapshots_hover }; - Controls_snapshots_hover next_hover { Controls_snapshots_hover::NONE }; - - Snapshot_pointer const prev_snapshots_hover { _snapshots_hover }; - Snapshot_pointer next_snapshots_hover { }; - - node.with_optional_sub_node("dialog", [&] (Xml_node const &node_0) { - node_0.with_optional_sub_node("frame", [&] (Xml_node const &node_1) { - node_1.with_optional_sub_node("vbox", [&] (Xml_node const &node_2) { - node_2.with_optional_sub_node("hbox", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("button", [&] (Xml_node const &node_4) { - - if (_has_name(node_4, "Lock")) { - - next_hover = Controls_snapshots_hover::LOCK_BUTTON; - } - }); - }); - node_2.with_optional_sub_node("frame", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("vbox", [&] (Xml_node const &node_4) { - node_4.with_optional_sub_node("vbox", [&] (Xml_node const &node_5) { - - if (_snapshots_select.valid()) { - - node_5.with_optional_sub_node("hbox", [&] (Xml_node const &node_6) { - - if (_has_name(node_6, "Leave")) { - - next_hover = Controls_snapshots_hover::GENERATION_LEAVE_BUTTON; - } - }); - node_5.with_optional_sub_node("button", [&] (Xml_node const &node_6) { - - if (_has_name(node_6, "Discard")) { - - next_hover = Controls_snapshots_hover::GENERATION_DISCARD_BUTTON; - } - }); - - } else { - - node_5.with_optional_sub_node("hbox", [&] (Xml_node const &node_6) { - - if (_has_name(node_6, "Leave")) { - - next_hover = Controls_snapshots_hover::LEAVE_BUTTON; - } - }); - node_5.with_optional_sub_node("vbox", [&] (Xml_node const &node_6) { - - if (_has_name(node_6, "Generations")) { - - node_6.with_optional_sub_node("float", [&] (Xml_node const &node_7) { - - Generation const generation { - node_7.attribute_value( - "name", Generation { INVALID_GENERATION }) }; - - if (generation != INVALID_GENERATION) { - - _snapshots.for_each([&] (Snapshot const &snap) - { - if (generation == snap.generation()) { - next_snapshots_hover = snap; - } - }); - } - }); - } - }); - node_5.with_optional_sub_node("button", [&] (Xml_node const &node_6) { - - if (_has_name(node_6, "Create")) { - - next_hover = Controls_snapshots_hover::CREATE_BUTTON; - } - }); - } - }); - }); - }); - }); - }); - }); - if (next_snapshots_hover != prev_snapshots_hover) { - - _snapshots_hover = next_snapshots_hover; - update_dialog = true; - } - if (next_hover != prev_hover) { - - _controls_snapshots_hover = next_hover; - update_dialog = true; - } - break; - } - case State::CONTROLS_DIMENSIONS: - { - Dimensions_hover const prev_hover { _dimensions_hover }; - Dimensions_hover next_hover { Dimensions_hover::NONE }; - - node.with_optional_sub_node("dialog", [&] (Xml_node const &node_0) { - node_0.with_optional_sub_node("frame", [&] (Xml_node const &node_1) { - node_1.with_optional_sub_node("vbox", [&] (Xml_node const &node_2) { - node_2.with_optional_sub_node("hbox", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("button", [&] (Xml_node const &node_4) { - - if (_has_name(node_4, "Lock")) { - - next_hover = Dimensions_hover::LOCK_BUTTON; - } - }); - }); - node_2.with_optional_sub_node("frame", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("vbox", [&] (Xml_node const &node_4) { - node_4.with_optional_sub_node("hbox", [&] (Xml_node const &node_5) { - - if (_has_name(node_5, "Leave")) { - - next_hover = Dimensions_hover::LEAVE_BUTTON; - } - }); - node_4.with_optional_sub_node("vbox", [&] (Xml_node const &node_5) { - - if (_has_name(node_5, "Expand Client FS")) { - - next_hover = Dimensions_hover::EXPAND_CLIENT_FS_BUTTON; - - } else if (_has_name(node_5, - RENAME_SNAPSHOT_BUFFER_JOURNALING_BUFFER ? - "Expand Journaling Buffer" : - "Expand Snapshot Buffer")) { - - next_hover = Dimensions_hover::EXPAND_SNAPSHOT_BUF_BUTTON; - } - }); - }); - }); - }); - }); - }); - if (next_hover != prev_hover) { - - _dimensions_hover = next_hover; - update_dialog = true; - } - break; - } - case State::CONTROLS_EXPAND_CLIENT_FS: - { - Expand_client_fs_hover const prev_hover { _expand_client_fs_hover }; - Expand_client_fs_hover next_hover { Expand_client_fs_hover::NONE }; - - node.with_optional_sub_node("dialog", [&] (Xml_node const &node_0) { - node_0.with_optional_sub_node("frame", [&] (Xml_node const &node_1) { - node_1.with_optional_sub_node("vbox", [&] (Xml_node const &node_2) { - node_2.with_optional_sub_node("hbox", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("button", [&] (Xml_node const &node_4) { - - if (_has_name(node_4, "Lock")) { - - next_hover = Expand_client_fs_hover::LOCK_BUTTON; - - } - }); - }); - node_2.with_optional_sub_node("frame", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("vbox", [&] (Xml_node const &node_4) { - node_4.with_optional_sub_node("vbox", [&] (Xml_node const &node_5) { - node_5.with_optional_sub_node("hbox", [&] (Xml_node const &node_6) { - - if (_has_name(node_6, "Leave")) { - - next_hover = Expand_client_fs_hover::LEAVE_BUTTON; - } - }); - node_5.with_optional_sub_node("float", [&] (Xml_node const &node_6) { - - if (_has_name(node_6, "Start")) { - - next_hover = Expand_client_fs_hover::START_BUTTON; - } - }); - node_5.with_optional_sub_node("frame", [&] (Xml_node const &node_6) { - - if (_has_name(node_6, "Contingent")) { - - next_hover = Expand_client_fs_hover::CONTINGENT_INPUT; - } - }); - }); - }); - }); - }); - }); - }); - if (next_hover != prev_hover) { - - _expand_client_fs_hover = next_hover; - update_dialog = true; - } - break; - } - case State::CONTROLS_EXPAND_SNAPSHOT_BUF: - { - Expand_snapshot_buf_hover const prev_hover { _expand_snapshot_buf_hover }; - Expand_snapshot_buf_hover next_hover { Expand_snapshot_buf_hover::NONE }; - - node.with_optional_sub_node("dialog", [&] (Xml_node const &node_0) { - node_0.with_optional_sub_node("frame", [&] (Xml_node const &node_1) { - node_1.with_optional_sub_node("vbox", [&] (Xml_node const &node_2) { - node_2.with_optional_sub_node("hbox", [&] (Xml_node const &node_3) { - - node_3.with_optional_sub_node("button", [&] (Xml_node const &node_4) { - - if (_has_name(node_4, "Lock")) { - - next_hover = Expand_snapshot_buf_hover::LOCK_BUTTON; - - } - }); - }); - node_2.with_optional_sub_node("frame", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("vbox", [&] (Xml_node const &node_4) { - node_4.with_optional_sub_node("vbox", [&] (Xml_node const &node_5) { - - node_5.with_optional_sub_node("hbox", [&] (Xml_node const &node_6) { - - if (_has_name(node_6, "Leave")) { - - next_hover = Expand_snapshot_buf_hover::LEAVE_BUTTON; - } - }); - node_5.with_optional_sub_node("float", [&] (Xml_node const &node_6) { - - if (_has_name(node_6, "Start")) { - - next_hover = Expand_snapshot_buf_hover::START_BUTTON; - } - }); - node_5.with_optional_sub_node("frame", [&] (Xml_node const &node_6) { - - if (_has_name(node_6, "Contingent")) { - - next_hover = Expand_snapshot_buf_hover::CONTINGENT_INPUT; - } - }); - }); - }); - }); - }); - }); - }); - if (next_hover != prev_hover) { - - _expand_snapshot_buf_hover = next_hover; - update_dialog = true; - } - break; - } - case State::CONTROLS_SECURITY: - { - Controls_security_hover const prev_hover { _controls_security_hover }; - Controls_security_hover next_hover { Controls_security_hover::NONE }; - - node.with_optional_sub_node("dialog", [&] (Xml_node const &node_0) { - node_0.with_optional_sub_node("frame", [&] (Xml_node const &node_1) { - node_1.with_optional_sub_node("vbox", [&] (Xml_node const &node_2) { - node_2.with_optional_sub_node("hbox", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("button", [&] (Xml_node const &node_4) { - - if (_has_name(node_4, "Lock")) { - - next_hover = Controls_security_hover::LOCK_BUTTON; - - } - }); - }); - node_2.with_optional_sub_node("frame", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("vbox", [&] (Xml_node const &node_4) { - node_4.with_optional_sub_node("hbox", [&] (Xml_node const &node_5) { - - if (_has_name(node_5, "Leave")) { - - next_hover = Controls_security_hover::SECURITY_EXPAND_BUTTON; - } - }); - node_4.with_optional_sub_node("vbox", [&] (Xml_node const &node_5) { - - if (_has_name(node_5, "Block Encryption Key")) { - - next_hover = Controls_security_hover::BLOCK_ENCRYPTION_KEY_EXPAND_BUTTON; - - } else if (_has_name(node_5, "Master Key")) { - - next_hover = Controls_security_hover::MASTER_KEY_EXPAND_BUTTON; - - } else if (_has_name(node_5, "User Passphrase")) { - - next_hover = Controls_security_hover::USER_PASSPHRASE_EXPAND_BUTTON; - } - }); - }); - }); - }); - }); - }); - if (next_hover != prev_hover) { - - _controls_security_hover = next_hover; - update_dialog = true; - } - break; - } - case State::CONTROLS_SECURITY_BLOCK_ENCRYPTION_KEY: - { - Controls_security_block_encryption_key_hover const prev_hover { _controls_security_block_encryption_key_hover }; - Controls_security_block_encryption_key_hover next_hover { Controls_security_block_encryption_key_hover::NONE }; - - node.with_optional_sub_node("dialog", [&] (Xml_node const &node_0) { - node_0.with_optional_sub_node("frame", [&] (Xml_node const &node_1) { - node_1.with_optional_sub_node("vbox", [&] (Xml_node const &node_2) { - node_2.with_optional_sub_node("hbox", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("button", [&] (Xml_node const &node_4) { - - if (_has_name(node_4, "Lock")) { - - next_hover = Controls_security_block_encryption_key_hover::LOCK_BUTTON; - - } - }); - }); - node_2.with_optional_sub_node("frame", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("vbox", [&] (Xml_node const &node_4) { - node_4.with_optional_sub_node("button", [&] (Xml_node const &node_5) { - - if (_has_name(node_5, "Rekey")) { - - next_hover = Controls_security_block_encryption_key_hover::REPLACE_BUTTON; - } - }); - node_4.with_optional_sub_node("hbox", [&] (Xml_node const &node_5) { - - if (_has_name(node_5, "Leave")) { - - next_hover = Controls_security_block_encryption_key_hover::LEAVE_BUTTON; - } - }); - }); - }); - }); - }); - }); - if (next_hover != prev_hover) { - - _controls_security_block_encryption_key_hover = next_hover; - update_dialog = true; - } - break; - } - case State::CONTROLS_SECURITY_MASTER_KEY: - { - Controls_security_master_key_hover const prev_hover { _controls_security_master_key_hover }; - Controls_security_master_key_hover next_hover { Controls_security_master_key_hover::NONE }; - - node.with_optional_sub_node("dialog", [&] (Xml_node const &node_0) { - node_0.with_optional_sub_node("frame", [&] (Xml_node const &node_1) { - node_1.with_optional_sub_node("vbox", [&] (Xml_node const &node_2) { - node_2.with_optional_sub_node("hbox", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("button", [&] (Xml_node const &node_4) { - - if (_has_name(node_4, "Lock")) { - - next_hover = Controls_security_master_key_hover::LOCK_BUTTON; - - } - }); - }); - node_2.with_optional_sub_node("frame", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("vbox", [&] (Xml_node const &node_4) { - node_4.with_optional_sub_node("hbox", [&] (Xml_node const &node_5) { - - if (_has_name(node_5, "Leave")) { - - next_hover = Controls_security_master_key_hover::LEAVE_BUTTON; - } - }); - }); - }); - }); - }); - }); - if (next_hover != prev_hover) { - - _controls_security_master_key_hover = next_hover; - update_dialog = true; - } - break; - } - case State::CONTROLS_SECURITY_USER_PASSPHRASE: - { - Controls_security_user_passphrase_hover const prev_hover { _controls_security_user_passphrase_hover }; - Controls_security_user_passphrase_hover next_hover { Controls_security_user_passphrase_hover::NONE }; - - node.with_optional_sub_node("dialog", [&] (Xml_node const &node_0) { - node_0.with_optional_sub_node("frame", [&] (Xml_node const &node_1) { - node_1.with_optional_sub_node("vbox", [&] (Xml_node const &node_2) { - node_2.with_optional_sub_node("hbox", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("button", [&] (Xml_node const &node_4) { - - if (_has_name(node_4, "Lock")) { - - next_hover = Controls_security_user_passphrase_hover::LOCK_BUTTON; - - } - }); - }); - node_2.with_optional_sub_node("frame", [&] (Xml_node const &node_3) { - node_3.with_optional_sub_node("vbox", [&] (Xml_node const &node_4) { - node_4.with_optional_sub_node("hbox", [&] (Xml_node const &node_5) { - - if (_has_name(node_5, "Leave")) { - - next_hover = Controls_security_user_passphrase_hover::LEAVE_BUTTON; - } - }); - }); - }); - }); - }); - }); - if (next_hover != prev_hover) { - - _controls_security_user_passphrase_hover = next_hover; - update_dialog = true; - } - break; - } - default: - - break; - } - if (update_dialog) { - _dialog.trigger_update(); - } -} - - -/*********************** - ** Genode::Component ** - ***********************/ - -void Component::construct(Genode::Env &env) -{ - static File_vault::Main main { env }; -} +void Component::construct(Genode::Env &env) { static File_vault::Main main { env }; } diff --git a/repos/gems/src/app/file_vault/menu_view_dialog.cc b/repos/gems/src/app/file_vault/menu_view_dialog.cc deleted file mode 100644 index 73607c04c6..0000000000 --- a/repos/gems/src/app/file_vault/menu_view_dialog.cc +++ /dev/null @@ -1,404 +0,0 @@ -/* - * \brief Local utilities for the menu view dialog - * \author Martin Stein - * \date 2021-02-24 - */ - -/* - * Copyright (C) 2021 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -/* local includes */ -#include -#include - -using namespace File_vault; - - -void File_vault::gen_normal_font_attribute(Xml_generator &xml) -{ - xml.attribute("font", "text/regular"); -} - - -void File_vault::gen_frame_title(Xml_generator &xml, - char const *name, - unsigned long min_width, - bool jent_avail) -{ - - xml.node("float", [&] () { - xml.attribute("name", name); - xml.attribute("west", "yes"); - xml.attribute("north", "yes"); - - if (jent_avail) { - xml.node("label", [&] () { - xml.attribute("text", "" ); - xml.attribute("min_ex", min_width); - }); - } else { - xml.node("vbox", [&] () { - xml.node("label", [&] () { - xml.attribute("name", "warning_0"); - xml.attribute("font", "title/regular"); - xml.attribute("text", " Warning: Insecure mode, no entropy source! " ); - xml.attribute("min_ex", min_width); - }); - xml.node("label", [&] () { - xml.attribute("name", "warning_1"); - xml.attribute("text", " " ); - }); - }); - } - }); -} - -void File_vault::gen_info_frame(Xml_generator &xml, - bool jent_avail, - char const *name, - char const *info, - unsigned long min_width) -{ - gen_main_frame(xml, jent_avail, name, min_width, [&] (Xml_generator &xml) { - - gen_centered_info_line(xml, "info", info); - gen_info_line(xml, "pad_1", ""); - }); -} - -void File_vault::gen_action_button_at_bottom(Xml_generator &xml, - char const *name, - char const *label, - bool hovered, - bool selected) -{ - xml.node("float", [&] () { - xml.attribute("name", name); - xml.attribute("east", "yes"); - xml.attribute("west", "yes"); - xml.attribute("south", "yes"); - - xml.node("button", [&] () { - - if (hovered) { - xml.attribute("hovered", "yes"); - } - if (selected) { - xml.attribute("selected", "yes"); - } - - xml.node("float", [&] () { - - xml.node("label", [&] () { - gen_normal_font_attribute(xml); - xml.attribute("text", label); - }); - }); - }); - }); -} - -void File_vault::gen_action_button_at_bottom(Xml_generator &xml, - char const *label, - bool hovered, - bool selected) -{ - gen_action_button_at_bottom(xml, label, label, hovered, selected); -} - -void File_vault::gen_action_button(Xml_generator &xml, - char const *name, - char const *label, - bool hovered, - bool selected, - size_t min_ex) -{ - xml.node("button", [&] () { - xml.attribute("name", name); - - if (hovered) { - xml.attribute("hovered", "yes"); - } - if (selected) { - xml.attribute("selected", "yes"); - } - xml.node("label", [&] () { - - if (min_ex != 0) { - xml.attribute("min_ex", min_ex); - } - xml.attribute("text", label); - }); - }); -} - -void File_vault::gen_text_input(Xml_generator &xml, - char const *name, - String<256> const &text, - bool selected) -{ - String<256> const padded_text { " ", text }; - - xml.node("frame", [&] () { - xml.attribute("name", name); - xml.node("float", [&] () { - xml.attribute("west", "yes"); - xml.node("label", [&] () { - gen_normal_font_attribute(xml); - xml.attribute("text", padded_text); - - if (selected) { - xml.node("cursor", [&] () { - xml.attribute("at", padded_text.length() - 1 ); - }); - } - }); - }); - }); -} - -void -File_vault:: -gen_input_passphrase(Xml_generator &xml, - size_t max_width, - Input_passphrase const &passphrase, - bool input_selected, - bool show_hide_button_hovered, - bool show_hide_button_selected) -{ - char const *show_hide_button_label; - size_t cursor_at; - if (passphrase.hide()) { - - show_hide_button_label = "Show"; - cursor_at = passphrase.length() + 1; - - } else { - - show_hide_button_label = "Hide"; - cursor_at = passphrase.length() + 1; - } - xml.node("float", [&] () { - xml.attribute("name", "Passphrase Label"); - xml.attribute("west", "yes"); - - xml.node("label", [&] () { - gen_normal_font_attribute(xml); - xml.attribute("text", " Passphrase: "); - }); - }); - xml.node("hbox", [&] () { - - String<256> const padded_text { " ", passphrase, " " }; - xml.node("frame", [&] () { - xml.attribute("name", "Passphrase"); - xml.node("float", [&] () { - xml.attribute("west", "yes"); - xml.node("label", [&] () { - xml.attribute("min_ex", max_width - 11); - gen_normal_font_attribute(xml); - xml.attribute("text", padded_text); - - - if (input_selected) { - xml.node("cursor", [&] () { - xml.attribute("at", cursor_at ); - }); - } - }); - }); - }); - xml.node("float", [&] () { - xml.attribute("name", "1"); - xml.attribute("east", "yes"); - - gen_action_button( - xml, "Show Hide", show_hide_button_label, - show_hide_button_hovered, show_hide_button_selected, 5); - }); - }); -} - -void File_vault::gen_titled_text_input(Xml_generator &xml, - char const *name, - char const *title, - String<256> const &text, - bool selected) -{ - xml.node("float", [&] () { - xml.attribute("name", String<64> { name, "_label" }); - xml.attribute("west", "yes"); - - xml.node("label", [&] () { - gen_normal_font_attribute(xml); - xml.attribute("text", String<64> { " ", title, ": " }); - }); - }); - gen_text_input(xml, name, text, selected); -} - -void File_vault::gen_empty_line(Xml_generator &xml, - char const *name, - size_t min_width) -{ - xml.node("label", [&] () { - xml.attribute("name", name); - xml.attribute("min_ex", min_width); - xml.attribute("text", ""); - }); -} - -void File_vault::gen_info_line(Xml_generator &xml, - char const *name, - char const *text) -{ - xml.node("float", [&] () { - xml.attribute("name", name); - xml.attribute("west", "yes"); - xml.node("label", [&] () { - gen_normal_font_attribute(xml); - xml.attribute("text", String<256> { " ", text, " "}); - }); - }); -} - -void File_vault::gen_centered_info_line(Xml_generator &xml, - char const *name, - char const *text) -{ - xml.node("float", [&] () { - xml.attribute("name", name); - xml.node("label", [&] () { - gen_normal_font_attribute(xml); - xml.attribute("text", String<256> { " ", text, " "}); - }); - }); -} - -void File_vault::gen_multiple_choice_entry(Xml_generator &xml, - char const *name, - char const *text, - bool hovered, - bool selected) -{ - xml.node("float", [&] () { - xml.attribute("name", name); - xml.attribute("west", "yes"); - - xml.node("hbox", [&] () { - - xml.node("button", [&] () { - if (selected) { - xml.attribute("selected", "yes"); - } - if (hovered) { - xml.attribute("hovered", "yes"); - } - xml.attribute("style", "radio"); - - xml.node("hbox", [&] () { }); - }); - xml.node("label", [&] () { - gen_normal_font_attribute(xml); - xml.attribute("text", String<64> { " ", text }); - }); - }); - }); -} - -void File_vault::gen_menu_title(Xml_generator &xml, - char const *name, - char const *label, - char const *label_annex, - bool hovered, - bool selected) -{ - xml.node("hbox", [&] () { - xml.attribute("name", name); - - xml.node("float", [&] () { - xml.attribute("name", "0"); - xml.attribute("west", "yes"); - - xml.node("hbox", [&] () { - - xml.node("button", [&] () { - if (selected) { - xml.attribute("style", "back"); - xml.attribute("selected", "yes"); - } else { - xml.attribute("style", "radio"); - } - if (hovered) { - xml.attribute("hovered", "yes"); - } - xml.attribute("hovered", "no"); - - xml.node("hbox", [&] () { }); - }); - xml.node("label", [&] () { - if (selected) { - xml.attribute("font", "title/regular"); - } - xml.attribute("text", String<64> { " ", label }); - }); - }); - }); - xml.node("float", [&] () { - xml.attribute("name", "2"); - xml.attribute("east", "yes"); - - xml.node("label", [&] () { - xml.attribute("font", "title/regular"); - xml.attribute( - "text", label_annex); - }); - }); - }); -} - - -void File_vault::gen_closed_menu(Xml_generator &xml, - char const *label, - char const *label_annex, - bool hovered) -{ - xml.node("vbox", [&] () { - xml.attribute("name", label); - - gen_menu_title(xml, "Enter", label, label_annex, hovered, false); - }); -} - - -void File_vault::gen_global_controls(Xml_generator &xml, - size_t min_width, - size_t tresor_image_size, - size_t client_fs_size, - size_t nr_of_clients, - bool lock_button_hovered, - bool lock_button_selected) -{ - gen_empty_line(xml, "Status 0", min_width); - gen_centered_info_line(xml, "Status 1", - String<256> { - " Image: ", - Capacity_string { tresor_image_size }, - ", Client FS: ", - Capacity_string { client_fs_size }, - ", Clients: ", - nr_of_clients - }.string() - ); - - gen_empty_line(xml, "Status 3", 0); - - xml.node("hbox", [&] () { - gen_action_button( - xml, "Lock", "Lock", lock_button_hovered, lock_button_selected); - }); -} diff --git a/repos/gems/src/app/file_vault/menu_view_dialog.h b/repos/gems/src/app/file_vault/menu_view_dialog.h deleted file mode 100644 index 9856f9d647..0000000000 --- a/repos/gems/src/app/file_vault/menu_view_dialog.h +++ /dev/null @@ -1,188 +0,0 @@ -/* - * \brief Local utilities for the menu view dialog - * \author Martin Stein - * \date 2021-02-24 - */ - -/* - * Copyright (C) 2021 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -#ifndef _MENU_VIEW_DIALOG_H_ -#define _MENU_VIEW_DIALOG_H_ - -/* Genode includes */ -#include - -/* local includes */ -#include -#include - -namespace File_vault { - - void gen_normal_font_attribute(Xml_generator &xml); - - void gen_frame_title(Xml_generator &xml, - char const *name, - unsigned long min_width, - bool jent_avail); - - template - void gen_main_frame(Xml_generator &xml, - bool jent_avail, - char const *name, - unsigned long min_width, - GEN_FRAME_CONTENT const &gen_frame_content) - { - xml.node("frame", [&] () { - xml.attribute("name", name); - - xml.node("vbox", [&] () { - - gen_frame_title(xml, "title", min_width, jent_avail); - gen_frame_content(xml); - }); - }); - } - - template - void gen_controls_frame(Xml_generator &xml, - bool jent_avail, - char const *name, - GEN_FRAME_CONTENT const &gen_frame_content) - { - xml.node("frame", [&] () { - xml.attribute("name", name); - - xml.node("vbox", [&] () { - - if (!jent_avail) - gen_frame_title(xml, "title", 0, jent_avail); - - gen_frame_content(xml); - }); - }); - } - - template - void gen_untitled_frame(Xml_generator &xml, - char const *name, - GEN_FRAME_CONTENT const &gen_frame_content) - { - xml.node("frame", [&] () { - xml.attribute("name", name); - - xml.node("float", [&] () { - xml.attribute("name", "xxx"); - xml.attribute("east", "yes"); - xml.attribute("west", "yes"); - xml.attribute("north", "yes"); - - xml.node("vbox", [&] () { - - gen_frame_content(xml); - }); - }); - }); - } - - void gen_info_frame(Xml_generator &xml, - bool jent_avail, - char const *name, - char const *info, - unsigned long min_width); - - void gen_action_button_at_bottom(Xml_generator &xml, - char const *name, - char const *label, - bool hovered, - bool selected); - - void gen_action_button_at_bottom(Xml_generator &xml, - char const *label, - bool hovered, - bool selected); - - void gen_text_input(Xml_generator &xml, - char const *name, - String<256> const &text, - bool selected); - - void gen_titled_text_input(Xml_generator &xml, - char const *name, - char const *title, - String<256> const &text, - bool selected); - - void gen_info_line(Xml_generator &xml, - char const *name, - char const *text); - - void gen_centered_info_line(Xml_generator &xml, - char const *name, - char const *text); - - void gen_empty_line(Xml_generator &xml, - char const *name, - size_t min_width); - - void gen_multiple_choice_entry(Xml_generator &xml, - char const *name, - char const *text, - bool hovered, - bool selected); - - void gen_menu_title(Xml_generator &xml, - char const *name, - char const *label, - char const *label_annex, - bool hovered, - bool selected); - - void gen_closed_menu(Xml_generator &xml, - char const *label, - char const *label_annex, - bool hovered); - - template - void gen_opened_menu(Xml_generator &xml, - char const *label, - char const *label_annex, - bool hovered, - GEN_CONTENT const &gen_content) - { - xml.node("vbox", [&] () { - xml.attribute("name", label); - - gen_menu_title(xml, "Leave", label, label_annex, hovered, true); - gen_content(xml); - }); - } - - void gen_input_passphrase(Xml_generator &xml, - size_t max_width, - Input_passphrase const &passphrase, - bool input_selected, - bool show_hide_button_hovered, - bool show_hide_button_selected); - - void gen_action_button(Xml_generator &xml, - char const *name, - char const *label, - bool hovered, - bool selected, - size_t min_ex = 0); - - void gen_global_controls(Xml_generator &xml, - size_t min_width, - size_t tresor_image_size, - size_t client_fs_size, - size_t nr_of_clients, - bool lock_button_hovered, - bool lock_button_selected); -} - -#endif /* _MENU_VIEW_DIALOG_H_ */ diff --git a/repos/gems/src/app/file_vault/sandbox.h b/repos/gems/src/app/file_vault/sandbox.h index 12d8d6148f..6b01db23d1 100644 --- a/repos/gems/src/app/file_vault/sandbox.h +++ b/repos/gems/src/app/file_vault/sandbox.h @@ -18,9 +18,6 @@ #include #include -/* local includes */ -#include - namespace File_vault { template diff --git a/repos/gems/src/app/file_vault/target.mk b/repos/gems/src/app/file_vault/target.mk index d926d10c8c..a6a0bacba4 100644 --- a/repos/gems/src/app/file_vault/target.mk +++ b/repos/gems/src/app/file_vault/target.mk @@ -1,6 +1,6 @@ TARGET := file_vault -SRC_CC += main.cc menu_view_dialog.cc capacity.cc +SRC_CC += main.cc INC_DIR += $(PRG_DIR) INC_DIR += $(call select_from_repositories,/src/lib/tresor/include) diff --git a/repos/gems/src/app/file_vault/types.h b/repos/gems/src/app/file_vault/types.h index 80d45bfd2b..17c38ea3ce 100644 --- a/repos/gems/src/app/file_vault/types.h +++ b/repos/gems/src/app/file_vault/types.h @@ -15,15 +15,10 @@ #define _TYPES_H_ /* Genode includes */ -#include - -namespace Genode { } +#include namespace File_vault { - using namespace Tresor; - using namespace Genode; - using Node_name = String<32>; using File_path = String<32>; diff --git a/repos/gems/src/app/file_vault/utf8.h b/repos/gems/src/app/file_vault/utf8.h deleted file mode 100644 index 2ab606b322..0000000000 --- a/repos/gems/src/app/file_vault/utf8.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * \brief Local extension of Genodes UTF8 utilities - * \author Norman Feske - * \author Martin Stein - * \date 2021-03-04 - */ - -/* - * Copyright (C) 2021 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -#ifndef _UTF8_H_ -#define _UTF8_H_ - -/* Genode includes */ -#include - -/* local includes */ -#include - -namespace File_vault { - - enum { - CODEPOINT_BACKSPACE = 8, - CODEPOINT_TAB = 9, - }; -} - -#endif /* _UTF8_H_ */ diff --git a/repos/gems/src/app/file_vault_gui/main.cc b/repos/gems/src/app/file_vault_gui/main.cc new file mode 100644 index 0000000000..dcb4fd5304 --- /dev/null +++ b/repos/gems/src/app/file_vault_gui/main.cc @@ -0,0 +1,758 @@ +/* + * \brief Test for Genode's dialog API + * \author Norman Feske + * \date 2023-03-25 + */ + +/* + * Copyright (C) 2023 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#include +#include +#include +#include +#include +#include + +using namespace Dialog; +using namespace File_vault; + +using Text = String<32>; + +struct Back_button : Widget +{ + void view(Scope &s) const + { + s.sub_scope