From 3606843b9b9e0c615112e9faf995a37c40b6f082 Mon Sep 17 00:00:00 2001 From: Xynnn007 Date: Sat, 25 Mar 2023 22:07:47 +0800 Subject: [PATCH 1/2] fix: add more debug information when using keyprovider Fixes #55 Signed-off-by: Xynnn007 --- Cargo.toml | 1 + src/encryption.rs | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index edef599..c9d878a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ ctr = { version = ">=0.9", optional = true } hmac = { version = ">=0.12", optional = true } josekit = { version = ">=0.7", optional = true } lazy_static = ">=1.4" +log = "0.4.17" openssl = { version = ">=0.10", features = ["vendored"], optional = true } pin-project-lite = { version = "0.2.9", optional = true } protobuf = { version = "3.2.0", optional = true } diff --git a/src/encryption.rs b/src/encryption.rs index f3f6b81..19861c8 100644 --- a/src/encryption.rs +++ b/src/encryption.rs @@ -5,6 +5,7 @@ use std::collections::HashMap; use std::io::Read; use anyhow::{anyhow, Result}; +use log::warn; use crate::blockcipher::{ EncryptionFinalizer, LayerBlockCipherHandler, LayerBlockCipherOptions, @@ -187,9 +188,17 @@ pub fn decrypt_layer_key_opts_data( priv_key_given = true; } - if let Ok(opts_data) = pre_unwrap_key(keywrapper, dc, &b64_annotation) { - if !opts_data.is_empty() { - return Ok(opts_data); + match pre_unwrap_key(keywrapper, dc, &b64_annotation) { + Ok(opts_data) => { + if !opts_data.is_empty() { + return Ok(opts_data); + } + + warn!("Get empty opts data when unwraping key from keyprovider {scheme}"); + continue; + } + Err(e) => { + warn!("Error occurs when unwraping key from keyprovider: {e}"); } } // try next keywrapper From 8cd8e707a9fcb710895fa5b1dacb971720eb4ae3 Mon Sep 17 00:00:00 2001 From: Xynnn007 Date: Sun, 26 Mar 2023 09:17:06 +0800 Subject: [PATCH 2/2] ttrpc: fix error info Signed-off-by: Xynnn007 --- src/keywrap/keyprovider.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/keywrap/keyprovider.rs b/src/keywrap/keyprovider.rs index 43581b6..3e481b5 100644 --- a/src/keywrap/keyprovider.rs +++ b/src/keywrap/keyprovider.rs @@ -448,8 +448,8 @@ impl KeyProviderKeyWrapper { }); match handler.join() { Ok(Ok(v)) => Ok(v), - Ok(Err(e)) => bail!("failed to unwrap key by gRPC, {e}"), - Err(e) => bail!("failed to unwrap key by gRPC, {e:?}"), + Ok(Err(e)) => bail!("failed to unwrap key by ttrpc, {e}"), + Err(e) => bail!("failed to unwrap key by ttrpc, {e:?}"), } } }