diff --git a/config/config.go b/config/config.go index a308c12..f59a643 100644 --- a/config/config.go +++ b/config/config.go @@ -32,6 +32,13 @@ type Config struct { Listen string `yaml:"listen"` } `yaml:"metrics"` + GoogleMessages struct { + OS string `yaml:"os"` + Browser string `yaml:"browser"` + + AggressiveReconnect bool `yaml:"aggressive_reconnect"` + } `yaml:"google_messages"` + Bridge BridgeConfig `yaml:"bridge"` } diff --git a/config/upgrade.go b/config/upgrade.go index 2992444..3c4c65d 100644 --- a/config/upgrade.go +++ b/config/upgrade.go @@ -31,6 +31,10 @@ func DoUpgrade(helper *up.Helper) { helper.Copy(up.Bool, "metrics", "enabled") helper.Copy(up.Str, "metrics", "listen") + helper.Copy(up.Str, "google_messages", "os") + helper.Copy(up.Str, "google_messages", "browser") + helper.Copy(up.Bool, "google_messages", "aggressive_reconnect") + helper.Copy(up.Str, "bridge", "username_template") helper.Copy(up.Str, "bridge", "displayname_template") helper.Copy(up.Bool, "bridge", "personal_filtering_spaces") diff --git a/example-config.yaml b/example-config.yaml index 3c78043..8c1563d 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -88,6 +88,17 @@ metrics: # IP and port where the metrics listener should be. The path is always /metrics listen: 127.0.0.1:8001 +google_messages: + # OS name to tell the phone. This is the name that shows up in the paired devices list. + os: mautrix-gmessages + # Browser type to tell the phone. This decides which icon is shown. + # Valid types: OTHER, CHROME, FIREFOX, SAFARI, OPERA, IE, EDGE + browser: OTHER + + # Should the bridge aggressively set itself as the active device if the user opens Google Messages in a browser? + # If this is disabled, the user must manually use the `reconnect` command to reactivate the bridge. + aggressive_reconnect: false + # Bridge config bridge: # Localpart template of MXIDs for SMS users. diff --git a/libgm/payload/config.go b/libgm/payload/config.go index 97c3c02..58d70f1 100644 --- a/libgm/payload/config.go +++ b/libgm/payload/config.go @@ -15,7 +15,7 @@ var ConfigMessage = &binary.ConfigVersion{ var Network = "Bugle" var BrowserDetailsMessage = &binary.BrowserDetails{ UserAgent: util.UserAgent, - BrowserType: util.BrowserType, - Os: util.OS, + BrowserType: binary.BrowserTypes_OTHER, + Os: "libgm", SomeBool: true, } diff --git a/libgm/util/constants.go b/libgm/util/constants.go index 26f32f1..8f33680 100644 --- a/libgm/util/constants.go +++ b/libgm/util/constants.go @@ -1,13 +1,8 @@ package util -import ( - "go.mau.fi/mautrix-gmessages/libgm/binary" -) - -var BrowserType = binary.BrowserTypes_CHROME - const GoogleAPIKey = "AIzaSyCA4RsOZUFrm9whhtGosPlJLmVPnfSHKz8" const UserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36" -const OS = "Linux" +const SecUA = `"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"` +const UAPlatform = "Linux" const XUserAgent = "grpc-web-javascript/0.1" const QRCodeURLBase = "https://support.google.com/messages/?p=web_computer#?c=" diff --git a/libgm/util/func.go b/libgm/util/func.go index 844afae..5dd7a54 100644 --- a/libgm/util/func.go +++ b/libgm/util/func.go @@ -43,7 +43,7 @@ func RandomUUIDv4() string { func BuildRelayHeaders(req *http.Request, contentType string, accept string) { req.Header.Add("host", "instantmessaging-pa.googleapis.com") req.Header.Add("connection", "keep-alive") - req.Header.Add("sec-ch-ua", "\"Google Chrome\";v=\"113\", \"Chromium\";v=\"113\", \"Not-A.Brand\";v=\"24\"") + req.Header.Add("sec-ch-ua", SecUA) req.Header.Add("x-user-agent", XUserAgent) req.Header.Add("x-goog-api-key", GoogleAPIKey) if len(contentType) > 0 { @@ -51,7 +51,7 @@ func BuildRelayHeaders(req *http.Request, contentType string, accept string) { } req.Header.Add("sec-ch-ua-mobile", "?0") req.Header.Add("user-agent", UserAgent) - req.Header.Add("sec-ch-ua-platform", "\""+OS+"\"") + req.Header.Add("sec-ch-ua-platform", "\""+UAPlatform+"\"") req.Header.Add("accept", accept) req.Header.Add("origin", "https://messages.google.com") req.Header.Add("sec-fetch-site", "cross-site") @@ -65,10 +65,10 @@ func BuildUploadHeaders(req *http.Request, metadata string) { req.Header.Add("host", "instantmessaging-pa.googleapis.com") req.Header.Add("connection", "keep-alive") req.Header.Add("x-goog-download-metadata", metadata) - req.Header.Add("sec-ch-ua", "\"Google Chrome\";v=\"113\", \"Chromium\";v=\"113\", \"Not-A.Brand\";v=\"24\"") + req.Header.Add("sec-ch-ua", SecUA) req.Header.Add("sec-ch-ua-mobile", "?0") req.Header.Add("user-agent", UserAgent) - req.Header.Add("sec-ch-ua-platform", "\""+OS+"\"") + req.Header.Add("sec-ch-ua-platform", "\""+UAPlatform+"\"") req.Header.Add("accept", "*/*") req.Header.Add("origin", "https://messages.google.com") req.Header.Add("sec-fetch-site", "cross-site") @@ -84,7 +84,7 @@ func NewMediaUploadHeaders(imageSize string, command string, uploadOffset string headers.Add("host", "instantmessaging-pa.googleapis.com") headers.Add("connection", "keep-alive") - headers.Add("sec-ch-ua", "\"Google Chrome\";v=\"113\", \"Chromium\";v=\"113\", \"Not-A.Brand\";v=\"24\"") + headers.Add("sec-ch-ua", SecUA) if protocol != "" { headers.Add("x-goog-upload-protocol", protocol) } @@ -101,7 +101,7 @@ func NewMediaUploadHeaders(imageSize string, command string, uploadOffset string if uploadOffset != "" { headers.Add("x-goog-upload-offset", uploadOffset) } - headers.Add("sec-ch-ua-platform", "\""+OS+"\"") + headers.Add("sec-ch-ua-platform", "\""+UAPlatform+"\"") headers.Add("accept", "*/*") headers.Add("origin", "https://messages.google.com") headers.Add("sec-fetch-site", "cross-site") diff --git a/main.go b/main.go index e803480..99dde37 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,8 @@ import ( "go.mau.fi/mautrix-gmessages/config" "go.mau.fi/mautrix-gmessages/database" + "go.mau.fi/mautrix-gmessages/libgm/binary" + "go.mau.fi/mautrix-gmessages/libgm/payload" ) // Information to find out exactly which commit the bridge was built from. @@ -65,6 +67,14 @@ func (br *GMBridge) Init() { br.CommandProcessor = commands.NewProcessor(&br.Bridge) br.RegisterCommands() + payload.BrowserDetailsMessage.Os = br.Config.GoogleMessages.OS + browserVal, ok := binary.BrowserTypes_value[br.Config.GoogleMessages.Browser] + if !ok { + br.ZLog.Error().Str("browser_value", br.Config.GoogleMessages.Browser).Msg("Invalid browser value") + } else { + payload.BrowserDetailsMessage.BrowserType = binary.BrowserTypes(browserVal) + } + Segment.log = br.ZLog.With().Str("component", "segment").Logger() Segment.key = br.Config.SegmentKey Segment.userID = br.Config.SegmentUserID