Skip to content

Commit

Permalink
tresor: improved module framework and clean-up
Browse files Browse the repository at this point in the history
* A new class Module_channel is introduced in the module framework and all
  channel classes inherit from it. With that class in place, the formerly
  module-specific implementations of the following methods are replaced by
  new generic implementations in the Module framework:

  * ready_to_submit_request
  * submit_request
  * _peek_completed_request
  * _drop_completed_request
  * _peek_generated_request
  * _drop_generated_request
  * generated_request_complete

* Module requests are now held for the duration of their lifetime at the
  module they originate from and not, like before, at their target module. As
  a result, modules can generate new requests inline (without having to wait
  for the target module), making code much simpler to read, reducing the amount
  of channel state, and allowing for non-copyable request types.

* Introduce a sub-state-machine for securing a superblock in the
  superblock_control module in order to reduce redundancy.

* Some modules, like free_tree, were completely re-designed in order to make
  them more readable.

* Replace all conditional exceptions by using the macros in
  tresor/assertion.h .

* Move methods that are used in multiple modules but that were implemented
  redundantly in each module to tresor/types.h.

* Remove verbosity node and all that was related to it from tresor tester
  config as the targeted verbosity can be achieved with the
  VERBOSE_MODULE_COMMUNICATION flag in tresor/verbosity.h .

* Extract the aspect of translating the byte-granular I/O-requests to
  tresor-block requests from the tresor VFS-plugin and move it to a new module
  called splitter.

* Rename the files and interface of the hashing back-end to not reflect the used
  hashing algorithm/config anymore, while at the same time making the hashing
  interface strict regarding the used types.

* Introduce the NONCOPYABLE macro that makes marking a class noncopyable short
  and clear.

* Replace the former tresor/vfs_utilities.h/.cc with a new tresor/file.h
  that contains the classes Read_write_file and Write_only_file. These classes
  significantly simplify the modules crypto, block_io, and trust_anchor by
  moving the details of file access to a sub-state machine.

* The former, rather trivial block allocator module is replaced by a normal
  object of type Pba_allocator that must be provided by the client of the
  Sb_initializer (reference in the Sb_initializer_request).

Ref genodelabs#5062
  • Loading branch information
m-stein committed Nov 27, 2023
1 parent 6074b65 commit 01eb216
Show file tree
Hide file tree
Showing 64 changed files with 6,234 additions and 17,939 deletions.
5 changes: 1 addition & 4 deletions repos/gems/lib/mk/tresor.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ TRESOR_DIR := $(REP_DIR)/src/lib/tresor

SRC_CC += crypto.cc
SRC_CC += request_pool.cc
SRC_CC += sha256_4k_hash.cc
SRC_CC += hash.cc
SRC_CC += trust_anchor.cc
SRC_CC += block_io.cc
SRC_CC += meta_tree.cc
SRC_CC += virtual_block_device.cc
SRC_CC += superblock_control.cc
SRC_CC += free_tree.cc
SRC_CC += module.cc
SRC_CC += block_allocator.cc
SRC_CC += vbd_initializer.cc
SRC_CC += ft_initializer.cc
SRC_CC += sb_initializer.cc
SRC_CC += vfs_utilities.cc
SRC_CC += ft_resizing.cc
SRC_CC += sb_check.cc
SRC_CC += vbd_check.cc
SRC_CC += ft_check.cc
Expand Down
2 changes: 1 addition & 1 deletion repos/gems/lib/mk/vfs_tresor.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LIB_DIR := $(REP_DIR)/src/lib/vfs/tresor

SRC_CC := vfs.cc
SRC_CC := vfs.cc splitter.cc

INC_DIR += $(LIB_DIR)

