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
- Variables
- func KeyDerivation(rawKey []byte, keyLen int, hSuite *hash.HashSuite) (key []byte)
- type Cipher
- type CipherHandler
- type CryptoConn
- func (c *CryptoConn) Close() error
- func (c *CryptoConn) LocalAddr() net.Addr
- func (c *CryptoConn) Read(b []byte) (n int, err error)
- func (c *CryptoConn) RemoteAddr() net.Addr
- func (c *CryptoConn) SetDeadline(t time.Time) error
- func (c *CryptoConn) SetReadDeadline(t time.Time) error
- func (c *CryptoConn) SetWriteDeadline(t time.Time) error
- func (c *CryptoConn) Write(b []byte) (n int, err error)
- type CryptoListener
Constants ¶
const (
// MagicSize is the ETLS magic header size.
MagicSize = 2
)
Variables ¶
var ( // MagicBytes is the ETLS connection magic header. MagicBytes = [MagicSize]byte{0xC0, 0x4E} )
Functions ¶
func KeyDerivation ¶
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.
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 ¶
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.
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.