╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve_ssh_protocol.zig ───────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1921 if (r.len > half or s.len > half) return false; 1922 var sig_bytes: [Ecdsa.Signature.encoded_length]u8 = @splat(0); 1923 @memcpy(sig_bytes[half - r.len .. half], r); 1924 @memcpy(sig_bytes[2 * half - s.len ..], s); 1925 1926 const pk = Ecdsa.PublicKey.fromSec1(point) catch return false; 1927 Ecdsa.Signature.fromBytes(sig_bytes).verify(signed, pk) catch return false; 1928 return true; 1929 } 1930 1931 // the unsigned bytes of a positive mpint in its shortest encoding (RFC 4251 1932 // §5), or null for zero, negative, or padded encodings 1933 fn canonicalMpintMagnitude(bytes: []const u8) ?[]const u8 { 1934 if (bytes.len == 0 or bytes[0] & 0x80 != 0) return null; 1935 if (bytes[0] != 0) return bytes; 1936 if (bytes.len < 2 or bytes[1] & 0x80 == 0) return null; 1937 return bytes[1..]; 1938 } 1939 1940 // --------------------------------------------------------------------------- 1941 // connection layer (RFC 4254): channels, requests, data, flow control 1942 // --------------------------------------------------------------------------- 1943 1944 const Channel = struct { 1945 local_id: u32, 1946 remote_id: u32, 1947 local_window: u32, // bytes peer may still send us before we adjust 1948 remote_window: u32, // bytes we may still send to peer before they adjust 1949 max_packet: u32, // max CHANNEL_DATA payload the peer accepts in one packet 1950 pty: ?PtySize = null, 1951 // value of GIT_PROTOCOL, one of the two env variables we keep 1952 git_protocol_buf: [64]u8 = undefined, 1953 git_protocol_len: ?usize = null, 1954 // false when NO_COLOR is set, the other env variable we keep 1955 color: bool = true, 1956 }; 1957 1958 pub const PtySize = struct { width_cells: u16, height_cells: u16 }; 1959 1960 // take the uint32 width/height cell counts of a pty-req or window-change, 1961 // bounded before either initial rendering or a resize can allocate grids. 1962 // keep zero dimensions intact (unspecified at startup, minimized on resize). 1963 fn takePtySize(r: *std.Io.Reader) !PtySize { 1964 const width = @min(try r.takeInt(u32, .big), max_pty_width); 1965 const height = @min(try r.takeInt(u32, .big), max_pty_height); 1966 return .{ 1967 .width_cells = @intCast(width), 1968 .height_cells = @intCast(height), 1969 }; 1970 } 1971 1972 fn runChannelLayer( 1973 conn: *Conn, 1974 client_key: *const ClientKey, 1975 handler: anytype, 1976 ) !void { 1977 const allocator = conn.allocator; 1978 var channel: ?Channel = null; 1979 1980 while (true) { 1981 const packet = try readSessionPacket(conn); 1982 defer allocator.free(packet); 1983 const msg_type = packet[0]; 1984 1985 switch (msg_type) { 1986 SSH_MSG_GLOBAL_REQUEST => try handleGlobalRequest(conn, packet), 1987 1988 SSH_MSG_CHANNEL_OPEN => { 1989 channel = try handleChannelOpen(conn, packet, channel != null) orelse continue; 1990 }, 1991 1992 SSH_MSG_CHANNEL_REQUEST => { 1993 const ch = if (channel) |*c| c else return error.UnknownChannel; 1994 const start_request = try handleChannelRequest(conn, ch, packet); 1995 // the request borrows from the packet, which outlives the session 1996 if (start_request) |request| { 1997 // any key authenticates, so the deadline holds until here 1998 conn.idle.session_started.store(true, .release); 1999 var sess = SessionCtx{ 2000 .conn = conn, 2001 .channel = ch, 2002 .fingerprint = client_key.fingerprint, 2003 .public_key = client_key.blob, 2004 }; 2005 defer sess.deinit(); 2006 handler.handleSession(&sess, request) catch |session_err| { 2007 // a failed read leaves the protocol unusable, so the 2008 // disconnect names it instead of a clean close 2009 if (sess.read_err) |read_err| return read_err; 2010 // try to send a non-zero exit status before closing 2011 sess.exit(1) catch {}; 2012 return sess.underlyingError(session_err); 2013 }; 2014 if (!sess.closed) try sess.exit(0); 2015 return; 2016 } 2017 }, 2018 2019 SSH_MSG_CHANNEL_WINDOW_ADJUST => { 2020 const ch = if (channel) |*c| c else return error.UnknownChannel; 2021 try handleWindowAdjust(ch, packet); 2022 }, 2023 2024 SSH_MSG_CHANNEL_DATA, SSH_MSG_CHANNEL_EXTENDED_DATA => { 2025 const ch = if (channel) |*c| c else return error.UnknownChannel; 2026 // before shell/exec the client shouldn't be sending data, but 2027 // some clients are chatty; discard and refill window. nothing 2028 // is buffered yet, so the whole window is available to credit. 2029 try discardChannelData(ch, packet, msg_type == SSH_MSG_CHANNEL_EXTENDED_DATA); 2030 try maybeRefillRecvWindow(conn, ch, initial_recv_window); 2031 }, 2032 2033 SSH_MSG_CHANNEL_EOF => { 2034 const ch = if (channel) |*c| c else return error.UnknownChannel; 2035 try parseChannelId(packet, ch.local_id); 2036 }, 2037 2038 SSH_MSG_CHANNEL_CLOSE => { 2039 const ch = if (channel) |*c| c else return error.UnknownChannel; 2040 try parseChannelId(packet, ch.local_id); 2041 try sendChannelMessage(conn, ch, SSH_MSG_CHANNEL_CLOSE); 2042 drainConnection(conn); 2043 return; 2044 }, 2045 2046 // RFC 4252 §5.1: silently ignored once authenticated 2047 SSH_MSG_USERAUTH_REQUEST => {}, 2048 else => try sendUnimplemented(conn), 2049 } 2050 } 2051 } 2052 2053 fn handleGlobalRequest(conn: *Conn, packet: []const u8) !void { 2054 // byte SSH_MSG_GLOBAL_REQUEST 2055 // string request_name 2056 // boolean want_reply 2057 // …request-specific data we ignore 2058 var r = std.Io.Reader.fixed(packet[1..]); 2059 _ = try takeString(&r, 256); 2060 const want_reply = (try r.takeByte()) != 0; 2061 if (want_reply) { 2062 try conn.writePacket(&.{&[_]u8{SSH_MSG_REQUEST_FAILURE}}); 2063 } 2064 } 2065 2066 /// parse a CHANNEL_OPEN. on a session channel, send CHANNEL_OPEN_CONFIRMATION 2067 /// and return the new Channel. on other types, send CHANNEL_OPEN_FAILURE and 2068 /// return null. 2069 fn handleChannelOpen(conn: *Conn, packet: []const u8, has_channel: bool) !?Channel { 2070 // byte SSH_MSG_CHANNEL_OPEN 2071 // string channel_type 2072 // uint32 sender_channel (peer's id) 2073 // uint32 initial_window 2074 // uint32 max_packet 2075 var r = std.Io.Reader.fixed(packet[1..]); 2076 const ch_type = try takeString(&r, 64); 2077 const remote_id = try r.takeInt(u32, .big); 2078 const initial_window = try r.takeInt(u32, .big); 2079 const max_packet = try r.takeInt(u32, .big); 2080 2081 if (has_channel) { 2082 try sendChannelOpenFailure(conn, remote_id, SSH_OPEN_RESOURCE_SHORTAGE, "only one channel per connection"); 2083 return null; 2084 } 2085 2086 if (!std.mem.eql(u8, ch_type, "session")) { 2087 try sendChannelOpenFailure(conn, remote_id, SSH_OPEN_UNKNOWN_CHANNEL_TYPE, "only session channels are supported"); 2088 return null; 2089 } 2090 2091 // a zero max_packet would leave writeBytes looping without progress 2092 if (max_packet == 0) { 2093 try sendChannelOpenFailure(conn, remote_id, SSH_OPEN_RESOURCE_SHORTAGE, "max packet size must be non-zero"); 2094 return null; 2095 } 2096 2097 const local_id: u32 = 0; // single-channel connection — id is always 0 from our side 2098 var reply: [17]u8 = undefined; 2099 reply[0] = SSH_MSG_CHANNEL_OPEN_CONFIRMATION; 2100 std.mem.writeInt(u32, reply[1..5], remote_id, .big); 2101 std.mem.writeInt(u32, reply[5..9], local_id, .big); 2102 std.mem.writeInt(u32, reply[9..13], initial_recv_window, .big); 2103 std.mem.writeInt(u32, reply[13..17], max_packet_size, .big); 2104 try conn.writePacket(&.{&reply}); 2105 2106 return .{ 2107 .local_id = local_id, 2108 .remote_id = remote_id, 2109 .local_window = initial_recv_window, 2110 .remote_window = initial_window, 2111 .max_packet = max_packet, 2112 }; 2113 } 2114 2115 fn sendChannelOpenFailure(conn: *Conn, remote_id: u32, reason: u32, description: []const u8) !void { 2116 const allocator = conn.allocator; 2117 2118 var reply: std.ArrayList(u8) = .empty; 2119 defer reply.deinit(allocator); 2120 try reply.append(allocator, SSH_MSG_CHANNEL_OPEN_FAILURE); 2121 try writeU32(&reply, allocator, remote_id); 2122 try writeU32(&reply, allocator, reason); 2123 try writeStringField(&reply, allocator, description); 2124 try writeStringField(&reply, allocator, ""); // language tag 2125 try conn.writePacket(&.{reply.items}); 2126 } 2127 2128 /// returns the session request if this one triggered it, else null. an exec 2129 /// command borrows from `packet`. 2130 fn handleChannelRequest(conn: *Conn, ch: *Channel, packet: []const u8) !?Request { 2131 // byte SSH_MSG_CHANNEL_REQUEST 2132 // uint32 recipient_channel (== our local_id) 2133 // string request_type 2134 // boolean want_reply 2135 // …request-specific data 2136 var r = std.Io.Reader.fixed(packet[1..]); 2137 const recipient_channel = try r.takeInt(u32, .big); 2138 if (recipient_channel != ch.local_id) return error.UnknownChannel; 2139 const req_type = try takeString(&r, 64); 2140 const want_reply = (try r.takeByte()) != 0; 2141 2142 if (std.mem.eql(u8, req_type, "pty-req")) { 2143 // string TERM, uint32 width chars, uint32 height rows, uint32 width px, 2144 // uint32 height px, string modes 2145 _ = try takeString(&r, 64); 2146 ch.pty = try takePtySize(&r); 2147 try replyChannelRequest(conn, ch, want_reply, true); 2148 return null; 2149 } 2150 2151 if (std.mem.eql(u8, req_type, "env")) { 2152 // string name, string value. the rest are ignored silently. 2153 const name = try takeString(&r, max_packet_len); 2154 const value = try takeString(&r, max_packet_len); 2155 if (std.mem.eql(u8, name, "GIT_PROTOCOL") and value.len <= ch.git_protocol_buf.len) { 2156 @memcpy(ch.git_protocol_buf[0..value.len], value); 2157 ch.git_protocol_len = value.len; 2158 } else if (std.mem.eql(u8, name, "NO_COLOR")) { 2159 ch.color = value.len == 0; 2160 } 2161 try replyChannelRequest(conn, ch, want_reply, true); 2162 return null; 2163 } 2164 2165 if (std.mem.eql(u8, req_type, "window-change")) { 2166 // uint32 width cells, uint32 height rows, uint32 width px, uint32 height px 2167 const sz = try takePtySize(&r); 2168 if (ch.pty != null) ch.pty = sz; 2169 // spec: window-change MUST NOT request a reply, but accept either 2170 try replyChannelRequest(conn, ch, want_reply, true); 2171 return null; 2172 } 2173 2174 if (std.mem.eql(u8, req_type, "shell")) { 2175 try replyChannelRequest(conn, ch, want_reply, true); 2176 return .{ .shell = .{ .pty = ch.pty, .color = ch.color } }; 2177 } 2178 2179 if (std.mem.eql(u8, req_type, "exec")) { 2180 // capture the command string for the handler to inspect 2181 const cmd = try takeString(&r, 4096); 2182 try replyChannelRequest(conn, ch, want_reply, true); 2183 return .{ .exec = .{ 2184 .command = cmd, 2185 .git_protocol = if (ch.git_protocol_len) |len| ch.git_protocol_buf[0..len] else null, 2186 } }; 2187 } 2188 2189 // unknown request kind — fail it 2190 try replyChannelRequest(conn, ch, want_reply, false); 2191 return null; 2192 } 2193 2194 fn replyChannelRequest(conn: *Conn, ch: *Channel, want_reply: bool, success: bool) !void { 2195 if (!want_reply) return; 2196 try sendChannelMessage(conn, ch, if (success) SSH_MSG_CHANNEL_SUCCESS else SSH_MSG_CHANNEL_FAILURE); 2197 } 2198 2199 fn sendChannelMessage(conn: *Conn, ch: *Channel, msg_type: u8) !void { 2200 var packet: [5]u8 = undefined; 2201 packet[0] = msg_type; 2202 std.mem.writeInt(u32, packet[1..5], ch.remote_id, .big); 2203 try conn.writePacket(&.{&packet}); 2204 } 2205 2206 fn handleWindowAdjust(ch: *Channel, packet: []const u8) !void { 2207 // byte SSH_MSG_CHANNEL_WINDOW_ADJUST 2208 // uint32 recipient_channel 2209 // uint32 bytes_to_add 2210 var r = std.Io.Reader.fixed(packet[1..]); 2211 const recipient_channel = try r.takeInt(u32, .big); 2212 if (recipient_channel != ch.local_id) return error.UnknownChannel; 2213 const add = try r.takeInt(u32, .big); 2214 ch.remote_window +|= add; 2215 } 2216 2217 // charge a payload's bytes against the receive window without keeping them. 2218 // the caller credits the window back, choosing the budget that suits it. 2219 fn discardChannelData(ch: *Channel, packet: []const u8, extended: bool) !void { 2220 // byte SSH_MSG_CHANNEL_DATA/EXTENDED_DATA 2221 // uint32 recipient_channel 2222 // [if extended: uint32 type_code] 2223 // string data 2224 const payload = try parseChannelData(packet, extended, ch.local_id); 2225 const data_len: u32 = @intCast(payload.len); 2226 2227 if (data_len > ch.local_window) return error.WindowExceeded; 2228 ch.local_window -= data_len; 2229 } 2230 2231 pub fn parseChannelData(packet: []const u8, extended: bool, expected_channel: u32) ![]const u8 { 2232 if (packet.len < 1) return error.EmptyPacket; 2233 var r = std.Io.Reader.fixed(packet[1..]); 2234 const recipient_channel = try r.takeInt(u32, .big); 2235 if (recipient_channel != expected_channel) return error.UnknownChannel; 2236 if (extended) { 2237 const data_type = try r.takeInt(u32, .big); 2238 if (data_type != SSH_EXTENDED_DATA_STDERR) return error.UnsupportedExtendedData; 2239 } 2240 const data_len = try r.takeInt(u32, .big); 2241 // catches both data_len > remaining (would otherwise be a bounds-check 2242 // panic on the slice) and trailing junk after the declared payload. 2243 if (data_len != r.buffered().len) return error.InvalidChannelData; 2244 return r.buffered(); 2245 } 2246 2247 fn parseChannelId(packet: []const u8, expected_channel: u32) !void { 2248 var r = std.Io.Reader.fixed(packet[1..]); 2249 const recipient_channel = try r.takeInt(u32, .big); 2250 if (recipient_channel != expected_channel) return error.UnknownChannel; 2251 if (r.buffered().len != 0) return error.InvalidChannelMessage; 2252 } 2253 2254 /// send a CHANNEL_WINDOW_ADJUST if our receive window has dipped below half 2255 /// of `budget`, the credit we're willing to have outstanding. used both for 2256 /// the pre-session discard path and by SessionCtx after it consumes a 2257 /// CHANNEL_DATA payload. 2258 fn maybeRefillRecvWindow(conn: *Conn, ch: *Channel, budget: u32) !void { 2259 if (ch.local_window >= budget / 2) return; 2260 const add = budget - ch.local_window; 2261 ch.local_window += add; 2262 var packet: [9]u8 = undefined; 2263 packet[0] = SSH_MSG_CHANNEL_WINDOW_ADJUST; 2264 std.mem.writeInt(u32, packet[1..5], ch.remote_id, .big); 2265 std.mem.writeInt(u32, packet[5..9], add, .big); 2266 try conn.writePacket(&.{&packet}); 2267 } 2268 2269 pub fn writeU32(buf: *std.ArrayList(u8), allocator: std.mem.Allocator, value: u32) !void { 2270 var bytes: [4]u8 = undefined; 2271 std.mem.writeInt(u32, &bytes, value, .big); 2272 try buf.appendSlice(allocator, &bytes); 2273 } 2274 2275 test "pty dimensions have bounded axes, preserving normal and zero sizes" { 2276 for ([_]struct { width: u32, height: u32, expected: PtySize }{ 2277 .{ .width = 80, .height = 24, .expected = .{ .width_cells = 80, .height_cells = 24 } }, 2278 .{ .width = 0, .height = 0, .expected = .{ .width_cells = 0, .height_cells = 0 } }, 2279 .{ .width = 0xffffffff, .height = 0xffffffff, .expected = .{ .width_cells = 512, .height_cells = 128 } }, 2280 }) |case| { 2281 var bytes: [8]u8 = undefined; 2282 std.mem.writeInt(u32, bytes[0..4], case.width, .big); 2283 std.mem.writeInt(u32, bytes[4..8], case.height, .big); 2284 var reader = std.Io.Reader.fixed(&bytes); 2285 try std.testing.expectEqual(case.expected, try takePtySize(&reader)); 2286 } 2287 } 2288 2289 test "channel close before shell or exec is acknowledged" { 2290 const io = std.testing.io; 2291 const allocator = std.testing.allocator; 2292 const key: [64]u8 = @splat(0x5a); 2293 var encoded: [256]u8 = undefined; 2294 var encoded_writer = std.Io.Writer.fixed(&encoded); 2295 var sender = Cipher.init(&key, 0); 2296 var open: std.ArrayList(u8) = .empty; 2297 defer open.deinit(allocator); 2298 try open.append(allocator, SSH_MSG_CHANNEL_OPEN); 2299 try writeStringField(&open, allocator, "session"); 2300 try writeU32(&open, allocator, 7); 2301 try writeU32(&open, allocator, 32768); 2302 try writeU32(&open, allocator, 32768); 2303 try sender.writePacket(io, &encoded_writer, &.{open.items}); 2304 try sender.writePacket(io, &encoded_writer, &.{&.{ SSH_MSG_CHANNEL_CLOSE, 0, 0, 0, 0 }}); 2305 var reader = std.Io.Reader.fixed(encoded_writer.buffered()); 2306 var output: [256]u8 = undefined; 2307 var writer = std.Io.Writer.fixed(&output); 2308 var idle = IdleState{}; 2309 var conn = Conn{ 2310 .io = io, 2311 .allocator = allocator, 2312 .reader = &reader, 2313 .writer = &writer, 2314 .cs_cipher = Cipher.init(&key, 0), 2315 .sc_cipher = Cipher.init(&key, 0), 2316 .rekey = undefined, 2317 .idle = &idle, 2318 }; 2319 const Handler = struct { 2320 pub fn handleSession(_: *@This(), _: *SessionCtx, _: Request) !void { 2321 return error.UnexpectedSession; 2322 } 2323 }; 2324 var handler = Handler{}; 2325 try runChannelLayer(&conn, &.{ .fingerprint = @splat(0), .blob = "" }, &handler); 2326 var output_reader = std.Io.Reader.fixed(writer.buffered()); 2327 var receiver = Cipher.init(&key, 0); 2328 const confirmation = try receiver.readPacket(allocator, &output_reader); 2329 defer allocator.free(confirmation); 2330 try std.testing.expectEqual(SSH_MSG_CHANNEL_OPEN_CONFIRMATION, confirmation[0]); 2331 const close = try receiver.readPacket(allocator, &output_reader); 2332 defer allocator.free(close); 2333 try std.testing.expectEqualSlices(u8, &.{ SSH_MSG_CHANNEL_CLOSE, 0, 0, 0, 7 }, close); 2334 try std.testing.expectEqual(0, output_reader.buffered().len); 2335 } 2336