Expand Down
1 change: 0 additions & 1 deletion repos/gems/recipes/api/tresor/used_apis
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
aes_cbc_4k
base
block_session
libc
openssl
os
Expand Down
25 changes: 6 additions & 19 deletions repos/gems/run/tresor_tester.run
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,6 @@ append config {
<resource name="RAM" quantum="10M"/>
<config ld_verbose="yes">

<verbose
cmd_pool_cmd_pending="no"
cmd_pool_cmd_in_progress="no"
cmd_pool_cmd_completed="no"
blk_io_req_in_progress="no"
blk_io_req_completed="no"
ta_req_in_progress="no"
ta_req_completed="no"
client_data_mismatch="yes"
client_data_transferred="no"/>

<block-io type="vfs" path="/} [tresor_image_name] {"/>
<crypto path="/crypto"/>
<trust-anchor path="/trust_anchor"/>
Expand Down Expand Up @@ -349,11 +338,10 @@ append config {
<request op="read" vba="22" count="3" sync="yes" salt="9612"/>
<request op="read" vba="15" count="2" sync="yes" salt="6111"/>
<request op="write" vba="11" count="6" sync="yes" salt="5436"/>
<list-snapshots/>
<check-snapshots/>
<request op="discard_snapshot" sync="yes" id="1"/>
<request op="discard_snapshot" sync="yes" id="2"/>
<list-snapshots/>
<request op="discard_snapshot" sync="yes" id="3"/>
<check-snapshots/>
<request op="sync" vba="0" count="256" sync="yes"/>
<check/>

Expand Down Expand Up @@ -382,7 +370,6 @@ append config {
<request op="write" vba="21" count="2" sync="no" salt="8094"/>
<request op="write" vba="12" count="10" sync="no" salt="4455"/>
<request op="write" vba="26" count="4" sync="no" salt="7574"/>
<request op="discard_snapshot" sync="no" id="4"/>
<request op="write" vba="15" count="7" sync="no" salt="1931"/>
<request op="read" vba="23" count="1" sync="no" salt="7463"/>
<request op="read" vba="25" count="1" sync="no" salt="4323"/>
Expand All @@ -392,7 +379,8 @@ append config {
<request op="read" vba="12" count="3" sync="no" salt="4455"/>
<request op="read" vba="19" count="3" sync="no" salt="1931"/>
<request op="read" vba="10" count="2" sync="no" salt="3758"/>
<list-snapshots/>
<check-snapshots/>
<request op="discard_snapshot" sync="no" id="4"/>
<request op="sync" vba="0" count="256" sync="yes"/>
<check/>

Expand Down Expand Up @@ -1073,15 +1061,14 @@ if {[benchmark_blk_count] > 0} {
}
append config {

<log string="Step 18: test list-snapshots command"/>
<log string="Step 18: test check-snapshots command"/>

<request op="create_snapshot" sync="no" id="13"/>
<request op="write" vba="17737" count="70" sync="no" salt="8924"/>
<request op="create_snapshot" sync="no" id="14"/>
<request op="write" vba="00129" count="30" sync="no" salt="9471"/>
<request op="create_snapshot" sync="no" id="15"/>

<list-snapshots/>
<check-snapshots/>

</commands>

Expand Down
12 changes: 6 additions & 6 deletions repos/gems/src/app/file_vault/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ struct File_vault::Ui_config
{
using Version_string = String<80>;

Version_string const version { };
Passphrase_string const passphrase { };
Number_of_bytes const client_fs_size { 0 };
Number_of_bytes const journaling_buf_size { 0 };
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_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 }) }
{
Expand Down Expand Up @@ -495,7 +495,7 @@ class File_vault::Main
throw Exception_1 { };
}

Passphrase_string _ui_setup_obtain_params_passphrase() const
Passphrase _ui_setup_obtain_params_passphrase() const
{
switch (_user_interface) {
case MENU_VIEW: return _setup_obtain_params_passphrase.plaintext().string();
Expand Down
6 changes: 3 additions & 3 deletions repos/gems/src/app/file_vault/sandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,9 @@ namespace File_vault {
});
}

void gen_tresor_init_trust_anchor_start_node(Xml_generator &xml,
Child_state const &child,
Passphrase_string const &passphrase)
void gen_tresor_init_trust_anchor_start_node(Xml_generator &xml,
Child_state const &child,
Passphrase const &passphrase)
{
child.gen_start_node(xml, [&] () {

Expand Down
1 change: 0 additions & 1 deletion repos/gems/src/app/file_vault/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace File_vault {
using namespace Genode;

using Node_name = String<32>;
using Passphrase_string = String<64>;
using File_path = String<32>;

class Tree_geometry
Expand Down
2 changes: 1 addition & 1 deletion repos/gems/src/app/tresor_check/main.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* \brief Integration of the Tresor block encryption
* \brief Verify the dimensions and hashes of a tresor container
* \author Martin Stein
* \author Josef Soentgen
* \date 2020-11-10
Expand Down
41 changes: 11 additions & 30 deletions repos/gems/src/app/tresor_init/include/tresor_init/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,37 +46,29 @@ class Tresor_init::Configuration

Configuration (Xml_node const &node)
{
node.with_optional_sub_node("virtual-block-device",
[&] (Xml_node const &vbd)
node.with_optional_sub_node("virtual-block-device", [&] (Xml_node const &vbd)
{
_vbd_nr_of_lvls =
vbd.attribute_value("nr_of_levels", (uint64_t)0);
_vbd_nr_of_children =
vbd.attribute_value("nr_of_children", (uint64_t)0);
_vbd_nr_of_leafs =
vbd.attribute_value("nr_of_leafs", (uint64_t)0);
_vbd_nr_of_lvls = vbd.attribute_value("nr_of_levels", (uint64_t)0);
_vbd_nr_of_children = vbd.attribute_value("nr_of_children", (uint64_t)0);
_vbd_nr_of_leafs = vbd.attribute_value("nr_of_leafs", (uint64_t)0);
});
node.with_optional_sub_node("free-tree",
[&] (Xml_node const &ft)
node.with_optional_sub_node("free-tree", [&] (Xml_node const &ft)
{
_ft_nr_of_lvls =
ft.attribute_value("nr_of_levels", (uint64_t)0);
_ft_nr_of_children =
ft.attribute_value("nr_of_children", (uint64_t)0);
_ft_nr_of_leafs =
ft.attribute_value("nr_of_leafs", (uint64_t)0);
_ft_nr_of_lvls = ft.attribute_value("nr_of_levels", (uint64_t)0);
_ft_nr_of_children = ft.attribute_value("nr_of_children", (uint64_t)0);
_ft_nr_of_leafs = ft.attribute_value("nr_of_leafs", (uint64_t)0);
});
ASSERT(_vbd_nr_of_lvls);
ASSERT(_vbd_nr_of_lvls <= TREE_MAX_NR_OF_LEVELS);
ASSERT(_vbd_nr_of_leafs);
ASSERT(is_power_of_2(_vbd_nr_of_children));
ASSERT(_vbd_nr_of_children <= NR_OF_T1_NODES_PER_BLK);
ASSERT(_vbd_nr_of_children <= NUM_NODES_PER_BLK);
ASSERT(_ft_nr_of_lvls);
ASSERT(_ft_nr_of_lvls <= TREE_MAX_NR_OF_LEVELS);
ASSERT(_ft_nr_of_leafs);
ASSERT(is_power_of_2(_ft_nr_of_children));
ASSERT(_ft_nr_of_children <= NR_OF_T1_NODES_PER_BLK);
ASSERT(_ft_nr_of_children <= NR_OF_T2_NODES_PER_BLK);
ASSERT(_ft_nr_of_children <= NUM_NODES_PER_BLK);
ASSERT(_ft_nr_of_children <= NUM_NODES_PER_BLK);
}

Configuration (Configuration const &other)
Expand All @@ -95,17 +87,6 @@ class Tresor_init::Configuration
uint64_t ft_nr_of_lvls () const { return _ft_nr_of_lvls ; }
uint64_t ft_nr_of_children () const { return _ft_nr_of_children ; }
uint64_t ft_nr_of_leafs () const { return _ft_nr_of_leafs ; }

void print(Output &out) const
{
Genode::print(out,
"vbd=(lvls=", _vbd_nr_of_lvls,
" children=", _vbd_nr_of_children,
" leafs=", _vbd_nr_of_leafs, ")",
" ft=(lvls=", _ft_nr_of_lvls,
" children=", _ft_nr_of_children,
" leafs=", _ft_nr_of_leafs, ")");
}
};

#endif /* _TRESOR_INIT__CONFIGURATION_H_ */

0 comments on commit 01eb216

Please sign in to comment.