Unnest device pair info in AuthData

This commit is contained in:
Tulir Asokan 2023-07-16 14:40:28 +03:00
parent 3fefda3a96
commit 7fe4f0b047
6 changed files with 16 additions and 15 deletions

View file

@ -32,7 +32,8 @@ type AuthData struct {
// 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
DevicePair *pblite.DevicePair `json:"device_pair,omitempty"`
Browser *binary.Device `json:"browser,omitempty"`
Mobile *binary.Device `json:"mobile,omitempty"`
// Key used to authenticate with the server
TachyonAuthToken []byte `json:"tachyon_token,omitempty"`
TachyonExpiry time.Time `json:"tachyon_expiry,omitempty"`
@ -153,7 +154,7 @@ func (c *Client) IsConnected() bool {
}
func (c *Client) IsLoggedIn() bool {
return c.authData != nil && c.authData.DevicePair != nil
return c.authData != nil && c.authData.Browser != nil
}
func (c *Client) Reconnect() error {
@ -270,9 +271,10 @@ func (c *Client) updateTachyonAuthToken(t []byte, validFor int64) {
c.Logger.Debug().Time("tachyon_expiry", c.authData.TachyonExpiry).Int64("valid_for", validFor).Msg("Updated tachyon token")
}
func (c *Client) updateDevicePair(devicePair *pblite.DevicePair) {
c.authData.DevicePair = devicePair
c.Logger.Debug().Any("devicePair", devicePair).Msg("Updated DevicePair")
func (c *Client) updateDevicePair(mobile, browser *binary.Device) {
c.authData.Mobile = mobile
c.authData.Browser = browser
c.Logger.Debug().Any("mobile", mobile).Any("browser", browser).Msg("Updated device pair")
}
func (c *Client) SaveAuthSession(path string) error {
@ -300,7 +302,7 @@ func LoadAuthSession(path string) (*AuthData, error) {
}
func (c *Client) refreshAuthToken() error {
if c.authData.DevicePair == nil || time.Until(c.authData.TachyonExpiry) > RefreshTachyonBuffer {
if c.authData.Browser == nil || time.Until(c.authData.TachyonExpiry) > RefreshTachyonBuffer {
return nil
}
c.Logger.Debug().Time("tachyon_expiry", c.authData.TachyonExpiry).Msg("Refreshing auth token")
@ -320,7 +322,7 @@ func (c *Client) refreshAuthToken() error {
TachyonAuthToken: c.authData.TachyonAuthToken,
ConfigVersion: payload.ConfigMessage,
},
CurrBrowserDevice: c.authData.DevicePair.Browser,
CurrBrowserDevice: c.authData.Browser,
UnixTimestamp: timestamp,
Signature: sig,
EmptyRefreshArr: &binary.EmptyRefreshArr{EmptyArr: &binary.EmptyArr{}},

View file

@ -134,7 +134,7 @@ func (c *Client) buildStartUploadPayload() (string, error) {
TachyonAuthToken: c.authData.TachyonAuthToken,
ConfigVersion: payload.ConfigMessage,
},
Mobile: c.authData.DevicePair.Mobile,
Mobile: c.authData.Mobile,
}
protoDataBytes, err := proto.Marshal(protoData)

View file

@ -169,7 +169,7 @@ func (c *Client) GetWebEncryptionKey() (*binary.WebEncryptionKeyResponse, error)
}
func (c *Client) Unpair() (*binary.RevokeRelayPairingResponse, error) {
if c.authData.TachyonAuthToken == nil || c.authData.DevicePair == nil || c.authData.DevicePair.Browser == nil {
if c.authData.TachyonAuthToken == nil || c.authData.Browser == nil {
return nil, nil
}
payload, err := proto.Marshal(&binary.RevokeRelayPairing{
@ -178,7 +178,7 @@ func (c *Client) Unpair() (*binary.RevokeRelayPairingResponse, error) {
TachyonAuthToken: c.authData.TachyonAuthToken,
ConfigVersion: payload.ConfigMessage,
},
Browser: c.authData.DevicePair.Browser,
Browser: c.authData.Browser,
})
if err != nil {
return nil, err

View file

@ -41,8 +41,7 @@ func (c *Client) pairCallback(data *binary.PairedData) error {
tokenData := data.GetTokenData()
c.updateTachyonAuthToken(tokenData.GetTachyonAuthToken(), tokenData.GetTTL())
devicePair := c.NewDevicePair(data.Mobile, data.Browser)
c.updateDevicePair(devicePair)
c.updateDevicePair(data.Mobile, data.Browser)
webEncryptionKeyResponse, webErr := c.GetWebEncryptionKey()
if webErr != nil {

View file

@ -91,7 +91,7 @@ func (r *RPC) ListenReceiveMessages() {
}
r.client.Logger.Debug().Int("statusCode", resp.StatusCode).Msg("Long polling opened")
r.conn = resp.Body
if r.client.authData.DevicePair != nil {
if r.client.authData.Browser != nil {
go func() {
err := r.client.NotifyDittoActivity()
if err != nil {

View file

@ -73,7 +73,7 @@ func (s *SessionHandler) sendMessage(actionType binary.ActionType, encryptedData
func (s *SessionHandler) buildMessage(actionType binary.ActionType, encryptedData proto.Message) (string, []byte, binary.ActionType, error) {
var requestID string
pairedDevice := s.client.authData.DevicePair.Mobile
pairedDevice := s.client.authData.Mobile
sessionId := s.client.sessionHandler.sessionID
token := s.client.authData.TachyonAuthToken
@ -142,7 +142,7 @@ func (s *SessionHandler) sendAckRequest() {
for i, reqID := range dataToAck {
ackMessages[i] = &binary.AckMessageData{
RequestID: reqID,
Device: s.client.authData.DevicePair.Browser,
Device: s.client.authData.Browser,
}
}
ackMessagePayload := &binary.AckMessagePayload{