libgm

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: AGPL-3.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const ContentTypePBLite = "application/json+protobuf"
View Source
const ContentTypeProtobuf = "application/x-protobuf"
View Source
const DefaultBugleDefaultCheckInterval = 2*time.Hour + 55*time.Minute
View Source
const GaiaInitTimeout = 20 * time.Second
View Source
const RefreshTachyonBuffer = 1 * time.Hour

Variables

View Source
var (
	ErrNoCookies          = errors.New("gaia pairing requires cookies")
	ErrNoDevicesFound     = errors.New("no devices found for gaia pairing")
	ErrIncorrectEmoji     = errors.New("user chose incorrect emoji on phone")
	ErrPairingCancelled   = errors.New("user cancelled pairing on phone")
	ErrPairingTimeout     = errors.New("pairing timed out")
	ErrPairingInitTimeout = errors.New("client init timed out")
	ErrHadMultipleDevices = errors.New("had multiple primary-looking devices")
)
View Source
var MimeToMediaType = map[string]MediaType{
	"image/jpeg":     {Extension: "jpeg", Type: gmproto.MediaFormats_IMAGE_JPEG},
	"image/jpg":      {Extension: "jpg", Type: gmproto.MediaFormats_IMAGE_JPG},
	"image/png":      {Extension: "png", Type: gmproto.MediaFormats_IMAGE_PNG},
	"image/gif":      {Extension: "gif", Type: gmproto.MediaFormats_IMAGE_GIF},
	"image/wbmp":     {Extension: "wbmp", Type: gmproto.MediaFormats_IMAGE_WBMP},
	"image/bmp":      {Extension: "bmp", Type: gmproto.MediaFormats_IMAGE_X_MS_BMP},
	"image/x-ms-bmp": {Extension: "bmp", Type: gmproto.MediaFormats_IMAGE_X_MS_BMP},

	"video/mp4":        {Extension: "mp4", Type: gmproto.MediaFormats_VIDEO_MP4},
	"video/3gpp2":      {Extension: "3gpp2", Type: gmproto.MediaFormats_VIDEO_3G2},
	"video/3gpp":       {Extension: "3gpp", Type: gmproto.MediaFormats_VIDEO_3GPP},
	"video/webm":       {Extension: "webm", Type: gmproto.MediaFormats_VIDEO_WEBM},
	"video/x-matroska": {Extension: "mkv", Type: gmproto.MediaFormats_VIDEO_MKV},

	"audio/aac":      {Extension: "aac", Type: gmproto.MediaFormats_AUDIO_AAC},
	"audio/amr":      {Extension: "amr", Type: gmproto.MediaFormats_AUDIO_AMR},
	"audio/mp3":      {Extension: "mp3", Type: gmproto.MediaFormats_AUDIO_MP3},
	"audio/mpeg":     {Extension: "mpeg", Type: gmproto.MediaFormats_AUDIO_MPEG},
	"audio/mpg":      {Extension: "mpg", Type: gmproto.MediaFormats_AUDIO_MPG},
	"audio/mp4":      {Extension: "mp4", Type: gmproto.MediaFormats_AUDIO_MP4},
	"audio/mp4-latm": {Extension: "latm", Type: gmproto.MediaFormats_AUDIO_MP4_LATM},
	"audio/3gpp":     {Extension: "3gpp", Type: gmproto.MediaFormats_AUDIO_3GPP},
	"audio/ogg":      {Extension: "ogg", Type: gmproto.MediaFormats_AUDIO_OGG},

	"text/vcard":         {Extension: "vcard", Type: gmproto.MediaFormats_TEXT_VCARD},
	"application/pdf":    {Extension: "pdf", Type: gmproto.MediaFormats_APP_PDF},
	"text/plain":         {Extension: "txt", Type: gmproto.MediaFormats_APP_TXT},
	"text/html":          {Extension: "html", Type: gmproto.MediaFormats_APP_HTML},
	"application/msword": {Extension: "doc", Type: gmproto.MediaFormats_APP_DOC},
	"application/vnd.openxmlformats-officedocument.wordprocessingml.document":   {Extension: "docx", Type: gmproto.MediaFormats_APP_DOCX},
	"application/vnd.openxmlformats-officedocument.presentationml.presentation": {Extension: "pptx", Type: gmproto.MediaFormats_APP_PPTX},
	"application/vnd.ms-powerpoint":                                             {Extension: "ppt", Type: gmproto.MediaFormats_APP_PPT},
	"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":         {Extension: "xlsx", Type: gmproto.MediaFormats_APP_XLSX},
	"application/vnd.ms-excel":                                                  {Extension: "xls", Type: gmproto.MediaFormats_APP_XLS},
	"application/vnd.android.package-archive":                                   {Extension: "apk", Type: gmproto.MediaFormats_APP_APK},
	"application/zip":          {Extension: "zip", Type: gmproto.MediaFormats_APP_ZIP},
	"application/java-archive": {Extension: "jar", Type: gmproto.MediaFormats_APP_JAR},
	"text/x-calendar":          {Extension: "vcs", Type: gmproto.MediaFormats_CAL_TEXT_VCALENDAR},
	"text/calendar":            {Extension: "ics", Type: gmproto.MediaFormats_CAL_TEXT_CALENDAR},

	"image":       {Type: gmproto.MediaFormats_IMAGE_UNSPECIFIED},
	"video":       {Type: gmproto.MediaFormats_VIDEO_UNSPECIFIED},
	"audio":       {Type: gmproto.MediaFormats_AUDIO_UNSPECIFIED},
	"application": {Type: gmproto.MediaFormats_APP_UNSPECIFIED},
	"text":        {Type: gmproto.MediaFormats_APP_TXT},
}

