Unnest device pair info in AuthData
This commit is contained in:
parent
3fefda3a96
commit
7fe4f0b047
6 changed files with 16 additions and 15 deletions
|
@ -32,7 +32,8 @@ type AuthData struct {
|
||||||
// Key used to sign requests to refresh the tachyon auth token from the server
|
// Key used to sign requests to refresh the tachyon auth token from the server
|
||||||
RefreshKey *crypto.JWK `json:"refresh_key,omitempty"`
|
RefreshKey *crypto.JWK `json:"refresh_key,omitempty"`
|
||||||
// Identity of the paired phone and browser
|
// 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
|
// Key used to authenticate with the server
|
||||||
TachyonAuthToken []byte `json:"tachyon_token,omitempty"`
|
TachyonAuthToken []byte `json:"tachyon_token,omitempty"`
|
||||||
TachyonExpiry time.Time `json:"tachyon_expiry,omitempty"`
|
TachyonExpiry time.Time `json:"tachyon_expiry,omitempty"`
|
||||||
|
@ -153,7 +154,7 @@ func (c *Client) IsConnected() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) IsLoggedIn() 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 {
|
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")
|
c.Logger.Debug().Time("tachyon_expiry", c.authData.TachyonExpiry).Int64("valid_for", validFor).Msg("Updated tachyon token")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) updateDevicePair(devicePair *pblite.DevicePair) {
|
func (c *Client) updateDevicePair(mobile, browser *binary.Device) {
|
||||||
c.authData.DevicePair = devicePair
|
c.authData.Mobile = mobile
|
||||||
c.Logger.Debug().Any("devicePair", devicePair).Msg("Updated DevicePair")
|
c.authData.Browser = browser
|
||||||
|
c.Logger.Debug().Any("mobile", mobile).Any("browser", browser).Msg("Updated device pair")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) SaveAuthSession(path string) error {
|
func (c *Client) SaveAuthSession(path string) error {
|
||||||
|
@ -300,7 +302,7 @@ func LoadAuthSession(path string) (*AuthData, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) refreshAuthToken() 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
|
return nil
|
||||||
}
|
}
|
||||||
c.Logger.Debug().Time("tachyon_expiry", c.authData.TachyonExpiry).Msg("Refreshing auth token")
|
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,
|
TachyonAuthToken: c.authData.TachyonAuthToken,
|
||||||
ConfigVersion: payload.ConfigMessage,
|
ConfigVersion: payload.ConfigMessage,
|
||||||
},
|
},
|
||||||
CurrBrowserDevice: c.authData.DevicePair.Browser,
|
CurrBrowserDevice: c.authData.Browser,
|
||||||
UnixTimestamp: timestamp,
|
UnixTimestamp: timestamp,
|
||||||
Signature: sig,
|
Signature: sig,
|
||||||
EmptyRefreshArr: &binary.EmptyRefreshArr{EmptyArr: &binary.EmptyArr{}},
|
EmptyRefreshArr: &binary.EmptyRefreshArr{EmptyArr: &binary.EmptyArr{}},
|
||||||
|
|
|
@ -134,7 +134,7 @@ func (c *Client) buildStartUploadPayload() (string, error) {
|
||||||
TachyonAuthToken: c.authData.TachyonAuthToken,
|
TachyonAuthToken: c.authData.TachyonAuthToken,
|
||||||
ConfigVersion: payload.ConfigMessage,
|
ConfigVersion: payload.ConfigMessage,
|
||||||
},
|
},
|
||||||
Mobile: c.authData.DevicePair.Mobile,
|
Mobile: c.authData.Mobile,
|
||||||
}
|
}
|
||||||
|
|
||||||
protoDataBytes, err := proto.Marshal(protoData)
|
protoDataBytes, err := proto.Marshal(protoData)
|
||||||
|
|
|
@ -169,7 +169,7 @@ func (c *Client) GetWebEncryptionKey() (*binary.WebEncryptionKeyResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Unpair() (*binary.RevokeRelayPairingResponse, 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
|
return nil, nil
|
||||||
}
|
}
|
||||||
payload, err := proto.Marshal(&binary.RevokeRelayPairing{
|
payload, err := proto.Marshal(&binary.RevokeRelayPairing{
|
||||||
|
@ -178,7 +178,7 @@ func (c *Client) Unpair() (*binary.RevokeRelayPairingResponse, error) {
|
||||||
TachyonAuthToken: c.authData.TachyonAuthToken,
|
TachyonAuthToken: c.authData.TachyonAuthToken,
|
||||||
ConfigVersion: payload.ConfigMessage,
|
ConfigVersion: payload.ConfigMessage,
|
||||||
},
|
},
|
||||||
Browser: c.authData.DevicePair.Browser,
|
Browser: c.authData.Browser,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -41,8 +41,7 @@ func (c *Client) pairCallback(data *binary.PairedData) error {
|
||||||
tokenData := data.GetTokenData()
|
tokenData := data.GetTokenData()
|
||||||
c.updateTachyonAuthToken(tokenData.GetTachyonAuthToken(), tokenData.GetTTL())
|
c.updateTachyonAuthToken(tokenData.GetTachyonAuthToken(), tokenData.GetTTL())
|
||||||
|
|
||||||
devicePair := c.NewDevicePair(data.Mobile, data.Browser)
|
c.updateDevicePair(data.Mobile, data.Browser)
|
||||||
c.updateDevicePair(devicePair)
|
|
||||||
|
|
||||||
webEncryptionKeyResponse, webErr := c.GetWebEncryptionKey()
|
webEncryptionKeyResponse, webErr := c.GetWebEncryptionKey()
|
||||||
if webErr != nil {
|
if webErr != nil {
|
||||||
|
|
|
@ -91,7 +91,7 @@ func (r *RPC) ListenReceiveMessages() {
|
||||||
}
|
}
|
||||||
r.client.Logger.Debug().Int("statusCode", resp.StatusCode).Msg("Long polling opened")
|
r.client.Logger.Debug().Int("statusCode", resp.StatusCode).Msg("Long polling opened")
|
||||||
r.conn = resp.Body
|
r.conn = resp.Body
|
||||||
if r.client.authData.DevicePair != nil {
|
if r.client.authData.Browser != nil {
|
||||||
go func() {
|
go func() {
|
||||||
err := r.client.NotifyDittoActivity()
|
err := r.client.NotifyDittoActivity()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -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) {
|
func (s *SessionHandler) buildMessage(actionType binary.ActionType, encryptedData proto.Message) (string, []byte, binary.ActionType, error) {
|
||||||
var requestID string
|
var requestID string
|
||||||
pairedDevice := s.client.authData.DevicePair.Mobile
|
pairedDevice := s.client.authData.Mobile
|
||||||
sessionId := s.client.sessionHandler.sessionID
|
sessionId := s.client.sessionHandler.sessionID
|
||||||
token := s.client.authData.TachyonAuthToken
|
token := s.client.authData.TachyonAuthToken
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ func (s *SessionHandler) sendAckRequest() {
|
||||||
for i, reqID := range dataToAck {
|
for i, reqID := range dataToAck {
|
||||||
ackMessages[i] = &binary.AckMessageData{
|
ackMessages[i] = &binary.AckMessageData{
|
||||||
RequestID: reqID,
|
RequestID: reqID,
|
||||||
Device: s.client.authData.DevicePair.Browser,
|
Device: s.client.authData.Browser,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ackMessagePayload := &binary.AckMessagePayload{
|
ackMessagePayload := &binary.AckMessagePayload{
|
||||||
|
|
Loading…
Reference in a new issue