Remove more unused utility functions
This commit is contained in:
parent
1f8ea3ddda
commit
360fe208a8
7 changed files with 14 additions and 148 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
|
@ -195,14 +196,13 @@ func (c *Client) triggerEvent(evt interface{}) {
|
|||
}
|
||||
|
||||
func (c *Client) DownloadMedia(mediaID string, key []byte) ([]byte, error) {
|
||||
reqId := util.RandomUUIDv4()
|
||||
downloadMetadata := &binary.UploadImagePayload{
|
||||
MetaData: &binary.ImageMetaData{
|
||||
ImageID: mediaID,
|
||||
Encrypted: true,
|
||||
},
|
||||
AuthData: &binary.AuthMessage{
|
||||
RequestID: reqId,
|
||||
RequestID: uuid.NewString(),
|
||||
TachyonAuthToken: c.authData.TachyonAuthToken,
|
||||
ConfigVersion: payload.ConfigMessage,
|
||||
},
|
||||
|
@ -330,15 +330,15 @@ func (c *Client) RefreshAuthToken() error {
|
|||
|
||||
func (c *Client) refreshAuthToken() error {
|
||||
jwk := c.authData.JWK
|
||||
requestId := util.RandomUUIDv4()
|
||||
requestID := uuid.NewString()
|
||||
timestamp := time.Now().UnixMilli() * 1000
|
||||
|
||||
sig, sigErr := jwk.SignRequest(requestId, int64(timestamp))
|
||||
sig, sigErr := jwk.SignRequest(requestID, int64(timestamp))
|
||||
if sigErr != nil {
|
||||
return sigErr
|
||||
}
|
||||
|
||||
payloadMessage, messageErr := payload.RegisterRefresh(sig, requestId, int64(timestamp), c.authData.DevicePair.Browser, c.authData.TachyonAuthToken)
|
||||
payloadMessage, messageErr := payload.RegisterRefresh(sig, requestID, int64(timestamp), c.authData.DevicePair.Browser, c.authData.TachyonAuthToken)
|
||||
if messageErr != nil {
|
||||
return messageErr
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"go.mau.fi/mautrix-gmessages/libgm/binary"
|
||||
|
@ -126,11 +127,10 @@ func (c *Client) StartUploadMedia(encryptedImageBytes []byte, mime string) (*Sta
|
|||
}
|
||||
|
||||
func (c *Client) buildStartUploadPayload() (string, error) {
|
||||
requestID := util.RandomUUIDv4()
|
||||
protoData := &binary.StartMediaUploadPayload{
|
||||
ImageType: 1,
|
||||
AuthData: &binary.AuthMessage{
|
||||
RequestID: requestID,
|
||||
RequestID: uuid.NewString(),
|
||||
TachyonAuthToken: c.authData.TachyonAuthToken,
|
||||
ConfigVersion: payload.ConfigMessage,
|
||||
},
|
||||
|
|
|
@ -92,7 +92,7 @@ func (p *Pairer) startRefreshRelayTask() {
|
|||
func (p *Pairer) RefreshPhoneRelay() {
|
||||
body, err := proto.Marshal(&binary.AuthenticationContainer{
|
||||
AuthMessage: &binary.AuthMessage{
|
||||
RequestID: util.RandomUUIDv4(),
|
||||
RequestID: uuid.NewString(),
|
||||
Network: &payload.Network,
|
||||
TachyonAuthToken: p.client.authData.TachyonAuthToken,
|
||||
ConfigVersion: payload.ConfigMessage,
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package payload
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"go.mau.fi/mautrix-gmessages/libgm/binary"
|
||||
"go.mau.fi/mautrix-gmessages/libgm/crypto"
|
||||
"go.mau.fi/mautrix-gmessages/libgm/util"
|
||||
)
|
||||
|
||||
func RegisterPhoneRelay(jwk *crypto.JWK) ([]byte, *binary.AuthenticationContainer, error) {
|
||||
id := util.RandomUUIDv4()
|
||||
|
||||
key, err := jwk.MarshalX509PublicKey()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
@ -18,7 +16,7 @@ func RegisterPhoneRelay(jwk *crypto.JWK) ([]byte, *binary.AuthenticationContaine
|
|||
|
||||
payloadData := &binary.AuthenticationContainer{
|
||||
AuthMessage: &binary.AuthMessage{
|
||||
RequestID: id,
|
||||
RequestID: uuid.NewString(),
|
||||
Network: &Network,
|
||||
ConfigVersion: ConfigMessage,
|
||||
},
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/exp/slices"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
|
@ -32,7 +33,7 @@ type SessionHandler struct {
|
|||
}
|
||||
|
||||
func (s *SessionHandler) ResetSessionID() {
|
||||
s.sessionID = util.RandomUUIDv4()
|
||||
s.sessionID = uuid.NewString()
|
||||
}
|
||||
|
||||
func (s *SessionHandler) sendMessageNoResponse(actionType binary.ActionType, encryptedData proto.Message) error {
|
||||
|
@ -84,7 +85,7 @@ func (s *SessionHandler) buildMessage(actionType binary.ActionType, encryptedDat
|
|||
if routeInfo.UseSessionID {
|
||||
requestID = s.sessionID
|
||||
} else {
|
||||
requestID = util.RandomUUIDv4()
|
||||
requestID = uuid.NewString()
|
||||
}
|
||||
|
||||
tmpMessage := payload.NewSendMessageBuilder(token, pairedDevice, requestID, sessionId).SetRoute(routeInfo.Action).SetSessionId(s.sessionID)
|
||||
|
@ -146,7 +147,7 @@ func (s *SessionHandler) sendAckRequest() {
|
|||
}
|
||||
ackMessagePayload := &binary.AckMessagePayload{
|
||||
AuthData: &binary.AuthMessage{
|
||||
RequestID: util.RandomUUIDv4(),
|
||||
RequestID: uuid.NewString(),
|
||||
TachyonAuthToken: s.client.authData.TachyonAuthToken,
|
||||
ConfigVersion: payload.ConfigMessage,
|
||||
},
|
||||
|
|
|
@ -8,27 +8,9 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"go.mau.fi/mautrix-gmessages/libgm/binary"
|
||||
)
|
||||
|
||||
var Charset = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
|
||||
|
||||
func RandStr(length int) string {
|
||||
b := make([]rune, length)
|
||||
for i := range b {
|
||||
b[i] = Charset[rand.Intn(len(Charset))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func GenerateImageID() string {
|
||||
part1 := RandomUUIDv4()
|
||||
part2 := RandStr(25)
|
||||
return part1 + "/" + part2
|
||||
}
|
||||
|
||||
func GenerateTmpID() string {
|
||||
src := rand.NewSource(time.Now().UnixNano())
|
||||
r := rand.New(src)
|
||||
|
@ -36,10 +18,6 @@ func GenerateTmpID() string {
|
|||
return fmt.Sprintf("tmp_%012d", randNum)
|
||||
}
|
||||
|
||||
func RandomUUIDv4() string {
|
||||
return uuid.New().String()
|
||||
}
|
||||
|
||||
func BuildRelayHeaders(req *http.Request, contentType string, accept string) {
|
||||
req.Header.Add("host", "instantmessaging-pa.googleapis.com")
|
||||
req.Header.Add("connection", "keep-alive")
|
||||
|
|
|
@ -1,111 +0,0 @@
|
|||
package util
|
||||
|
||||
import "go.mau.fi/mautrix-gmessages/libgm/binary"
|
||||
|
||||
type SessionResponse struct {
|
||||
Success bool
|
||||
Settings *binary.Settings
|
||||
}
|
||||
|
||||
type Headers struct {
|
||||
Host string `json:"host,omitempty" header:"host"`
|
||||
Connection string `json:"connection,omitempty" header:"connection"`
|
||||
SecChUa string `json:"sec-ch-ua,omitempty" header:"sec-ch-ua"`
|
||||
SecChUaMobile string `json:"sec-ch-ua-mobile,omitempty" header:"sec-ch-ua-mobile"`
|
||||
SecChUaPlatform string `json:"sec-ch-ua-platform,omitempty" header:"sec-ch-ua-platform"`
|
||||
UpgradeInsecureRequests string `json:"upgrade-insecure-requests,omitempty" header:"upgrade-insecure-requests"`
|
||||
UserAgent string `json:"user-agent,omitempty" header:"user-agent"`
|
||||
Accept string `json:"accept,omitempty" header:"accept"`
|
||||
Cookie string `json:"cookie,omitempty" header:"cookie"`
|
||||
Referer string `json:"referer,omitempty" header:"referer"`
|
||||
SecFetchSite string `json:"sec-fetch-site,omitempty" header:"sec-fetch-site"`
|
||||
SecFetchMode string `json:"sec-fetch-mode,omitempty" header:"sec-fetch-mode"`
|
||||
SecFetchUser string `json:"sec-fetch-user,omitempty" header:"sec-fetch-user"`
|
||||
SecFetchDest string `json:"sec-fetch-dest,omitempty" header:"sec-fetch-dest"`
|
||||
AcceptEncoding string `json:"accept-encoding,omitempty" header:"accept-encoding"`
|
||||
AcceptLanguage string `json:"accept-language,omitempty" header:"accept-language"`
|
||||
}
|
||||
|
||||
func (h *Headers) Build() {
|
||||
h.Connection = "keep-alive"
|
||||
h.SecChUa = `"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"`
|
||||
h.SecChUaMobile = "?0"
|
||||
h.SecChUaPlatform = `"Linux"`
|
||||
h.UpgradeInsecureRequests = "1"
|
||||
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"
|
||||
h.SecFetchUser = "?1"
|
||||
h.SecFetchDest = "document"
|
||||
h.AcceptEncoding = "gzip, deflate, br"
|
||||
h.AcceptLanguage = "en-US,en;q=0.9"
|
||||
}
|
||||
|
||||
func (h *Headers) SetReferer(referer string) {
|
||||
h.Referer = referer
|
||||
}
|
||||
|
||||
func (h *Headers) SetSecFetchSite(val string) {
|
||||
h.SecFetchSite = val
|
||||
}
|
||||
|
||||
func (h *Headers) SetSecFetchUser(val string) {
|
||||
h.SecFetchUser = val
|
||||
}
|
||||
|
||||
func (h *Headers) SetSecFetchDest(val string) {
|
||||
h.SecFetchDest = val
|
||||
}
|
||||
|
||||
func (h *Headers) SetUpgradeInsecureRequests(val string) {
|
||||
h.UpgradeInsecureRequests = val
|
||||
}
|
||||
|
||||
func (h *Headers) SetAccept(val string) {
|
||||
h.Accept = val
|
||||
}
|
||||
|
||||
type RelayHeaders struct {
|
||||
Host string `json:"host,omitempty"`
|
||||
Connection string `json:"connection,omitempty"`
|
||||
SecChUa string `json:"sec-ch-ua,omitempty"`
|
||||
XUserAgent string `json:"x-user-agent,omitempty"`
|
||||
XGoogAPIKey string `json:"x-goog-api-key,omitempty"`
|
||||
ContentType string `json:"content-type,omitempty"`
|
||||
SecChUaMobile string `json:"sec-ch-ua-mobile,omitempty"`
|
||||
UserAgent string `json:"user-agent,omitempty"`
|
||||
SecChUaPlatform string `json:"sec-ch-ua-platform,omitempty"`
|
||||
Accept string `json:"accept,omitempty"`
|
||||
Origin string `json:"origin,omitempty"`
|
||||
XClientData string `json:"x-client-data,omitempty"`
|
||||
SecFetchSite string `json:"sec-fetch-site,omitempty"`
|
||||
SecFetchMode string `json:"sec-fetch-mode,omitempty"`
|
||||
SecFetchDest string `json:"sec-fetch-dest,omitempty"`
|
||||
Referer string `json:"referer,omitempty"`
|
||||
AcceptEncoding string `json:"accept-encoding,omitempty"`
|
||||
AcceptLanguage string `json:"accept-language,omitempty"`
|
||||
}
|
||||
|
||||
type MediaUploadHeaders struct {
|
||||
Host string `json:"host"`
|
||||
Connection string `json:"connection"`
|
||||
SecChUa string `json:"sec-ch-ua"`
|
||||
XGoogUploadProtocol string `json:"x-goog-upload-protocol"`
|
||||
XGoogUploadHeaderContentLength string `json:"x-goog-upload-header-content-length"`
|
||||
SecChUaMobile string `json:"sec-ch-ua-mobile"`
|
||||
UserAgent string `json:"user-agent"`
|
||||
XGoogUploadHeaderContentType string `json:"x-goog-upload-header-content-type"`
|
||||
ContentType string `json:"content-type"`
|
||||
XGoogUploadCommand string `json:"x-goog-upload-command"`
|
||||
SecChUaPlatform string `json:"sec-ch-ua-platform"`
|
||||
Accept string `json:"accept"`
|
||||
Origin string `json:"origin"`
|
||||
XClientData string `json:"x-client-data"`
|
||||
SecFetchSite string `json:"sec-fetch-site"`
|
||||
SecFetchMode string `json:"sec-fetch-mode"`
|
||||
SecFetchDest string `json:"sec-fetch-dest"`
|
||||
Referer string `json:"referer"`
|
||||
AcceptEncoding string `json:"accept-encoding"`
|
||||
AcceptLanguage string `json:"accept-language"`
|
||||
}
|
Loading…
Reference in a new issue