Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

An extended SslStream with support to peek TLS handshake extensions

License

Notifications You must be signed in to change notification settings

justcoding121/stream-extended

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stream extended

Note: This Project is no longer maintained.

  • An extended SslStream with support for SNI
  • An extended BufferedStream with support for reading bytes and string

Build Status

Installation

Install by nuget

Install-Package StreamExtended

Supports

  • .Net Standard 1.3 or above
  • .Net Framework 4.5 or above

Development environment

Windows

  • Visual Studio Code as IDE for .NET core
  • Visual Studio 2017 as IDE for .NET framework/.NET core

Mac OS

  • Visual Studio Code as IDE for .NET core
  • Visual Studio 2017 as IDE for Mono

Linux

  • Visual Studio Code as IDE for .NET core
  • Mono develop as IDE for Mono

Usage

Server Name Indication

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);
}

Peek SSL Information

Peek Client SSL Hello

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);
}

Peek Server SSL Hello

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);

}

Note to contributors

Special thanks to @honfika who contributed this code originally in Titanium Web Proxy project.

Collaborators