fscp

package
v0.0.0-...-da1f172 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2019 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MessageVersion3 is the mandatory version 3 in messages.
	MessageVersion3 MessageVersion = 3

	// MessageTypeHelloRequest is a HELLO request message.
	MessageTypeHelloRequest MessageType = 0x00
	// MessageTypeHelloResponse is a HELLO response message.
	MessageTypeHelloResponse MessageType = 0x01
	// MessageTypePresentation is a PRESENTATION message.
	MessageTypePresentation MessageType = 0x02
	// MessageTypeSessionRequest is a SESSION REQUEST message.
	MessageTypeSessionRequest MessageType = 0x03
	// MessageTypeSession is a SESSION message.
	MessageTypeSession MessageType = 0x04
	// MessageTypeData is a DATA message.
	MessageTypeData = 0x70
	// MessageTypeContactRequest is a CONTACT REQUEST message.
	MessageTypeContactRequest = 0xfd
	// MessageTypeContact is a CONTACT message.
	MessageTypeContact = 0xfe
	// MessageTypeKeepAlive is a KEEP-ALIVE message.
	MessageTypeKeepAlive = 0xff
)
View Source
const DefaultPresharedKeyIterations = 2000

DefaultPresharedKeyIterations is the default preshared key iterations.

View Source
const DefaultPresharedKeyPassphrase = ""

DefaultPresharedKeyPassphrase is the default preshared key passphrase.

View Source
const DefaultTimeout = time.Second * 5

DefaultTimeout is the default time to wait for dialing connections.

View Source
const (
	// Network is the default network.
	Network = "fscp"
)

Variables

View Source
var (
	// DefaultAddr is the default listening address.
	DefaultAddr = &Addr{
		TransportAddr: &net.UDPAddr{
			Port: 5000,
		},
	}
)
View Source
var DefaultDialer = &Dialer{}

DefaultDialer is the default dialer backing the free-form dialing functions.

View Source
var DefaultPresharedKeySalt = []byte("freelan")

DefaultPresharedKeySalt is the default preshared key salt.

Functions

func Dial

func Dial(network, addr string) (net.Conn, error)

Dial dials a new FSCP connection using the default Dialer.

func GenerateLocalCertificate

func GenerateLocalCertificate() (*rsa.PrivateKey, *x509.Certificate, error)

GenerateLocalCertificate generates a default local X509 certificate for the current host.

func Listen

func Listen(network string, addr string) (net.Listener, error)

Listen listens to a FSCP address.

Types

type Addr

type Addr struct {
	TransportAddr net.Addr
}

Addr is a FSCP address.

func ResolveFSCPAddr

func ResolveFSCPAddr(network, address string) (*Addr, error)

ResolveFSCPAddr parses a FSCP address.

func (*Addr) Network

func (a *Addr) Network() string

Network returns the network associated to the address.

func (*Addr) String

func (a *Addr) String() string

type CipherSuite

type CipherSuite uint8

CipherSuite represents a cipher suite.

const (
	// NullCipherSuite represents an invalid cipher suite.
	NullCipherSuite CipherSuite = 0x00
	// ECDHERSAAES128GCMSHA256 is the ECDHE-RSA-AES-128-GCM-SHA256 cipher suite.
	ECDHERSAAES128GCMSHA256 CipherSuite = 0x01
	// ECDHERSAAES256GCMSHA384 is the ECDHE-RSA-AES-256-GCM-SHA384 cipher suite.
	ECDHERSAAES256GCMSHA384 CipherSuite = 0x02
)

func (CipherSuite) BlockSize

func (s CipherSuite) BlockSize() int

BlockSize returns the block size.

func (CipherSuite) String

func (i CipherSuite) String() string

type CipherSuiteSlice

type CipherSuiteSlice []CipherSuite

CipherSuiteSlice represents a slice of cipher suites.

func DefaultCipherSuites

func DefaultCipherSuites() CipherSuiteSlice

DefaultCipherSuites returns the default cipher suites.

func (CipherSuiteSlice) FindCommon

func (s CipherSuiteSlice) FindCommon(others CipherSuiteSlice) CipherSuite

FindCommon returns the first cipher suite that is found in both slices.

func (CipherSuiteSlice) String

func (s CipherSuiteSlice) String() string

type Client

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

Client represents a FSCP connection.

func ListenFSCP

func ListenFSCP(network string, addr *Addr, security *ClientSecurity) (*Client, error)

ListenFSCP listens to a FSCP address.

func NewClient

func NewClient(conn net.PacketConn, security *ClientSecurity) (client *Client, err error)

NewClient creates a new client.

func (*Client) Accept

func (c *Client) Accept() (net.Conn, error)

Accept a new connection.

func (*Client) Addr

func (c *Client) Addr() net.Addr

Addr returns the listener address.

func (*Client) Close

func (c *Client) Close() error

Close the listener.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context, remoteAddr *Addr) (conn *Conn, err error)

Connect connects to the specified host.

func (*Client) Security

func (c *Client) Security() ClientSecurity

Security gets the client's security.

func (*Client) SetSecurity

func (c *Client) SetSecurity(security ClientSecurity)

SetSecurity sets the security used by the client.

Existing connections are shut-down.

type ClientSecurity

type ClientSecurity struct {
	Certificate    *x509.Certificate
	PrivateKey     *rsa.PrivateKey
	PresharedKey   []byte
	CipherSuites   CipherSuiteSlice
	EllipticCurves EllipticCurveSlice

	RemoteClientSecurity *RemoteClientSecurity
}

ClientSecurity contains all the security settings of a client.

func (*ClientSecurity) SetPresharedKeyFromPassphrase

func (s *ClientSecurity) SetPresharedKeyFromPassphrase(passphrase string, salt []byte, iterations int)

SetPresharedKeyFromPassphrase set the preshared key from a passphrase and salt/iterations parameters.

func (ClientSecurity) Sign

func (s ClientSecurity) Sign(cleartext []byte) ([]byte, error)

Sign a message.

func (*ClientSecurity) Validate

func (s *ClientSecurity) Validate() (err error)

Validate the security.

func (ClientSecurity) Verify

func (s ClientSecurity) Verify(cleartext []byte, signature []byte) error

Verify a signature.

type Conn

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

Conn is a FSCP connection.

func DialFSCP

func DialFSCP(network string, laddr *Addr, raddr *Addr) (*Conn, error)

DialFSCP dials a new FSCP connection.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection.

func (*Conn) LocalAddr

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

LocalAddr returns the local address of the connection.

func (*Conn) Read

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

func (*Conn) RemoteAddr

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

RemoteAddr returns the remote address of the connection.

func (*Conn) SetDeadline

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

SetDeadline sets the deadline on the connection.

func (*Conn) SetReadDeadline

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

SetReadDeadline sets the deadline on the connection.

func (*Conn) SetWriteDeadline

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

SetWriteDeadline sets the deadline on the connection.

func (*Conn) Write

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

type Dialer

type Dialer struct {
	Timeout  time.Duration
	Security *ClientSecurity
}

A Dialer offers connection dialing primitives.

func (*Dialer) Dial

func (d *Dialer) Dial(network, addr string) (net.Conn, error)

Dial dials a new connection.

func (*Dialer) DialFSCP

func (d *Dialer) DialFSCP(network string, laddr *Addr, raddr *Addr) (*Conn, error)

DialFSCP dials a new FSCP connection.

type EllipticCurve

type EllipticCurve uint8

EllipticCurve represents an elliptic curve.

const (
	// NullEllipticCurve represents an invalid elliptic curve.
	NullEllipticCurve EllipticCurve = 0x00
	// SECT571K1 is the SECT571K1 elliptic curve.
	SECT571K1 EllipticCurve = 0x01
	// SECP384R1 is the SECP384R1 elliptic curve.
	SECP384R1 EllipticCurve = 0x02
	// SECP521R1 is the SECP521R1 elliptic curve.
	SECP521R1 EllipticCurve = 0x03
)

func (EllipticCurve) Curve

func (c EllipticCurve) Curve() elliptic.Curve

Curve returns the associated elliptic curve.

func (EllipticCurve) String

func (i EllipticCurve) String() string

type EllipticCurveSlice

type EllipticCurveSlice []EllipticCurve

EllipticCurveSlice represents a slice of elliptic curves.

func DefaultEllipticCurves

func DefaultEllipticCurves() EllipticCurveSlice

DefaultEllipticCurves returns the default elliptic curves.

func (EllipticCurveSlice) FindCommon

FindCommon returns the first elliptic curve that is found in both slices.

func (EllipticCurveSlice) String

func (s EllipticCurveSlice) String() string

type HostIdentifier

type HostIdentifier [32]byte

HostIdentifier represents a host identifier.

func GenerateHostIdentifier

func GenerateHostIdentifier() (result HostIdentifier, err error)

GenerateHostIdentifier generates a new random host identifier.

func (HostIdentifier) String

func (i HostIdentifier) String() string

type MessageType

type MessageType uint8

MessageType represents a message type.

func (MessageType) String

func (m MessageType) String() string

type MessageVersion

type MessageVersion uint8

MessageVersion represents a message version.

type RemoteClientSecurity

type RemoteClientSecurity struct {
	Certificate *x509.Certificate
}

RemoteClientSecurity represents the remote client security.

type Retrier

type Retrier struct {
	Operation func() error
	OnFailure func(error)
	Period    time.Duration
	// contains filtered or unexported fields
}

A Retrier retries a given operation until it is satisfied.

func (*Retrier) Start

func (r *Retrier) Start()

Start the retrier.

func (*Retrier) Stop

func (r *Retrier) Stop() bool

Stop the retrier.

type SequenceNumber

type SequenceNumber uint32

A SequenceNumber is a 4 bytes sequence number.

type Session

type Session struct {
	LocalHostIdentifier  HostIdentifier
	RemoteHostIdentifier HostIdentifier
	SessionNumber        SessionNumber
	CipherSuite          CipherSuite
	EllipticCurve        EllipticCurve
	LocalSequenceNumber  SequenceNumber
	RemoteSequenceNumber SequenceNumber
	PublicKey            *ecdsa.PublicKey
	PrivateKey           []byte
	RemotePublicKey      *ecdsa.PublicKey
	LocalSessionKey      []byte
	RemoteSessionKey     []byte
	LocalIV              []byte
	RemoteIV             []byte
	LocalAEAD            cipher.AEAD
	RemoteAEAD           cipher.AEAD
}

Session represents an outgoing or incoming session.

func NewSession

func NewSession(hostIdentifier HostIdentifier, sessionNumber SessionNumber, cipherSuite CipherSuite, ellipticCurve EllipticCurve) (*Session, error)

NewSession instantiate a new session.

In case of an error, an invalid session is always returned.

func (*Session) Decrypt

func (s *Session) Decrypt(msg *messageData) ([]byte, error)

Decrypt a ciphertext.

This method is not thread-safe.

ciphertext will be modified after the call, regardless of the outcome.

func (*Session) Encrypt

func (s *Session) Encrypt(cleartext []byte) *messageData

Encrypt a cleartext.

This method is not thread-safe.

func (*Session) SetRemote

func (s *Session) SetRemote(hostIdentifier HostIdentifier, publicKey *ecdsa.PublicKey) error

SetRemote computes the session keys.

type SessionNumber

type SessionNumber uint32

SessionNumber represents a session number.

type Signer

type Signer interface {
	Sign(cleartext []byte) ([]byte, error)
}

A Signer signs data.

type UniqueNumber

type UniqueNumber uint32

An UniqueNumber is a randomly generated number used during the HELLO exchange.

type Verifier

type Verifier interface {
	Verify(cleartext []byte, signature []byte) error
}

A Verifier verifies signed data.

Jump to

Keyboard shortcuts

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