2

I Have a NetworkStream should handle both ssl and unencrypted

my data is ascii so when i check some first byte of stream i can determine stream is ssl or not

when i detect stream is ssl I cant create sslStream because AuthenticateAsServer should begin from begining of stream what can I do?

Hamid
  • 577
  • 1
  • 6
  • 15
  • possible duplicate of [How to allow a Server to accept both SSL and plain text (insecure) connections?](http://stackoverflow.com/questions/15227492/how-to-allow-a-server-to-accept-both-ssl-and-plain-text-insecure-connections) – Ed S. Mar 08 '14 at 08:51
  • 1
    it doesnt help me becasue the class provided by answer is not suitable with sslstream class – Hamid Mar 08 '14 at 08:56
  • Maybe Stream.Peek can help you? http://msdn.microsoft.com/en-us/library/system.io.streamreader.peek(v=vs.110).aspx – Yevgeniy.Chernobrivets Mar 08 '14 at 08:58
  • I don't think you understand the code there. It defines a class that can pass a stream to an SSLStream, but only does so if the underlying data is encrypted. It's literally the same exact question. – Ed S. Mar 08 '14 at 08:58
  • ssl stream dont accept that kind of stream u can test it – Hamid Mar 08 '14 at 09:10
  • it throw The stream has to be read/write.Parameter name: innerStream exception – Hamid Mar 08 '14 at 09:14
  • Huh. Ok. I just assumed that it would work given that the question is the same and the answer was accepted. I'll take your word for it though, I must have missed something. – Ed S. Mar 08 '14 at 19:56

1 Answers1

0

What you need is to put back the one byte you needed to peek at. None of the standard streams supports that.

Write a wrapping stream that allows you to prepend a single byte to the stream that you have wrapped. That way, the SSL implementation will not notice any difference.

usr
  • 168,620
  • 35
  • 240
  • 369