Skip to content

Commit

Permalink
Add support for unpairing google logins
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Feb 23, 2024
1 parent ca15922 commit 49a3fd9
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 207 deletions.
2 changes: 2 additions & 0 deletions libgm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type AuthData struct {
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"`
}

Expand Down
458 changes: 259 additions & 199 deletions libgm/gmproto/authentication.pb.go

Large diffs are not rendered by default.

Binary file modified libgm/gmproto/authentication.pb.raw
Binary file not shown.
6 changes: 5 additions & 1 deletion libgm/gmproto/authentication.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ message SignInGaiaResponse {
}

message GaiaPairingRequestContainer {
string pairingUUID = 1;
string pairingAttemptID = 1;
BrowserDetails browserDetails = 2;
int64 startTimestamp = 3;
bytes data = 4;
Expand All @@ -98,6 +98,10 @@ message GaiaPairingResponseContainer {
bytes data = 5;
}

message RevokeGaiaPairingRequest {
string pairingAttemptID = 1;
}

message RPCGaiaData {
message UnknownContainer {
message Item2 {
Expand Down
1 change: 0 additions & 1 deletion libgm/gmtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func main() {
}
_ = file.Close()
cli = libgm.NewClient(&sess, log)
log.Info().Str("device_id", sess.SessionID.String()).Msg("meow")
cli.SetEventHandler(evtHandler)
if doLogin {
err = cli.DoGaiaPairing(func(emoji string) {
Expand Down
11 changes: 10 additions & 1 deletion libgm/pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (c *Client) GetWebEncryptionKey() (*gmproto.WebEncryptionKeyResponse, error
)
}

func (c *Client) Unpair() (*gmproto.RevokeRelayPairingResponse, error) {
func (c *Client) UnpairBugle() (*gmproto.RevokeRelayPairingResponse, error) {
if c.AuthData.TachyonAuthToken == nil || c.AuthData.Browser == nil {
return nil, nil
}
Expand All @@ -150,3 +150,12 @@ func (c *Client) Unpair() (*gmproto.RevokeRelayPairingResponse, error) {
c.makeProtobufHTTPRequest(util.RevokeRelayPairingURL, payload, ContentTypeProtobuf),
)
}

func (c *Client) Unpair() (err error) {
if c.AuthData.Cookies != nil {
err = c.UnpairGaia()
} else {
_, err = c.UnpairBugle()
}
return
}
21 changes: 17 additions & 4 deletions libgm/pair_google.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func (c *Client) DoGaiaPairing(emojiCallback func(string)) error {
if err != nil {
return fmt.Errorf("failed to parse destination UUID: %w", err)
}
c.AuthData.DestRegID = destRegUUID
go c.doLongPoll(false)
ps := NewPairingSession(destRegUUID)
clientInit, clientFinish, err := ps.PreparePayloads()
Expand Down Expand Up @@ -297,6 +298,7 @@ func (c *Client) DoGaiaPairing(emojiCallback func(string)) error {
}
c.AuthData.RequestCrypto.AESKey = doHKDF(ps.NextKey, encryptionKeyInfo, []byte("client"))
c.AuthData.RequestCrypto.HMACKey = doHKDF(ps.NextKey, encryptionKeyInfo, []byte("server"))
c.AuthData.PairingID = ps.UUID
c.triggerEvent(&events.PairSuccessful{})

go func() {
Expand All @@ -316,10 +318,10 @@ func (c *Client) sendGaiaPairingMessage(sess PairingSession, action gmproto.Acti
resp, err := c.sessionHandler.sendMessageWithParams(SendMessageParams{
Action: action,
Data: &gmproto.GaiaPairingRequestContainer{
PairingUUID: sess.UUID.String(),
BrowserDetails: util.BrowserDetailsMessage,
StartTimestamp: sess.Start.UnixMilli(),
Data: msg,
PairingAttemptID: sess.UUID.String(),
BrowserDetails: util.BrowserDetailsMessage,
StartTimestamp: sess.Start.UnixMilli(),
Data: msg,
},
DontEncrypt: true,
CustomTTL: (300 * time.Second).Microseconds(),
Expand All @@ -338,3 +340,14 @@ func (c *Client) sendGaiaPairingMessage(sess PairingSession, action gmproto.Acti
}
return &respDat, nil
}

func (c *Client) UnpairGaia() error {
return c.sessionHandler.sendMessageNoResponse(SendMessageParams{
Action: gmproto.ActionType_UNPAIR_GAIA_PAIRING,
Data: &gmproto.RevokeGaiaPairingRequest{
PairingAttemptID: c.AuthData.PairingID.String(),
},
DestRegistrationIDs: []string{c.AuthData.DestRegID.String()},
NoPingOnTimeout: true,
})
}
2 changes: 1 addition & 1 deletion user.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ func (user *User) FillBridgeState(state status.BridgeState) status.BridgeState {

func (user *User) Logout(state status.BridgeState, unpair bool) (logoutOK bool) {
if user.Client != nil && unpair {
_, err := user.Client.Unpair()
err := user.Client.Unpair()
if err != nil {
user.zlog.Debug().Err(err).Msg("Error sending unpair request")
} else {
Expand Down

0 comments on commit 49a3fd9

Please sign in to comment.