Functions

func GetEmojiSVG

func GetEmojiSVG(emoji string) string

func SAPISIDHash

func SAPISIDHash(origin, sapisid string) string

Types

type AuthData

type AuthData struct {
	// Keys used to encrypt communication with the phone
	RequestCrypto *crypto.AESCTRHelper `json:"request_crypto,omitempty"`
	// Key used to sign requests to refresh the tachyon auth token from the server
	RefreshKey *crypto.JWK `json:"refresh_key,omitempty"`
	// Identity of the paired phone and browser
	Browser *gmproto.Device `json:"browser,omitempty"`
	Mobile  *gmproto.Device `json:"mobile,omitempty"`
	// Key used to authenticate with the server
	TachyonAuthToken []byte    `json:"tachyon_token,omitempty"`
	TachyonExpiry    time.Time `json:"tachyon_expiry,omitempty"`
	TachyonTTL       int64     `json:"tachyon_ttl,omitempty"`
	// Unknown encryption key, not used for anything
	WebEncryptionKey []byte `json:"web_encryption_key,omitempty"`

	SessionID uuid.UUID `json:"session_id,omitempty"`
	DestRegID uuid.UUID `json:"dest_reg_id,omitempty"`
	PairingID uuid.UUID `json:"pairing_id,omitempty"`

	Cookies     map[string]string `json:"cookies,omitempty"`
	CookiesLock sync.RWMutex      `json:"-"`
}

func NewAuthData

func NewAuthData() *AuthData

func (*AuthData) AddCookiesToRequest

func (ad *AuthData) AddCookiesToRequest(req *http.Request)

func (*AuthData) AuthNetwork

func (ad *AuthData) AuthNetwork() string

func (*AuthData) HasCookies

func (ad *AuthData) HasCookies() bool

func (*AuthData) SetCookies

func (ad *AuthData) SetCookies(cookies map[string]string)

func (*AuthData) UpdateCookiesFromResponse

func (ad *AuthData) UpdateCookiesFromResponse(resp *http.Response)

type Client

type Client struct {
	Logger zerolog.Logger

	GaiaHackyDeviceSwitcher int

	PairCallback atomic.Pointer[func(data *gmproto.PairedData)]

	AuthData *AuthData
	// contains filtered or unexported fields
}

func NewClient

func NewClient(authData *AuthData, logger zerolog.Logger) *Client

func (*Client) Connect

func (c *Client) Connect() error

func (*Client) CurrentSessionID

func (c *Client) CurrentSessionID() string

func (*Client) DeleteMessage

func (c *Client) DeleteMessage(messageID string) (*gmproto.DeleteMessageResponse, error)

func (*Client) Disconnect

func (c *Client) Disconnect()

func (*Client) DoGaiaPairing

func (c *Client) DoGaiaPairing(ctx context.Context, emojiCallback func(string)) error

func (*Client) DownloadMedia

func (c *Client) DownloadMedia(mediaID string, key []byte) ([]byte, error)

func (*Client) FetchConfig

func (c *Client) FetchConfig() (*gmproto.Config, error)

func (*Client) FetchMessages

func (c *Client) FetchMessages(conversationID string, count int64, cursor *gmproto.Cursor) (*gmproto.ListMessagesResponse, error)

func (*Client) FinalizeUploadMedia

func (c *Client) FinalizeUploadMedia(upload *StartGoogleUpload) (*MediaUpload, error)

func (*Client) FinishGaiaPairing

func (c *Client) FinishGaiaPairing(ctx context.Context, ps *PairingSession) (string, error)

func (*Client) GenerateQRCodeData

func (c *Client) GenerateQRCodeData(pairingKey []byte) (string, error)

func (*Client) GetContactThumbnail

func (c *Client) GetContactThumbnail(contactIDs ...string) (*gmproto.GetThumbnailResponse, error)

func (*Client) GetConversation

func (c *Client) GetConversation(conversationID string) (*gmproto.Conversation, error)

func (*Client) GetConversationType

func (c *Client) GetConversationType(conversationID string) (*gmproto.GetConversationTypeResponse, error)

func (*Client) GetFullSizeImage

func (c *Client) GetFullSizeImage(messageID, actionMessageID string) (*gmproto.GetFullSizeImageResponse, error)

func (*Client) GetParticipantThumbnail

func (c *Client) GetParticipantThumbnail(participantIDs ...string) (*gmproto.GetThumbnailResponse, error)

