hybrid_tcp_tls_conn

package module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

README

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.

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferConn added in v0.3.0

type BufferConn struct {
	// contains filtered or unexported fields
}

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 added in v0.3.0

func CreateBufferConn(connection net.Conn) *BufferConn

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

func (*BufferConn) Close added in v0.3.0

func (connection *BufferConn) Close() error

Close the underlying connection.

func (*BufferConn) GetBuffer added in v0.3.0

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

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

func (*BufferConn) LocalAddr added in v0.3.0

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

LocalAddr of the underlying connection.

func (*BufferConn) Read added in v0.3.0

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 added in v0.3.0

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

RemoteAddr of the underlying connection.

func (*BufferConn) SetBuffer added in v0.3.0

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 added in v0.3.0

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

SetDeadline to the underlying connection.

func (*BufferConn) SetReadDeadline added in v0.3.0

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

SetReadDeadline to the underlying connection.

func (*BufferConn) SetWriteDeadline added in v0.3.0

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

SetWriteDeadline to the underlying connection.

func (*BufferConn) Write added in v0.3.0

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

Write to the underlying connection.

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

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

func New added in v0.3.0

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 added in v0.3.0

func (connection *Conn) GetTls() bool

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

func (*Conn) GetTlsConfig added in v0.3.0

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 added in v0.3.0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL