LibSSH: Add a getter and a test for Peer::m_session_id

This commit is contained in:
Lucas Chollet
2026-04-01 16:07:41 +02:00
parent 60304ac57d
commit ea28ea7877
2 changed files with 31 additions and 0 deletions

View File

@@ -67,6 +67,16 @@ public:
{
return SSH::Peer::handle_disconnect_message(data);
}
void set_hash(Crypto::Hash::Digest<256> hash)
{
SSH::Peer::set_hash(hash);
}
ReadonlyBytes session_id() const
{
return SSH::Peer::session_id();
}
};
// Copied from wireshark, sniffed from a connection between an openssh server and client.
@@ -116,3 +126,19 @@ TEST_CASE(disconnect_packet)
TRY_OR_FAIL(peer.handle_disconnect_message(message));
EXPECT(!socket.is_open());
}
TEST_CASE(stable_session_id)
{
// A session ID is stable, even after the peers rekeyed.
AllocatingMemoryStream stream;
SocketMock socket(stream);
auto peer = PeerMock(socket);
auto session_id = peer.session_id();
Crypto::Hash::Digest<256> new_hash;
fill_with_random({ new_hash.data, sizeof(new_hash.data) });
peer.set_hash(new_hash);
EXPECT_EQ(peer.session_id(), session_id);
}

View File

@@ -47,6 +47,11 @@ protected:
m_shared_secret = shared_secret;
}
ReadonlyBytes session_id() const
{
return m_session_id.value().bytes();
}
private:
Core::Socket& m_tcp_socket;
NonnullOwnPtr<Cipher> m_cipher;