Shahroozevsky
Shahroozevsky

Reputation: 343

How to get Packet Sequence Number in SslStream?

I developed a Tls Server (On .Net 6.0) that listens on port 12345 for incoming traffic. I want to extract Sequence Number of received packets in my Tls Server.
For first step I check sslStream.InnerStream but this method doesn't exist on SslStream class. This was mentioned in Microsoft Document on Ssl Stream Properties and Microsoft Document on AuthenticatedStream.InnerStream Property.
For second step I tend to use reflection on TcpConnectionInformation like below:

SslStream sslStream = new SslStream(client.GetStream(), false);
await sslStream.AuthenticateAsServerAsync(serverCertificate);

NetworkStream networkStream = sslStream.GetType().GetProperty("InnerStream", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(sslStream) as NetworkStream;
if (networkStream != null)
{
    TcpConnectionInformation tcpInfo = networkStream.GetType().GetMethod("GetConnectionInfo", BindingFlags.NonPublic | BindingFlags.Instance)?.Invoke(networkStream, null) as TcpConnectionInformation;
    long sendSequenceNumber = tcpInfo?.SendSequenceNumber ?? 0;
    long receiveSequenceNumber = tcpInfo?.ReceiveSequenceNumber ?? 0;
    // do something with the sequence numbers
}

But TcpConnectionInformation class doesn't have SendSequenceNumber nor ReceiveSequenceNumber.
My main question, is itpossible to get packet sequence number in TLS packets or not?

Upvotes: 0

Views: 49

Answers (0)

Related Questions