2023-06-30 09:54:08 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
2023-07-15 17:43:28 +00:00
|
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
|
2023-06-30 09:54:08 +00:00
|
|
|
"go.mau.fi/mautrix-gmessages/libgm/binary"
|
|
|
|
"go.mau.fi/mautrix-gmessages/libgm/crypto"
|
|
|
|
"go.mau.fi/mautrix-gmessages/libgm/util"
|
|
|
|
)
|
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
func RegisterPhoneRelay(jwk *crypto.JWK) ([]byte, *binary.AuthenticationContainer, error) {
|
2023-06-30 09:54:08 +00:00
|
|
|
id := util.RandomUUIDv4()
|
2023-07-09 11:16:52 +00:00
|
|
|
|
2023-07-15 23:35:35 +00:00
|
|
|
key, err := jwk.MarshalX509PublicKey()
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
payloadData := &binary.AuthenticationContainer{
|
2023-07-15 22:56:11 +00:00
|
|
|
AuthMessage: &binary.AuthMessage{
|
2023-07-09 11:16:52 +00:00
|
|
|
RequestID: id,
|
2023-07-15 22:56:11 +00:00
|
|
|
Network: &Network,
|
2023-07-09 11:16:52 +00:00
|
|
|
ConfigVersion: ConfigMessage,
|
|
|
|
},
|
|
|
|
BrowserDetails: BrowserDetailsMessage,
|
|
|
|
Data: &binary.AuthenticationContainer_KeyData{
|
|
|
|
KeyData: &binary.KeyData{
|
|
|
|
EcdsaKeys: &binary.ECDSAKeys{
|
|
|
|
Field1: 2,
|
2023-07-15 23:35:35 +00:00
|
|
|
EncryptedKeys: key,
|
2023-07-09 11:16:52 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-07-15 17:43:28 +00:00
|
|
|
encoded, err4 := proto.Marshal(payloadData)
|
2023-07-09 11:16:52 +00:00
|
|
|
if err4 != nil {
|
|
|
|
return nil, payloadData, err4
|
|
|
|
}
|
|
|
|
return encoded, payloadData, nil
|
|
|
|
}
|