From b752ab65b87465d287837724a95d59ed6d0351d1 Mon Sep 17 00:00:00 2001 From: Firstyear Date: Wed, 28 Jun 2023 18:34:03 +1000 Subject: [PATCH] 20230628 tpm minor issue with key regen (#1790) * Ignore key that cant be loaded * fix handle --- unix_integration/src/db.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/unix_integration/src/db.rs b/unix_integration/src/db.rs index 7761a5bff..8d50e1716 100644 --- a/unix_integration/src/db.rs +++ b/unix_integration/src/db.rs @@ -830,20 +830,22 @@ pub(crate) mod tpm { let ex_ctx = if let Some(ctx_data) = ctx_data { // Test loading, blank it out if it fails. - // deserialise - let maybe_ctx: TpmsContext = - serde_json::from_slice(ctx_data.as_slice()).map_err(|e| { + serde_json::from_slice(ctx_data.as_slice()).map_err(|e| { warn!("json error -> {:?}", e); - })?; - - // can it load? - context - .execute_with_nullauth_session(|ctx| ctx.context_load(maybe_ctx.clone())) - .map_err(|e| { - error!(tpm_err = ?e, "Failed to load tpm context"); - })?; - - Some(maybe_ctx) + }) + // On error, becomes none and we do nothing else. + .ok() + .and_then(|maybe_ctx: TpmsContext| { + // can it load? + context + .execute_with_nullauth_session(|ctx| ctx.context_load(maybe_ctx.clone())) + .map_err(|e| { + error!(tpm_err = ?e, "Failed to load tpm context"); + }) + .ok() + // It loaded, so sub in our context. + .map(|_handle| maybe_ctx) + }) } else { None };