package socket

import "github.com/testovoleg/whatsmeow/socket"

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

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"
)
const (
	NoiseStartPattern = "Noise_XX_25519_AESGCM_SHA256\x00\x00\x00\x00"

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

Variables

var (
	ErrFrameTooLarge     = errors.New("frame too large")
	ErrSocketClosed      = errors.New("frame socket is closed")
	ErrSocketAlreadyOpen = errors.New("frame socket is already open")
)
var WAConnHeader = []byte{'W', 'A', WAMagicValue, token.DictVersion}

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
	Proxy  Proxy
	// contains filtered or unexported fields
}

func NewFrameSocket

func NewFrameSocket(log waLog.Logger, header []byte, proxy Proxy) *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)

type Proxy

type Proxy = func(*http.Request) (*url.URL, error)

Source Files

constants.go framesocket.go noisehandshake.go noisesocket.go

Version
v0.0.0-20230731113359-3e87cabb9327 (latest)
Published
Jul 31, 2023
Platform
linux/amd64
Imports
18 packages
Last checked
1 month ago

Tools for package owners.