Documentation ¶
Index ¶
- Constants
- Variables
- func DecodePayload(encodedPayload []byte, v interface{}) error
- func DecryptPayload(clientKey [nacl.NaclKeyBytesSize]byte, ...) ([]byte, error)
- func EncodePayload(payload interface{}) ([]byte, error)
- func EncryptPayload(clientKey [nacl.NaclKeyBytesSize]byte, ...) ([]byte, error)
- func ExtractNonce(b []byte) (n []byte, err error)
- func IsValidAddressID(id interface{}) bool
- func IsValidPingInterval(pingInterval interface{}) bool
- func IsValidReasonCode(reason interface{}) bool
- func IsValidResponderAddressID(id interface{}) bool
- func IsValidResponderAddressType(addr AddressType) bool
- func IsValidSubprotocols(subprotocols interface{}) bool
- func IsValidYourCookieBytes(pk interface{}) bool
- func IsValidYourKey(yourKey interface{}) bool
- func MakeNonce(h Header) (bts []byte)
- func ParsePingInterval(pingInterval interface{}) (int, error)
- func ParseReasonCode(reason interface{}) (int, error)
- func ParseSubprotocols(subprotocols interface{}) ([]string, error)
- func ParseYourCookie(pk interface{}) ([]byte, error)
- func ParseYourKey(yourKey interface{}) ([KeyBytesSize]byte, error)
- func SignKeys(clientKey [nacl.NaclKeyBytesSize]byte, ...) []byte
- func UnmarshalMessage(f Frame) (msg interface{}, err error)
- func WriteFrame(w io.Writer, f Frame) error
- func WriteHeader(w io.Writer, h Header) error
- type AddressType
- type BaseMessage
- type BasicEncodingOpts
- type ClientAuthMessage
- type ClientHelloMessage
- type DisconnectedMessage
- type DropResponderMessage
- type Frame
- type Header
- type MessageFlowError
- type MessageType
- type NewInitiatorMessage
- type NewResponderMessage
- type PayloadFieldError
- type PayloadMarshaler
- type PayloadUnmarshaler
- type PayloadWriter
- type RawMessage
- type ServerAuthEncodingOpts
- type ServerAuthMessage
- type ServerHelloMessage
Constants ¶
const ( // CloseCodeNormalClosure is Normal closure (WebSocket internal close code) CloseCodeNormalClosure = 1000 // CloseCodeGoingAway is Going Away (WebSocket internal close code) CloseCodeGoingAway = 1001 // CloseCodeSubprotocolError is Protocol Error (WebSocket internal close code) CloseCodeSubprotocolError = 1002 // CloseCodePathFullError is Path Full CloseCodePathFullError = 3000 // CloseCodeProtocolError is Protocol Error CloseCodeProtocolError = 3001 // CloseCodeInternalError is Internal Error CloseCodeInternalError = 3002 // CloseCodeHandover is Handover of the Signalling Channel CloseCodeHandover = 3003 // CloseCodeDropByInitiator is Dropped by Initiator CloseCodeDropByInitiator = 3004 // CloseCodeInitiatorCouldNotDecrypt is Initiator Could Not Decrypt CloseCodeInitiatorCouldNotDecrypt = 3005 CloseCodeNoSharedTasks = 3006 // CloseCodeInvalidKey is Invalid Key CloseCodeInvalidKey = 3007 // CloseCodeTimeout is Timeout CloseCodeTimeout = 3008 )
const ( // KeyBitSize represents the size of a key in bits KeyBitSize = 256 // KeyBytesSize represents the size of a key in bytes KeyBytesSize = 32 // KeyStringLength represents the size of a key in string KeyStringLength = 64 // PathLength is length of a path in string PathLength = KeyStringLength )
const ( // DataLengthMin minimum length of data (nonce + payload) DataLengthMin = 25 // NonceLength is length of nonce in bytes NonceLength = 24 // CookieLength is length of cookie in bytes CookieLength = 16 // SourceLength is length of source client in bytes SourceLength = 1 // SourceUpperBound is CookieLength + SourceLength SourceUpperBound = CookieLength + SourceLength // DestinationLength is length of destination client DestinationLength = 1 // DestinationUpperBound is SourceUpperBound + DestinationLength DestinationUpperBound = SourceUpperBound + DestinationLength // CsnUpperBound is upper bound of combined sequence number CsnUpperBound = NonceLength )
const (
// HeaderSize is size of header
HeaderSize = 24
)
const (
// SubprotocolSaltyRTCv1 default protocol identifier: "v1.saltyrtc.org"
SubprotocolSaltyRTCv1 = "v1.saltyrtc.org"
)
Variables ¶
var ( // ErrNotAllowedMessage occurs when you are trying to relay a message to invalid dest ErrNotAllowedMessage = errors.New("not allowed message") // ErrNotMatchedIdentities occurs when you identities dont match for two different source ErrNotMatchedIdentities = errors.New("identities dont match") // ErrNotAuthenticatedClient occurs when you are trying to encrypt message ErrNotAuthenticatedClient = errors.New("client is not authenticated") // ErrMessageTooShort occurs when the length of message less than expected ErrMessageTooShort = errors.New("message is too short") // ErrCantDecodePayload occurs when try to decode payload ErrCantDecodePayload = errors.New("cant decode payload") // ErrFieldNotExist occurs when a field should exist but it doesnt ErrFieldNotExist = errors.New("field doesnt exist") // ErrInvalidFieldValue occurs when fiel value is not valid ErrInvalidFieldValue = errors.New("invalid field value") // ErrCantDecryptPayload occurs when try to decrypt payload ErrCantDecryptPayload = errors.New("cant decrypt payload") )
var ( // ErrHeaderLengthUnexpected occurs when header does not match with expected length ErrHeaderLengthUnexpected = fmt.Errorf("header error: unexpected header length bytes") )
var ( // ErrSlotsFull occurs when no free slot on path ErrSlotsFull = errors.New("no free slot on path") )
Functions ¶
func DecodePayload ¶
DecodePayload decodes encodedPayload into v
func DecryptPayload ¶
func DecryptPayload(clientKey [nacl.NaclKeyBytesSize]byte, serverSessionSk [nacl.NaclKeyBytesSize]byte, nonce []byte, data []byte) ([]byte, error)
DecryptPayload returns decrypted data in bytes
func EncodePayload ¶
EncodePayload returns encoded of payload in bytes
func EncryptPayload ¶
func EncryptPayload(clientKey [nacl.NaclKeyBytesSize]byte, serverSessionSk [nacl.NaclKeyBytesSize]byte, nonce []byte, encodedPayload []byte) ([]byte, error)
EncryptPayload encryptes payload as bytes
func ExtractNonce ¶
ExtractNonce extracts nonce from b
func IsValidAddressID ¶
func IsValidAddressID(id interface{}) bool
IsValidAddressID checks whether id is a valid address
func IsValidPingInterval ¶
func IsValidPingInterval(pingInterval interface{}) bool
IsValidPingInterval checks if given pingInterval is valid. it must be type of int and higher than 0
func IsValidReasonCode ¶
func IsValidReasonCode(reason interface{}) bool
IsValidReasonCode checks if given reason valid
func IsValidResponderAddressID ¶
func IsValidResponderAddressID(id interface{}) bool
IsValidResponderAddressID returns true if id is a valid responder address
func IsValidResponderAddressType ¶
func IsValidResponderAddressType(addr AddressType) bool
IsValidResponderAddressType checks if addr is valid address
func IsValidSubprotocols ¶
func IsValidSubprotocols(subprotocols interface{}) bool
IsValidSubprotocols checks if given subprotocols is valid. it must be type of []string
func IsValidYourCookieBytes ¶
func IsValidYourCookieBytes(pk interface{}) bool
IsValidYourCookieBytes checks if given pk is valid. length of pk must be equal to 16(CookieLength)
func IsValidYourKey ¶
func IsValidYourKey(yourKey interface{}) bool
IsValidYourKey checks if given yourKey is valid. It must be a valid public key of nacl box
func ParsePingInterval ¶
ParsePingInterval parses given pingInterval as type of int
func ParseReasonCode ¶
ParseReasonCode parses given reason as type of int
func ParseSubprotocols ¶
ParseSubprotocols parses given subprotocols to subprotocols as type of []string
func ParseYourCookie ¶
ParseYourCookie parses given pk to your_cookie in bytes
func ParseYourKey ¶
func ParseYourKey(yourKey interface{}) ([KeyBytesSize]byte, error)
ParseYourKey parses yourKey. It creates nacl box public key in bytes
func SignKeys ¶
func SignKeys(clientKey [nacl.NaclKeyBytesSize]byte, serverSessionPk [nacl.NaclKeyBytesSize]byte, serverPermanentSk [nacl.NaclKeyBytesSize]byte, nonce []byte) []byte
SignKeys seals nonce with client and server keys to bytes
func UnmarshalMessage ¶
UnmarshalMessage ..
func WriteFrame ¶
WriteFrame writes frame binary representation into w.
Types ¶
type AddressType ¶
type AddressType = uint8
AddressType represents type of address
const ( // Server represents address identifier for a Server Server AddressType = 0x00 // Initiator represents address identifier for a Initiator Initiator AddressType = 0x01 // Responder represents address identifier for a Responder Responder AddressType = 0xff )
func GetAddressTypeFromAddr ¶
func GetAddressTypeFromAddr(addr AddressType) AddressType
GetAddressTypeFromAddr parses type of addr
func ParseAddressID ¶
func ParseAddressID(id interface{}) (AddressType, error)
ParseAddressID parses id to address of type
func ParseResponderAddressID ¶
func ParseResponderAddressID(id interface{}) (AddressType, error)
ParseResponderAddressID parses id as address of type
type BasicEncodingOpts ¶
BasicEncodingOpts is options for encoding with basic fields
type ClientAuthMessage ¶
type ClientAuthMessage struct { BaseMessage ServerCookie []byte Subprotocols []string PingInterval uint32 ServerKey [KeyBytesSize]byte EncodingOpts BasicEncodingOpts }
ClientAuthMessage ..
func NewClientAuthMessage ¶
func NewClientAuthMessage(src AddressType, dest AddressType, serverCookie []byte, subprotocols []string, pingInterval uint32, serverKey [KeyBytesSize]byte) *ClientAuthMessage
NewClientAuthMessage ..
func (*ClientAuthMessage) MarshalPayload ¶
func (m *ClientAuthMessage) MarshalPayload() ([]byte, error)
MarshalPayload ..
type ClientHelloMessage ¶
type ClientHelloMessage struct { BaseMessage ClientPublicKey []byte }
ClientHelloMessage ..
func NewClientHelloMessage ¶
func NewClientHelloMessage(src AddressType, dest AddressType, clientPublicKey []byte) *ClientHelloMessage
NewClientHelloMessage ..
func (*ClientHelloMessage) MarshalPayload ¶
func (m *ClientHelloMessage) MarshalPayload() ([]byte, error)
MarshalPayload ..
type DisconnectedMessage ¶
type DisconnectedMessage struct { BaseMessage EncodingOpts BasicEncodingOpts // contains filtered or unexported fields }
DisconnectedMessage ..
func NewDisconnectedMessage ¶
func NewDisconnectedMessage(src AddressType, dest AddressType, clientID AddressType) *DisconnectedMessage
NewDisconnectedMessage ..
func (*DisconnectedMessage) MarshalPayload ¶
func (m *DisconnectedMessage) MarshalPayload() ([]byte, error)
MarshalPayload ..
type DropResponderMessage ¶
type DropResponderMessage struct { BaseMessage ResponderID AddressType Reason int EncodingOpts BasicEncodingOpts }
DropResponderMessage ..
func NewDropResponderMessage ¶
func NewDropResponderMessage(src AddressType, dest AddressType, responderID AddressType) *DropResponderMessage
NewDropResponderMessage ..
func NewDropResponderMessageWithReason ¶
func NewDropResponderMessageWithReason(src AddressType, dest AddressType, responderID AddressType, reason int) *DropResponderMessage
NewDropResponderMessageWithReason ..
func (*DropResponderMessage) MarshalPayload ¶
func (m *DropResponderMessage) MarshalPayload() ([]byte, error)
MarshalPayload returns the bytes encoding of m
type Header ¶
type Header struct { Cookie []byte // 16 byte Csn []byte // 2+4 byte Src uint8 // 1 byte Dest uint8 // 1 byte }
Header represents fields in header of a frame
type MessageFlowError ¶
MessageFlowError occurs when a received message violates flow
func NewMessageFlowError ¶
func NewMessageFlowError(message string, err error) *MessageFlowError
NewMessageFlowError ..
func (*MessageFlowError) Error ¶
func (e *MessageFlowError) Error() string
type MessageType ¶
type MessageType = string
MessageType is used to represent type of a message
const ( // ServerHello .. ServerHello MessageType = "server-hello" // ClientHello .. ClientHello MessageType = "client-hello" // ClientAuth .. ClientAuth MessageType = "client-auth" // ServerAuth .. ServerAuth MessageType = "server-auth" // NewResponder .. NewResponder MessageType = "new-responder" // NewInitiator .. NewInitiator MessageType = "new-initiator" // DropResponder .. DropResponder MessageType = "drop-responder" // SendError .. SendError MessageType = "send-error" // Disconnected .. Disconnected MessageType = "disconnected" )
type NewInitiatorMessage ¶
type NewInitiatorMessage struct { BaseMessage EncodingOpts BasicEncodingOpts // contains filtered or unexported fields }
NewInitiatorMessage ..
func NewNewInitiatorMessage ¶
func NewNewInitiatorMessage(src AddressType, dest AddressType) *NewInitiatorMessage
NewNewInitiatorMessage ..
func (*NewInitiatorMessage) MarshalPayload ¶
func (m *NewInitiatorMessage) MarshalPayload() ([]byte, error)
MarshalPayload ..
type NewResponderMessage ¶
type NewResponderMessage struct { BaseMessage EncodingOpts BasicEncodingOpts // contains filtered or unexported fields }
NewResponderMessage ..
func NewNewResponderMessage ¶
func NewNewResponderMessage(src AddressType, dest AddressType, responderID AddressType) *NewResponderMessage
NewNewResponderMessage ..
func (*NewResponderMessage) MarshalPayload ¶
func (m *NewResponderMessage) MarshalPayload() ([]byte, error)
MarshalPayload ..
type PayloadFieldError ¶
PayloadFieldError represents an error correlated to a particular field
func NewPayloadFieldError ¶
func NewPayloadFieldError(payloadType string, field string, err error) *PayloadFieldError
NewPayloadFieldError creates PayloadFieldError instance
type PayloadMarshaler ¶
PayloadMarshaler ..
type PayloadUnmarshaler ¶
PayloadUnmarshaler ..
type PayloadWriter ¶
PayloadWriter writes payload into w
type RawMessage ¶
type RawMessage struct { BaseMessage Data []byte }
RawMessage ..
func NewRawMessage ¶
func NewRawMessage(src AddressType, dest AddressType, data []byte) *RawMessage
NewRawMessage ..
func (*RawMessage) MarshalPayload ¶
func (m *RawMessage) MarshalPayload() ([]byte, error)
MarshalPayload ..
type ServerAuthEncodingOpts ¶
type ServerAuthEncodingOpts struct { ServerPermanentSk [nacl.NaclKeyBytesSize]byte ClientKey [nacl.NaclKeyBytesSize]byte ServerSessionSk [nacl.NaclKeyBytesSize]byte ServerSessionPk [nacl.NaclKeyBytesSize]byte Nonce []byte }
ServerAuthEncodingOpts is options for encoding of server auth messsage
type ServerAuthMessage ¶
type ServerAuthMessage struct { BaseMessage EncodingOpts ServerAuthEncodingOpts // contains filtered or unexported fields }
ServerAuthMessage ..
func NewServerAuthMessageForInitiator ¶
func NewServerAuthMessageForInitiator(src AddressType, dest AddressType, clientCookie []byte, signKeys bool, responderIds []AddressType) *ServerAuthMessage
NewServerAuthMessageForInitiator ..
func NewServerAuthMessageForResponder ¶
func NewServerAuthMessageForResponder(src AddressType, dest AddressType, clientCookie []byte, signKeys bool, initiatorConnected bool) *ServerAuthMessage
NewServerAuthMessageForResponder ..
func (ServerAuthMessage) MarshalPayload ¶
func (m ServerAuthMessage) MarshalPayload() ([]byte, error)
MarshalPayload ...
type ServerHelloMessage ¶
type ServerHelloMessage struct { BaseMessage // contains filtered or unexported fields }
ServerHelloMessage ..
func NewServerHelloMessage ¶
func NewServerHelloMessage(src AddressType, dest AddressType, serverPublicKey []byte) *ServerHelloMessage
NewServerHelloMessage ..
func (*ServerHelloMessage) MarshalPayload ¶
func (m *ServerHelloMessage) MarshalPayload() ([]byte, error)
MarshalPayload ..