noiseconn

package module
v0.0.0-...-f6d9ecb Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MIT Imports: 7 Imported by: 2

README

noiseconn

A net.Conn wrapper around github.com/flynn/noise.

https://pkg.go.dev/github.com/jtolio/noiseconn

Documentation

Index

Constants

View Source
const HeaderByte = 0x80

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn is a net.Conn that implements a framed Noise protocol on top of the underlying net.Conn provided in NewConn. Conn allows for 0-RTT protocols, in the sense that bytes given to Write will be added to handshake payloads. Read and Write should not be called concurrently until HandshakeComplete() is true.

func NewConn

func NewConn(conn net.Conn, config noise.Config) (*Conn, error)

NewConn wraps an existing net.Conn with encryption provided by noise.Config.

func NewConnWithOptions

func NewConnWithOptions(conn net.Conn, config noise.Config, opts Options) (*Conn, error)

NewConn wraps an existing net.Conn with encryption provided by noise.Config and options provided by Options.

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) HandshakeComplete

func (c *Conn) HandshakeComplete() bool

HandshakeComplete returns whether a handshake is complete.

func (*Conn) HandshakeHash

func (c *Conn) HandshakeHash() []byte

HandshakeHash returns the hash generated by the handshake which can be used for channel identification and channel binding. This returns nil until the handshake is completed.

func (*Conn) Read

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

func (*Conn) Write

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

If a Noise handshake is still occurring (or has yet to occur), the data provided to Write will be included in handshake payloads. Note that even if the Noise configuration allows for 0-RTT, the request will only be 0-RTT if the request is 65535 bytes or smaller.

type Listener

type Listener struct {
	net.Listener
	// contains filtered or unexported fields
}

func NewListener

func NewListener(inner net.Listener, config noise.Config) *Listener

func NewListenerWithOptions

func NewListenerWithOptions(inner net.Listener, config noise.Config, opts Options) *Listener

func (*Listener) Accept

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

type MessageInspector

type MessageInspector func(addr net.Addr, message []byte) error

MessageInspector is a callback that gets informed about unparsed Noise messages.

type Options

type Options struct {
	// ResponderFirstMessageValidator will be called with the first
	// received Noise message (unparsed) for a responder, if set. It is
	// not considered for initiators or for any subsequent packet.
	// This can be used for analyzing message replay, debouncing
	// messages deliberately sent twice
	// (see github.com/jtolio/noiseconn/debounce), and other issues,
	// but is not safe for use as replay attack prevention.
	ResponderFirstMessageValidator MessageInspector
}

Directories

Path Synopsis
debounce module

Jump to

Keyboard shortcuts

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