|
|
@ -4,6 +4,7 @@ import (
|
|
|
|
"encoding/json"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"go.step.sm/crypto/kms/uri"
|
|
|
|
"go.step.sm/crypto/kms/uri"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type WireIDJSON struct {
|
|
|
|
type WireIDJSON struct {
|
|
|
@ -24,16 +25,21 @@ type ClientID struct {
|
|
|
|
Domain string
|
|
|
|
Domain string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ClientId format is : "wireapp://CzbfFjDOQrenCbDxVmgnFw!594930e9d50bb175@wire.com" where '!' is used as a separator
|
|
|
|
|
|
|
|
// between the user id & device id
|
|
|
|
func ParseClientID(clientID string) (ClientID, error) {
|
|
|
|
func ParseClientID(clientID string) (ClientID, error) {
|
|
|
|
clientIdUri, err := uri.Parse(clientID)
|
|
|
|
clientIdUri, err := uri.Parse(clientID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return ClientID{}, fmt.Errorf("invalid client id URI")
|
|
|
|
return ClientID{}, fmt.Errorf("invalid client id URI")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
username := clientIdUri.User.Username()
|
|
|
|
fullUsername := clientIdUri.User.Username()
|
|
|
|
deviceId, _ := clientIdUri.User.Password()
|
|
|
|
parts := strings.SplitN(fullUsername, "!", 2)
|
|
|
|
|
|
|
|
if len(parts) != 2 {
|
|
|
|
|
|
|
|
return ClientID{}, fmt.Errorf("invalid client id")
|
|
|
|
|
|
|
|
}
|
|
|
|
return ClientID{
|
|
|
|
return ClientID{
|
|
|
|
Username: username,
|
|
|
|
Username: parts[0],
|
|
|
|
DeviceID: deviceId,
|
|
|
|
DeviceID: parts[1],
|
|
|
|
Domain: clientIdUri.Host,
|
|
|
|
Domain: clientIdUri.Host,
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|