1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
//! Messages involved in the SSH's **transport** (`SSH-TRANS`) part of the protocol,
//! as defined in the [RFC 4253](https://datatracker.ietf.org/doc/html/rfc4253)
//! and [RFC 5656](https://datatracker.ietf.org/doc/html/rfc5656).
use binrw::binrw;
use crate::arch;
/// The `SSH_MSG_DISCONNECT` message.
///
/// see <https://datatracker.ietf.org/doc/html/rfc4253#section-11.1>.
#[binrw]
#[derive(Debug)]
#[brw(big, magic = 1_u8)]
pub struct Disconnect {
/// Reason for disconnection.
pub reason: DisconnectReason,
/// Description of the reason for disconnection.
pub description: arch::StringUtf8,
/// Language tag.
pub language: arch::StringAscii,
}
/// The `reason` for disconnect in the `SSH_MSG_DISCONNECT` message.
#[binrw]
#[derive(Debug)]
#[brw(big)]
pub enum DisconnectReason {
/// `SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT`.
#[brw(magic = 1_u32)]
HostNotAllowedToConnect,
/// `SSH_DISCONNECT_PROTOCOL_ERROR`.
#[brw(magic = 2_u32)]
ProtocolError,
/// `SSH_DISCONNECT_KEY_EXCHANGE_FAILED`.
#[brw(magic = 3_u32)]
KeyExchangeFailed,
/// `SSH_DISCONNECT_RESERVED`.
#[brw(magic = 4_u32)]
Reserved,
/// `SSH_DISCONNECT_MAC_ERROR`.
#[brw(magic = 5_u32)]
MacError,
/// `SSH_DISCONNECT_COMPRESSION_ERROR`.
#[brw(magic = 6_u32)]
CompressionError,
/// `SSH_DISCONNECT_SERVICE_NOT_AVAILABLE`.
#[brw(magic = 7_u32)]
ServiceNotAvailable,
/// `SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED`.
#[brw(magic = 8_u32)]
ProtocolVersionNotSupported,
/// `SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE`.
#[brw(magic = 9_u32)]
HostKeyNotVerifiable,
/// `SSH_DISCONNECT_CONNECTION_LOST`.
#[brw(magic = 10_u32)]
ConnectionLost,
/// `SSH_DISCONNECT_BY_APPLICATION`.
#[brw(magic = 11_u32)]
ByApplication,
/// `SSH_DISCONNECT_TOO_MANY_CONNECTIONS`.
#[brw(magic = 12_u32)]
TooManyConnections,
/// `SSH_DISCONNECT_AUTH_CANCELLED_BY_USER`.
#[brw(magic = 13_u32)]
AuthCancelledByUser,
/// `SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE`.
#[brw(magic = 14_u32)]
NoMoreAuthMethodsAvailable,
/// `SSH_DISCONNECT_ILLEGAL_USER_NAME`.
#[brw(magic = 15_u32)]
IllegalUserName,
/// Any other disconnect reason, may be non-standard.
///
/// The 'reason' values in the range of `0xFE000000`
/// through `0xFFFFFFFF` are reserved for PRIVATE USE.
Other(u32),
}
/// The `SSH_MSG_IGNORE` message.
///
/// see <https://datatracker.ietf.org/doc/html/rfc4253#section-11.2>.
#[binrw]
#[derive(Debug)]
#[brw(big, magic = 2_u8)]
pub struct Ignore {
/// A random blob of data to ignore.
pub data: arch::Bytes,
}
/// The `SSH_MSG_DEBUG` message.
///
/// see <https://datatracker.ietf.org/doc/html/rfc4253#section-11.3>.
#[binrw]
#[derive(Debug)]
#[brw(big, magic = 4_u8)]
pub struct Debug {
/// Whether the debug data should be forcefully displayed.
pub always_display: arch::Bool,
/// The debug message.
pub message: arch::StringUtf8,
/// Language tag.
pub language: arch::StringAscii,
}
/// The `SSH_MSG_UNIMPLEMENTED` message.
///
/// see <https://datatracker.ietf.org/doc/html/rfc4253#section-11.4>.
#[binrw]
#[derive(Debug)]
#[brw(big, magic = 3_u8)]
pub struct Unimplemented {
/// Packet sequence number of rejected message.
pub seq: u32,
}
/// The `SSH_MSG_SERVICE_REQUEST` message.
///
/// see <https://datatracker.ietf.org/doc/html/rfc4253#section-10>.
#[binrw]
#[derive(Debug)]
#[brw(big, magic = 5_u8)]
pub struct ServiceRequest {
/// The service name to request.
pub service_name: u32,
}
/// The `SSH_MSG_SERVICE_ACCEPT` message.
///
/// see <https://datatracker.ietf.org/doc/html/rfc4253#section-10>.
#[binrw]
#[derive(Debug)]
#[brw(big, magic = 6_u8)]
pub struct ServiceAccept {
/// Service name accepted to be requested.
pub service_name: u32,
}
/// The `SSH_MSG_KEXINIT` message.
///
/// see <https://datatracker.ietf.org/doc/html/rfc4253#section-7.1>.
#[binrw]
#[derive(Debug)]
#[brw(big, magic = 20_u8)]
pub struct KexInit {
/// The kex-init cookie.
pub cookie: [u8; 16],
/// Kex algorithms.
pub kex_algorithms: arch::NameList,
/// Server host-key algorithms.
pub server_host_key_algorithms: arch::NameList,
/// Client -> server encryption algorithms.
pub encryption_algorithms_client_to_server: arch::NameList,
/// Server -> client encryption algorithms.
pub encryption_algorithms_server_to_client: arch::NameList,
/// Client -> server MAC algorithms.
pub mac_algorithms_client_to_server: arch::NameList,
/// Server -> client MAC algorithms.
pub mac_algorithms_server_to_client: arch::NameList,
/// Client -> server compression algorithms.
pub compression_algorithms_client_to_server: arch::NameList,
/// Server -> client compression algorithms.
pub compression_algorithms_server_to_client: arch::NameList,
/// Client -> server languages.
pub languages_client_to_server: arch::NameList,
/// Server -> client languages.
pub languages_server_to_client: arch::NameList,
/// Whether the first kex packet follows.
pub first_kex_packet_follows: arch::Bool,
#[bw(calc = 0)]
_reserved: u32,
}
/// The `SSH_MSG_NEWKEYS` message.
///
/// see <https://datatracker.ietf.org/doc/html/rfc4253#section-7.3>.
#[binrw]
#[derive(Debug)]
#[brw(big, magic = 21_u8)]
pub struct NewKeys;
/// The `SSH_MSG_KEXDH_INIT` message.
///
/// see <https://datatracker.ietf.org/doc/html/rfc4253#section-8>.
#[binrw]
#[derive(Debug)]
#[brw(big, magic = 30_u8)]
pub struct KexdhInit {
/// Exchange value sent by the client.
pub e: arch::MpInt,
}
/// The `SSH_MSG_KEXDH_REPLY` message.
///
/// see <https://datatracker.ietf.org/doc/html/rfc4253#section-8>.
#[binrw]
#[derive(Debug)]
#[brw(big, magic = 31_u8)]
pub struct KexdhReply {
/// Server's public host key.
pub k_s: arch::Bytes,
/// Exchange value sent by the server.
pub f: arch::MpInt,
/// Signature of the exchange hash.
pub signature: arch::Bytes,
}
/// The `SSH_MSG_KEX_ECDH_INIT` message.
///
/// see <https://datatracker.ietf.org/doc/html/rfc5656#section-4>.
#[binrw]
#[derive(Debug)]
#[brw(big, magic = 30_u8)]
pub struct KexEcdhInit {
/// Client's ephemeral public key octet string
pub q_c: arch::Bytes,
}
/// The `SSH_MSG_KEX_ECDH_REPLY` message.
///
/// see <https://datatracker.ietf.org/doc/html/rfc5656#section-4>.
#[binrw]
#[derive(Debug)]
#[brw(big, magic = 31_u8)]
pub struct KexEcdhReply {
/// Server's public host key.
pub k_s: arch::Bytes,
/// Server's ephemeral public key octet string
pub q_s: arch::Bytes,
/// Signature of the exchange hash.
pub signature: arch::Bytes,
}