Move start login methods to pair.go
This commit is contained in:
parent
b46885ad58
commit
6caf7e89fb
2 changed files with 29 additions and 30 deletions
|
@ -4,7 +4,6 @@ import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -14,7 +13,6 @@ import (
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"google.golang.org/protobuf/proto"
|
|
||||||
|
|
||||||
"go.mau.fi/mautrix-gmessages/libgm/crypto"
|
"go.mau.fi/mautrix-gmessages/libgm/crypto"
|
||||||
"go.mau.fi/mautrix-gmessages/libgm/events"
|
"go.mau.fi/mautrix-gmessages/libgm/events"
|
||||||
|
@ -133,34 +131,6 @@ func (c *Client) Connect() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) StartLogin() (string, error) {
|
|
||||||
registered, err := c.RegisterPhoneRelay()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
c.AuthData.TachyonAuthToken = registered.AuthKeyData.TachyonAuthToken
|
|
||||||
go c.rpc.ListenReceiveMessages(false)
|
|
||||||
qr, err := c.GenerateQRCodeData(registered.GetPairingKey())
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("failed to generate QR code: %w", err)
|
|
||||||
}
|
|
||||||
return qr, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) GenerateQRCodeData(pairingKey []byte) (string, error) {
|
|
||||||
urlData := &gmproto.URLData{
|
|
||||||
PairingKey: pairingKey,
|
|
||||||
AESKey: c.AuthData.RequestCrypto.AESKey,
|
|
||||||
HMACKey: c.AuthData.RequestCrypto.HMACKey,
|
|
||||||
}
|
|
||||||
encodedURLData, err := proto.Marshal(urlData)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
cData := base64.StdEncoding.EncodeToString(encodedURLData)
|
|
||||||
return util.QRCodeURLBase + cData, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) Disconnect() {
|
func (c *Client) Disconnect() {
|
||||||
c.rpc.CloseConnection()
|
c.rpc.CloseConnection()
|
||||||
c.http.CloseIdleConnections()
|
c.http.CloseIdleConnections()
|
||||||
|
|
|
@ -3,6 +3,7 @@ package libgm
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -15,6 +16,34 @@ import (
|
||||||
"go.mau.fi/mautrix-gmessages/libgm/util"
|
"go.mau.fi/mautrix-gmessages/libgm/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (c *Client) StartLogin() (string, error) {
|
||||||
|
registered, err := c.RegisterPhoneRelay()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
c.AuthData.TachyonAuthToken = registered.AuthKeyData.TachyonAuthToken
|
||||||
|
go c.rpc.ListenReceiveMessages(false)
|
||||||
|
qr, err := c.GenerateQRCodeData(registered.GetPairingKey())
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to generate QR code: %w", err)
|
||||||
|
}
|
||||||
|
return qr, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) GenerateQRCodeData(pairingKey []byte) (string, error) {
|
||||||
|
urlData := &gmproto.URLData{
|
||||||
|
PairingKey: pairingKey,
|
||||||
|
AESKey: c.AuthData.RequestCrypto.AESKey,
|
||||||
|
HMACKey: c.AuthData.RequestCrypto.HMACKey,
|
||||||
|
}
|
||||||
|
encodedURLData, err := proto.Marshal(urlData)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
cData := base64.StdEncoding.EncodeToString(encodedURLData)
|
||||||
|
return util.QRCodeURLBase + cData, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) handlePairingEvent(msg *IncomingRPCMessage) {
|
func (c *Client) handlePairingEvent(msg *IncomingRPCMessage) {
|
||||||
switch evt := msg.Pair.Event.(type) {
|
switch evt := msg.Pair.Event.(type) {
|
||||||
case *gmproto.RPCPairData_Paired:
|
case *gmproto.RPCPairData_Paired:
|
||||||
|
|
Loading…
Reference in a new issue