0

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?

Shahroozevsky
  • 343
  • 4
  • 17
  • @shingo I don't think that this link is the answer of mine. – Shahroozevsky Aug 12 '23 at 13:26
  • You care using c which is managed and doesn't allow access to all object properties. In c# you cannot get the sequence number. The sequence number is a protected property in the TCP header. See : https://networklessons.com/cisco/ccie-routing-switching-written/tcp-header – jdweng Aug 12 '23 at 14:29
  • Sequence number is an internal property of the TCP stream, which simply provides an unending stream of bytes. The TCP stream is itself used by the SSL stream, which is also an unending stream of bytes. There is no way to get this property, nor does itm make sense to do so. What are you *actually* trying to achieve that you feel you need this? – Charlieface Aug 13 '23 at 05:35
  • @Charlieface thank you for asking, there is a system that sends packets through ssl stream. If this system restarts, it sends all not-sent packets in a burst mode and when I receive these packets, I think that they are not in their correct order. Order of these packets is important because these when all of the packets from one stream received, I create an audio file from it. – Shahroozevsky Aug 13 '23 at 12:11
  • I think you need a better way of telling where the stream was interrupted. For example you can pass an offset of how many bytes to jump. Sequence numbers are just not a reliable indicator especially when SSL streams are involved. – Charlieface Aug 13 '23 at 13:41

0 Answers0