socket

package
v0.0.0-...-9e1ef92 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2022 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package socket implements a subset of the Noise protocol framework on top of websockets as used by WhatsApp.

There shouldn't be any need to manually interact with this package. The Client struct in the top-level whatsmeow package handles everything.

Index

Constants

View Source
const (
	// Origin is the Origin header for all WhatsApp websocket connections
	Origin = "https://web.whatsapp.com"
	// URL is the websocket URL for the new multidevice protocol
	URL = "wss://web.whatsapp.com/ws/chat"
)
View Source
const (
	NoiseXXPattern         = "Noise_XX_25519_AESGCM_SHA256\x00\x00\x00\x00"
	NoiseIKPattern         = "Noise_IK_25519_AESGCM_SHA256\x00\x00\x00\x00"
	NoiseXXFallbackPattern = "Noise_XXfallback_25519_AESGCM_SHA256"

	WADictVersion = 2
	WAMagicValue  = 5
)
View Source
const (
	FrameMaxSize    = 2 << 23
	FrameLengthSize = 3
)

Variables

View Source
var (
	ErrFrameTooLarge     = errors.New("frame too large")
	ErrSocketClosed      = errors.New("frame socket is closed")
	ErrSocketAlreadyOpen = errors.New("frame socket is already open")
)
View Source
var EdgeHeader = []byte{'E', 'D', 0, 1}
View Source
var WAConnHeader = []byte{'W', 'A', WAMagicValue, WADictVersion}

Functions

This section is empty.

Types

type DisconnectHandler

type DisconnectHandler func(socket *NoiseSocket, remote bool)

type FrameHandler

type FrameHandler func([]byte)

type FrameSocket

type FrameSocket struct {
	Frames       chan []byte
	OnDisconnect func(remote bool)
	WriteTimeout time.Duration

	Header []byte
	// contains filtered or unexported fields
}

func NewFrameSocket

func NewFrameSocket(header []byte, dialer proxy.Dialer) *FrameSocket

func (*FrameSocket) Close

func (fs *FrameSocket) Close(code int)

func (*FrameSocket) Connect

func (fs *FrameSocket) Connect() error

func (*FrameSocket) Context

func (fs *FrameSocket) Context() context.Context

func (*FrameSocket) IsConnected

func (fs *FrameSocket) IsConnected() bool

func (*FrameSocket) SendFrame

func (fs *FrameSocket) SendFrame(data []byte) error

type NoiseHandshake

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

func NewNoiseHandshake

func NewNoiseHandshake() *NoiseHandshake

func (*NoiseHandshake) Authenticate

func (nh *NoiseHandshake) Authenticate(data []byte)

func (*NoiseHandshake) Decrypt

func (nh *NoiseHandshake) Decrypt(ciphertext []byte) (plaintext []byte, err error)

func (*NoiseHandshake) Encrypt

func (nh *NoiseHandshake) Encrypt(plaintext []byte) []byte

func (*NoiseHandshake) Finish

func (nh *NoiseHandshake) Finish(fs *FrameSocket, frameHandler FrameHandler, disconnectHandler DisconnectHandler) (*NoiseSocket, error)

func (*NoiseHandshake) MixIntoKey

func (nh *NoiseHandshake) MixIntoKey(data []byte) error

func (*NoiseHandshake) MixSharedSecretIntoKey

func (nh *NoiseHandshake) MixSharedSecretIntoKey(priv, pub [32]byte) error

func (*NoiseHandshake) Start

func (nh *NoiseHandshake) Start(pattern string, header []byte)

type NoiseSocket

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

func (*NoiseSocket) Context

func (ns *NoiseSocket) Context() context.Context

func (*NoiseSocket) IsConnected

func (ns *NoiseSocket) IsConnected() bool

func (*NoiseSocket) SendFrame

func (ns *NoiseSocket) SendFrame(plaintext []byte) error

func (*NoiseSocket) Stop

func (ns *NoiseSocket) Stop(disconnect bool)

Jump to

Keyboard shortcuts

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