From 9aa0894115bb3c0ea5794edbea970a6b82af3233 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 30 Jun 2023 16:31:35 +0300 Subject: [PATCH] Make constants actual constants --- libgm/payload/registerPhoneRelay.go | 2 +- libgm/qr.go | 2 +- libgm/util/constants.go | 10 +++++----- libgm/util/func.go | 10 +++++----- libgm/util/structs.go | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libgm/payload/registerPhoneRelay.go b/libgm/payload/registerPhoneRelay.go index 31d9bb2..3b08c69 100644 --- a/libgm/payload/registerPhoneRelay.go +++ b/libgm/payload/registerPhoneRelay.go @@ -43,7 +43,7 @@ func RegisterPhoneRelay(jwk *crypto.JWK) ([]byte, *binary.Container, error) { }, }, BrowserDetails: &binary.BrowserDetails{ - UserAgent: util.USER_AGENT, + UserAgent: util.UserAgent, SomeInt: 2, SomeBool: true, Os: util.OS, diff --git a/libgm/qr.go b/libgm/qr.go index 9e4dd86..0ec837e 100644 --- a/libgm/qr.go +++ b/libgm/qr.go @@ -18,5 +18,5 @@ func (p *Pairer) GenerateQRCodeData() (string, error) { return "", err } cData := base64.StdEncoding.EncodeToString(encodedUrlData) - return util.QR_CODE_URL + cData, nil + return util.QRCodeURLBase + cData, nil } diff --git a/libgm/util/constants.go b/libgm/util/constants.go index 3312fac..b547fe2 100644 --- a/libgm/util/constants.go +++ b/libgm/util/constants.go @@ -1,7 +1,7 @@ package util -var GOOG_API_KEY = "AIzaSyCA4RsOZUFrm9whhtGosPlJLmVPnfSHKz8" -var USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36" -var OS = "Linux" -var X_USER_AGENT = "grpc-web-javascript/0.1" -var QR_CODE_URL = "https://support.google.com/messages/?p=web_computer#?c=" +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 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 90c5800..7fc746a 100644 --- a/libgm/util/func.go +++ b/libgm/util/func.go @@ -64,13 +64,13 @@ 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("x-user-agent", X_USER_AGENT) - req.Header.Add("x-goog-api-key", GOOG_API_KEY) + req.Header.Add("x-user-agent", XUserAgent) + req.Header.Add("x-goog-api-key", GoogleAPIKey) if len(contentType) > 0 { req.Header.Add("content-type", contentType) } req.Header.Add("sec-ch-ua-mobile", "?0") - req.Header.Add("user-agent", USER_AGENT) + req.Header.Add("user-agent", UserAgent) req.Header.Add("sec-ch-ua-platform", "\""+OS+"\"") req.Header.Add("accept", accept) req.Header.Add("origin", "https://messages.google.com") @@ -87,7 +87,7 @@ func BuildUploadHeaders(req *http.Request, metadata string) { 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-mobile", "?0") - req.Header.Add("user-agent", USER_AGENT) + req.Header.Add("user-agent", UserAgent) req.Header.Add("sec-ch-ua-platform", "\""+OS+"\"") req.Header.Add("accept", "*/*") req.Header.Add("origin", "https://messages.google.com") @@ -110,7 +110,7 @@ func NewMediaUploadHeaders(imageSize string, command string, uploadOffset string } headers.Add("x-goog-upload-header-content-length", imageSize) headers.Add("sec-ch-ua-mobile", "?0") - headers.Add("user-agent", USER_AGENT) + headers.Add("user-agent", UserAgent) if imageContentType != "" { headers.Add("x-goog-upload-header-content-type", imageContentType) } diff --git a/libgm/util/structs.go b/libgm/util/structs.go index f1f5b54..86eff61 100644 --- a/libgm/util/structs.go +++ b/libgm/util/structs.go @@ -32,7 +32,7 @@ func (h *Headers) Build() { h.SecChUaMobile = "?0" h.SecChUaPlatform = `"Linux"` h.UpgradeInsecureRequests = "1" - h.UserAgent = USER_AGENT + h.UserAgent = UserAgent h.Accept = `text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7` h.SecFetchSite = "none" h.SecFetchMode = "navigate"