diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-10-30 09:21:24 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-10-30 09:21:24 +0800 |
| commit | cc43704e7412ef82f6d41ba211b50e26307a3ddf (patch) | |
| tree | f52402ba8103644320e02e30d73656545a6a4597 /crates/utils/tcp_connection/src | |
| parent | 50945b098e3f6ff16f3f4cf25c2835ddf1e7b3a8 (diff) | |
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
Diffstat (limited to 'crates/utils/tcp_connection/src')
| -rw-r--r-- | crates/utils/tcp_connection/src/instance_challenge.rs | 10 |
1 files changed, 5 insertions, 5 deletions
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<Path>, - ) -> Result<bool, TcpTargetError> { + ) -> 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 |
