etls

package
v0.0.0-...-020e20f Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package etls implements "Enhanced Transport Layer Security", but more efficient than TLS used in https. example can be found in test case.

Index

Constants

View Source
const (
	// MagicSize is the ETLS magic header size.
	MagicSize = 2
)

Variables

View Source
var (
	// MagicBytes is the ETLS connection magic header.
	MagicBytes = [MagicSize]byte{0xC0, 0x4E}
)

Functions

func KeyDerivation

func KeyDerivation(rawKey []byte, keyLen int, hSuite *hash.HashSuite) (key []byte)

KeyDerivation .according to ANSI X9.63 we should do a key derivation before using it as a symmetric key, there is not really a common standard KDF(Key Derivation Func). But as SSL/TLS/DTLS did it described in "RFC 4492 TLS ECC", we prefer a Double SHA-256 with it.

Types

type Cipher

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

Cipher struct keeps cipher mode, key, iv.

func NewCipher

func NewCipher(rawKey []byte) (c *Cipher)

NewCipher creates a cipher that can be used in Dial(), Listen() etc.

type CipherHandler

type CipherHandler func(conn net.Conn) (cryptoConn *CryptoConn, err error)

CipherHandler is the func type for converting net.Conn to CryptoConn.

type CryptoConn

type CryptoConn struct {
	net.Conn
	*Cipher
}

CryptoConn implements net.Conn and Cipher interface.

func Dial

func Dial(network, address string, cipher *Cipher) (c *CryptoConn, err error)

Dial connects to a address with a Cipher address should be in the form of host:port.

func NewConn

func NewConn(c net.Conn, cipher *Cipher) *CryptoConn

NewConn returns a new CryptoConn.

func (*CryptoConn) Close

func (c *CryptoConn) Close() error

Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.

func (*CryptoConn) LocalAddr

func (c *CryptoConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*CryptoConn) Read

func (c *CryptoConn) Read(b []byte) (n int, err error)

Read iv and Encrypted data.

func (*CryptoConn) RemoteAddr

func (c *CryptoConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*CryptoConn) SetDeadline

func (c *CryptoConn) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with the connection. A zero value for t means Read and Write will not time out. After a Write has timed out, the TLS state is corrupt and all future writes will return the same error.

func (*CryptoConn) SetReadDeadline

func (c *CryptoConn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the read deadline on the underlying connection. A zero value for t means Read will not time out.

func (*CryptoConn) SetWriteDeadline

func (c *CryptoConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the write deadline on the underlying connection. A zero value for t means Write will not time out. After a Write has timed out, the TLS state is corrupt and all future writes will return the same error.

func (*CryptoConn) Write

func (c *CryptoConn) Write(b []byte) (n int, err error)

Write iv and Encrypted data.

type CryptoListener

type CryptoListener struct {
	net.Listener
	CHandler CipherHandler
}

CryptoListener implements net.Listener.

func NewCryptoListener

func NewCryptoListener(network, addr string, handler CipherHandler) (*CryptoListener, error)

NewCryptoListener returns a new CryptoListener.

func (*CryptoListener) Accept

func (l *CryptoListener) Accept() (net.Conn, error)

Accept waits for and returns the next connection to the listener.

func (*CryptoListener) Addr

func (l *CryptoListener) Addr() net.Addr

Addr returns the listener's network address.

func (*CryptoListener) Close

func (l *CryptoListener) Close() error

Close closes the listener. Any blocked Accept operations will be unblocked and return errors.

Jump to

Keyboard shortcuts

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