feat(ssh): implement session key derivation
Some checks failed
Test / test (push) Has been cancelled
Test / build (push) Has been cancelled

SSH会话密钥实现完成:

实现内容:
1. KexExchangeHandler保存shared_secret和public_keys
   - shared_secret字段(Option<Vec<u8>>)
   - client_public_key字段
   - server_public_key字段

2. compute_session_keys()方法实现
   - 从保存的shared_secret计算会话密钥
   - 使用SessionKeys::derive()方法
   - 返回真实SessionKeys(而非临时默认密钥)

3. server.rs使用真实会话密钥
   - perform_complete_kex_exchange调用compute_session_keys()
   - EncryptionContext::from_session_keys()
   - 初始化真实加密上下文

测试结果:
-  Connection established
-  SSH2_MSG_KEX_ECDH_REPLY received(签名验证成功)
-  SSH2_MSG_NEWKEYS sent/received(加密通道建立)
- 🆕 SSH_MSG_SERVICE_REQUEST sent(客户端尝试认证)
-  Connection reset(服务器无法处理加密packet)

进展对比:
- 之前:Bad packet length错误
- 现在:客户端成功发送SERVICE_REQUEST,连接重置

下一步:
- perform_ssh_auth()使用EncryptedPacket
- 实现EncryptedPacket::read()
- 完成加密packet处理
This commit is contained in:
Warren
2026-06-13 21:20:52 +08:00
parent 609e839f92
commit ec4674ffb7
2 changed files with 25 additions and 10 deletions

View File

@@ -172,7 +172,10 @@ fn perform_complete_kex_exchange(
return Err(anyhow::anyhow!("Encryption channel not ready"));
}
Ok(EncryptionContext::default())
let session_keys = kex_state.exchange_handler.compute_session_keys()?;
let encryption_ctx = EncryptionContext::from_session_keys(&session_keys);
Ok(encryption_ctx)
}
/// SSH认证流程Phase 5