Skip to content

A net.Conn implementation which can change tls.TLSConn from net.TCPConn when a TLS ClientHello received.

License

Notifications You must be signed in to change notification settings

Rasek91/hybrid_tcp_tls_conn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hybrid_tcp_tls_conn

A net.Conn implementation which can change tls.TLSConn from net.TCPConn when a TLS ClientHello received. It should be used with net.TCPListener.Accept() as underlying connection for BufferConn and the BufferConn should be used for Conn as underlying connection. For implementation example check the test files.

Usage

type BufferConn

type BufferConn struct {
}

BufferConn implements the net.Conn interface. It has an internal buffer and when there is data in it the Read returns the data from the buffer and delete the buffer instead of reading the underlying connection.

func CreateBufferConn

func CreateBufferConn(connection net.Conn) *BufferConn

CreateBufferConn returns a new BufferConn using connection as the underlying connection.

func (*BufferConn) Close

func (connection *BufferConn) Close() error

Close the underlying connection.

func (*BufferConn) GetBuffer

func (connection *BufferConn) GetBuffer() []byte

GetBuffer read the data from the buffer and delete the data from it.

func (*BufferConn) LocalAddr

func (connection *BufferConn) LocalAddr() net.Addr

LocalAddr of the underlying connection.

func (*BufferConn) Read

func (connection *BufferConn) Read(buffer []byte) (int, error)

Read returns the data from the buffer and delete the buffer instead of reading the underlying connection if the internal buffer has data.

func (*BufferConn) RemoteAddr

func (connection *BufferConn) RemoteAddr() net.Addr

RemoteAddr of the underlying connection.

func (*BufferConn) SetBuffer

func (connection *BufferConn) SetBuffer(buffer []byte)

SetBuffer the internal buffer will be equal to buffer. If there was data in the internal buffer it will be overwritten.

func (*BufferConn) SetDeadline

func (connection *BufferConn) SetDeadline(time time.Time) error

SetDeadline to the underlying connection.

func (*BufferConn) SetReadDeadline

func (connection *BufferConn) SetReadDeadline(time time.Time) error

SetReadDeadline to the underlying connection.

func (*BufferConn) SetWriteDeadline

func (connection *BufferConn) SetWriteDeadline(time time.Time) error

SetWriteDeadline to the underlying connection.

func (*BufferConn) Write

func (connection *BufferConn) Write(buffer []byte) (int, error)

Write to the underlying connection.

type Conn

type Conn struct {
}

Conn implements the net.Conn interface. Which can change the underlying connection from TCP to TLS if a TLS ClientHello received.

func New

func New(connection net.Conn, tlsConfig *tls.Config) *Conn

New returns a new Conn using connection converted to BufferConn as the underlying connection. The configuration config must be non-nil and must include at least one certificate or else set GetCertificate, if TLS will be added to the connection.

func (*Conn) Close

func (connection *Conn) Close() error

Close the underlying connection.

func (*Conn) GetTls

func (connection *Conn) GetTls() bool

GetTls returns true if the underlying connection is using TLS and false if not.

func (*Conn) GetTlsConfig

func (connection *Conn) GetTlsConfig() *tls.Config

GetTlsConfig returns the TLS server configuration.

func (*Conn) LocalAddr

func (connection *Conn) LocalAddr() net.Addr

LocalAddr of the underlying connection.

func (*Conn) Read

func (connection *Conn) Read(buffer []byte) (int, error)

Read from the underlying connection. If TLS ClientHello received execute tls.TLSConn.Handshake() and read again for the actual message.

func (*Conn) RemoteAddr

func (connection *Conn) RemoteAddr() net.Addr

RemoteAddr of the underlying connection.

func (*Conn) SetDeadline

func (connection *Conn) SetDeadline(time time.Time) error

SetDeadline to the underlying connection.

func (*Conn) SetReadDeadline

func (connection *Conn) SetReadDeadline(time time.Time) error

SetReadDeadline to the underlying connection.

func (*Conn) SetTlsConfig

func (connection *Conn) SetTlsConfig(tlsConfig *tls.Config)

SetTlsConfig change the TLS server configuration. New connection will be not generated if you change it and TLS is already in use.

func (*Conn) SetWriteDeadline

func (connection *Conn) SetWriteDeadline(time time.Time) error

SetWriteDeadline to the underlying connection.

func (*Conn) Write

func (connection *Conn) Write(buffer []byte) (int, error)

Write to the underlying connection.

About

A net.Conn implementation which can change tls.TLSConn from net.TCPConn when a TLS ClientHello received.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages