Documentation ¶
Index ¶
- Constants
- Variables
- func Dial(network, addr string) (net.Conn, error)
- func GenerateLocalCertificate() (*rsa.PrivateKey, *x509.Certificate, error)
- func Listen(network string, addr string) (net.Listener, error)
- type Addr
- type CipherSuite
- type CipherSuiteSlice
- type Client
- type ClientSecurity
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(b []byte) (n int, err error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) Write(p []byte) (n int, err error)
- type Dialer
- type EllipticCurve
- type EllipticCurveSlice
- type HostIdentifier
- type MessageType
- type MessageVersion
- type RemoteClientSecurity
- type Retrier
- type SequenceNumber
- type Session
- type SessionNumber
- type Signer
- type UniqueNumber
- type Verifier
Constants ¶
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 )
DefaultPresharedKeyIterations is the default preshared key iterations.
DefaultPresharedKeyPassphrase is the default preshared key passphrase.
const DefaultTimeout = time.Second * 5
DefaultTimeout is the default time to wait for dialing connections.
const (
// Network is the default network.
Network = "fscp"
)
Variables ¶
var ( // DefaultAddr is the default listening address. DefaultAddr = &Addr{ TransportAddr: &net.UDPAddr{ Port: 5000, }, } )
var DefaultDialer = &Dialer{}
DefaultDialer is the default dialer backing the free-form dialing functions.
DefaultPresharedKeySalt is the default preshared key salt.
Functions ¶
func GenerateLocalCertificate ¶
func GenerateLocalCertificate() (*rsa.PrivateKey, *x509.Certificate, error)
GenerateLocalCertificate generates a default local X509 certificate for the current host.
Types ¶
type Addr ¶
Addr is a FSCP address.
func ResolveFSCPAddr ¶
ResolveFSCPAddr parses a FSCP address.
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) 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 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.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a FSCP connection.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the remote address of the connection.
func (*Conn) SetDeadline ¶
SetDeadline sets the deadline on the connection.
func (*Conn) SetReadDeadline ¶
SetReadDeadline sets the deadline on the connection.
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline sets the deadline on the connection.
type Dialer ¶
type Dialer struct { Timeout time.Duration Security *ClientSecurity }
A Dialer offers connection dialing primitives.
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 ¶
func (s EllipticCurveSlice) FindCommon(others EllipticCurveSlice) EllipticCurve
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 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.
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 ¶
Decrypt a ciphertext.
This method is not thread-safe.
ciphertext will be modified after the call, regardless of the outcome.
type UniqueNumber ¶
type UniqueNumber uint32
An UniqueNumber is a randomly generated number used during the HELLO exchange.