Introduce a state machine for Bob's secure-join

This introduces a state machine which takes care of managing the
handshake transitions in the secure-join protocol.  This separates
user interactions from the protocol state handling.

This means that while handling the protocol state there are a bunch of
failures no longer possible due to all state information being
guaranteed to be present.  As part of this the QR-code state has been
extracted from the generic Lot structure to something suitable just
for the SecureJoin protocol.

A LogSink has been added to the testing tools allowing log messages to
be correctly displayed on test failures.
This commit is contained in:
Floris Bruynooghe
2021-01-10 19:07:24 +01:00
parent 4508eced37
commit 11e3380f65
7 changed files with 833 additions and 440 deletions

View File

@@ -47,7 +47,7 @@ pub struct InnerContext {
pub(crate) blobdir: PathBuf,
pub(crate) sql: Sql,
pub(crate) os_name: Option<String>,
pub(crate) bob: RwLock<Bob>,
pub(crate) bob: Bob,
pub(crate) last_smeared_timestamp: RwLock<i64>,
pub(crate) running_state: RwLock<RunningState>,
/// Mutex to avoid generating the key for the user more than once.
@@ -129,7 +129,7 @@ impl Context {
os_name: Some(os_name),
running_state: RwLock::new(Default::default()),
sql: Sql::new(),
bob: RwLock::new(Default::default()),
bob: Default::default(),
last_smeared_timestamp: RwLock::new(0),
generating_key_mutex: Mutex::new(()),
oauth2_mutex: Mutex::new(()),
@@ -197,7 +197,10 @@ impl Context {
});
}
/// Get the next queued event.
/// Returns a receiver for emitted events.
///
/// Multiple emitters can be created, but note that in this case each emitted event will
/// only be received by one of the emitters, not by all of them.
pub fn get_event_emitter(&self) -> EventEmitter {
self.events.get_emitter()
}