- An extended SslStream with support for SNI
- An extended BufferedStream with support for reading bytes and string
Install by nuget
Install-Package StreamExtended
Supports
- .Net Standard 1.3 or above
- .Net Framework 4.5 or above
- Visual Studio Code as IDE for .NET core
- Visual Studio 2017 as IDE for .NET framework/.NET core
- Visual Studio Code as IDE for .NET core
- Visual Studio 2017 as IDE for Mono
- Visual Studio Code as IDE for .NET core
- Mono develop as IDE for Mono
var bufferSize = 4096;
var bufferPool = new DefaultBufferPool();
var yourClientStream = new CustomBufferedStream(clientStream, bufferPool, bufferSize)
var clientSslHelloInfo = await SslTools.PeekClientHello(yourClientStream, bufferPool);
//will be null if no client hello was received (not a SSL connection)
if (clientSslHelloInfo != null)
{
string sniHostName = clientSslHelloInfo.Extensions?.FirstOrDefault(x => x.Name == "server_name")?.Data;
//create yourClientCertificate based on sniHostName
//and now as usual
var sslStream = new SslStream(yourClientStream);
await sslStream.AuthenticateAsServerAsync(yourClientCertificate, false, SupportedSslProtocols, false);
}
var bufferSize = 4096;
var bufferPool = new DefaultBufferPool();
var yourClientStream = new CustomBufferedStream(clientStream, bufferPool, bufferSize)
var clientSslHelloInfo = await SslTools.PeekClientHello(yourClientStream, bufferPool);
//will be null if no client hello was received (not a SSL connection)
if(clientSslHelloInfo!=null)
{
//and now as usual
var sslStream = new SslStream(yourClientStream);
await sslStream.AuthenticateAsServerAsync(yourClientCertificate, false, SupportedSslProtocols, false);
}
var bufferSize = 4096;
var bufferPool = new DefaultBufferPool();
var yourServerStream = new CustomBufferedStream(serverStream, bufferPool, bufferSize)
var serverSslHelloInfo = await SslTools.PeekServerHello(yourServerStream, bufferPool);
//will be null if no server hello was received (not a SSL connection)
if(serverSslHelloInfo!=null)
{
//and now as usual
var sslStream = new SslStream(yourServerStream, false, null, null);
await sslStream.AuthenticateAsClientAsync(yourRemoteHostName, null, yourSupportedSslProtocols, false);
}
Special thanks to @honfika who contributed this code originally in Titanium Web Proxy project.