From cc43704e7412ef82f6d41ba211b50e26307a3ddf Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 30 Oct 2025 09:21:24 +0800 Subject: Return key ID along with challenge verification result - Update challenge method to return (bool, String) tuple - Include key ID in both success and failure cases - Update tests to verify key ID matches expected value - Maintain same verification logic but provide additional context --- crates/utils/tcp_connection/src/instance_challenge.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/utils/tcp_connection/src') diff --git a/crates/utils/tcp_connection/src/instance_challenge.rs b/crates/utils/tcp_connection/src/instance_challenge.rs index c1cf46f..c4ea6a8 100644 --- a/crates/utils/tcp_connection/src/instance_challenge.rs +++ b/crates/utils/tcp_connection/src/instance_challenge.rs @@ -35,13 +35,13 @@ impl ConnectionInstance { /// * `public_key_dir` - Directory containing public key files for verification /// /// # Returns - /// * `Ok(true)` - Challenge verification successful - /// * `Ok(false)` - Challenge verification failed + /// * `Ok((true, "KeyId"))` - Challenge verification successful + /// * `Ok((false, "KeyId"))` - Challenge verification failed /// * `Err(TcpTargetError)` - Error during challenge process pub async fn challenge( &mut self, public_key_dir: impl AsRef, - ) -> Result { + ) -> Result<(bool, String), TcpTargetError> { // Generate random challenge let mut challenge = [0u8; 32]; rand::rngs::OsRng @@ -76,7 +76,7 @@ impl ConnectionInstance { // Load appropriate public key let public_key_path = public_key_dir.as_ref().join(format!("{}.pem", key_id)); if !public_key_path.exists() { - return Ok(false); + return Ok((false, key_id)); } let public_key_pem = tokio::fs::read_to_string(&public_key_path).await?; @@ -103,7 +103,7 @@ impl ConnectionInstance { false }; - Ok(verified) + Ok((verified, key_id)) } /// Accepts a challenge from the target machine to verify connection security -- cgit