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