func (*Client) GetWebEncryptionKey

func (c *Client) GetWebEncryptionKey() (*gmproto.WebEncryptionKeyResponse, error)

func (*Client) HandleRPCMsg

func (c *Client) HandleRPCMsg(rawMsg *gmproto.IncomingRPCMessage)

func (*Client) IsBugleDefault

func (c *Client) IsBugleDefault() (*gmproto.IsBugleDefaultResponse, error)

func (*Client) IsConnected

func (c *Client) IsConnected() bool

func (*Client) IsLoggedIn

func (c *Client) IsLoggedIn() bool

func (*Client) ListContacts

func (c *Client) ListContacts() (*gmproto.ListContactsResponse, error)

func (*Client) ListConversations

func (*Client) ListTopContacts

func (c *Client) ListTopContacts() (*gmproto.ListTopContactsResponse, error)

func (*Client) MarkRead

func (c *Client) MarkRead(conversationID, messageID string) error

func (*Client) NotifyDittoActivity

func (c *Client) NotifyDittoActivity() (<-chan *IncomingRPCMessage, error)

func (*Client) Reconnect

func (c *Client) Reconnect() error

func (*Client) RefreshPhoneRelay

func (c *Client) RefreshPhoneRelay() (string, error)

func (*Client) RegisterPhoneRelay

func (c *Client) RegisterPhoneRelay() (*gmproto.RegisterPhoneRelayResponse, error)

func (*Client) SendMessage

func (c *Client) SendMessage(payload *gmproto.SendMessageRequest) (*gmproto.SendMessageResponse, error)

func (*Client) SendReaction

func (c *Client) SendReaction(payload *gmproto.SendReactionRequest) (*gmproto.SendReactionResponse, error)

func (*Client) SetActiveSession

func (c *Client) SetActiveSession() error

func (*Client) SetEventHandler

func (c *Client) SetEventHandler(eventHandler EventHandler)

func (*Client) SetProxy

func (c *Client) SetProxy(proxy string) error

func (*Client) SetTyping

func (c *Client) SetTyping(convID string) error

func (*Client) StartGaiaPairing

func (c *Client) StartGaiaPairing(ctx context.Context) (string, *PairingSession, error)

func (*Client) StartLogin

func (c *Client) StartLogin() (string, error)

func (*Client) StartUploadMedia

func (c *Client) StartUploadMedia(encryptedImageBytes []byte, mime string) (*StartGoogleUpload, error)

func (*Client) Unpair

func (c *Client) Unpair() (err error)

func (*Client) UnpairBugle

func (c *Client) UnpairBugle() (*gmproto.RevokeRelayPairingResponse, error)

func (*Client) UnpairGaia

func (c *Client) UnpairGaia() error

func (*Client) UpdateConversation

func (*Client) UploadMedia

func (c *Client) UploadMedia(data []byte, fileName, mime string) (*gmproto.MediaContent, error)

type EventHandler

type EventHandler func(evt any)

type GaiaPairingState

type GaiaPairingState struct {
	*PairingSession
}

type IncomingRPCMessage

type IncomingRPCMessage struct {
	*gmproto.IncomingRPCMessage

	IsOld bool

	Pair *gmproto.RPCPairData
	Gaia *gmproto.RPCGaiaData

	Message          *gmproto.RPCMessageData
	DecryptedData    []byte
	DecryptedMessage proto.Message
}

type MediaType

type MediaType struct {
	Extension string
	Format    string
	Type      gmproto.MediaFormats
}

type MediaUpload

type MediaUpload struct {
	MediaID     string
	MediaNumber int64
}

type PairingSession

type PairingSession struct {
	UUID          uuid.UUID
	Start         time.Time
	PairingKeyDSA *ecdsa.PrivateKey
	DestRegDevice primaryDeviceID
	ServerInit    *gmproto.GaiaPairingResponseContainer
	InitPayload   []byte
	FinishPayload []byte
	NextKey       []byte
}

func NewPairingSession

func NewPairingSession(destRegDevice primaryDeviceID) *PairingSession

func (*PairingSession) PreparePayloads

func (ps *PairingSession) PreparePayloads() ([]byte, []byte, error)

func (*PairingSession) ProcessServerInit

func (ps *PairingSession) ProcessServerInit(msg *gmproto.GaiaPairingResponseContainer) (string, error)

type Proxy

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

type SendMessageParams

type SendMessageParams struct {
	Action gmproto.ActionType
	Data   proto.Message

	RequestID   string
	OmitTTL     bool
	CustomTTL   int64
	DontEncrypt bool
	MessageType gmproto.MessageType
}

type SessionHandler

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

func (*SessionHandler) ResetSessionID

func (s *SessionHandler) ResetSessionID()

type StartGoogleUpload

type StartGoogleUpload struct {
	UploadID         string
	UploadURL        string
	UploadStatus     string
	ChunkGranularity int64
	ControlURL       string
	MimeType         string

	EncryptedMediaBytes []byte
}

type WrappedMessage

type WrappedMessage struct {
	*gmproto.Message
	IsOld bool
	Data  []byte
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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