Skip to main content

wireforge_app/ssh/
mod.rs

1//! SSH protocol identification — banner and key exchange init parsing (RFC 4253).
2
3mod banner;
4mod kex;
5
6pub use banner::SshBanner;
7pub use kex::{SshBinaryPacket, SshKexInit};
8
9/// Unified SSH identification payload.
10///
11/// SSH traffic on port 22 starts with either a plaintext banner line
12/// (`SSH-2.0-...`) or, after the banner, a binary packet containing
13/// `SSH_MSG_KEXINIT`. This enum wraps both possibilities so that a single
14/// port-based dispatch can return either one.
15#[derive(Debug, Clone)]
16pub enum SshPacket<'a> {
17    Banner(SshBanner<'a>),
18    KexInit(SshKexInit<'a>),
19}
20
21impl<'a> SshPacket<'a> {
22    /// Try to parse an SSH payload.
23    ///
24    /// First attempts to parse a banner line; if that fails, attempts to
25    /// parse a binary `SSH_MSG_KEXINIT` packet.
26    pub fn parse(buf: &'a [u8]) -> Option<Self> {
27        SshBanner::parse(buf)
28            .map(SshPacket::Banner)
29            .or_else(|| SshKexInit::parse(buf).map(SshPacket::KexInit))
30    }
31}