socket

package
v1.0.1-fix Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: MPL-2.0 Imports: 17 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 waSocket 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 (
	NoiseStartPattern = "Noise_XX_25519_AESGCM_SHA256\x00\x00\x00\x00"

	WAMagicValue = 6
)
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 WAConnHeader = []byte{'W', 'A', WAMagicValue, token.DictVersion}

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 {
	URL         string
	HTTPHeaders http.Header

	Frames       chan []byte
	OnDisconnect func(remote bool)
	WriteTimeout time.Duration

	Header []byte
	Dialer websocket.Dialer
	// contains filtered or unexported fields
}

func NewFrameSocket

func NewFrameSocket(log waLog.Logger, dialer websocket.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