mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-11 16:13:10 -06:00
Get federated pseudoID invites working
This commit is contained in:
parent
2337752988
commit
cea8f0ade1
|
|
@ -54,11 +54,14 @@ func NewFederationInternalAPI(
|
|||
KeyDatabase: serverKeyDB,
|
||||
}
|
||||
|
||||
pubKey := cfg.Matrix.PrivateKey.Public().(ed25519.PublicKey)
|
||||
addDirectFetcher := func() {
|
||||
keyRing.KeyFetchers = append(
|
||||
keyRing.KeyFetchers,
|
||||
&gomatrixserverlib.DirectKeyFetcher{
|
||||
Client: federation,
|
||||
Client: federation,
|
||||
IsLocalServerName: cfg.Matrix.IsLocalServerName,
|
||||
LocalPublicKey: []byte(pubKey),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -616,10 +616,6 @@ func (r *FederationInternalAPI) SendInviteV3(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if event.StateKey == nil {
|
||||
return nil, errors.New("invite must be a state event")
|
||||
}
|
||||
|
||||
// TODO (devon): This should be allowed via a relay. Currently only transactions
|
||||
// can be sent to relays. Would need to extend relays to handle invites.
|
||||
if !r.shouldAttemptDirectFederation(invitee.Domain()) {
|
||||
|
|
@ -627,7 +623,7 @@ func (r *FederationInternalAPI) SendInviteV3(
|
|||
}
|
||||
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"user_id": *event.StateKey,
|
||||
"user_id": invitee.String(),
|
||||
"room_id": event.RoomID,
|
||||
"room_version": version,
|
||||
"destination": invitee.Domain(),
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ package internal
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ed25519"
|
||||
"testing"
|
||||
|
||||
"github.com/matrix-org/dendrite/federationapi/api"
|
||||
|
|
@ -53,10 +54,14 @@ func TestPerformWakeupServers(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.True(t, offline)
|
||||
|
||||
_, key, err := ed25519.GenerateKey(nil)
|
||||
assert.NoError(t, err)
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "relay",
|
||||
KeyID: "ed25519:1",
|
||||
PrivateKey: key,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -95,10 +100,14 @@ func TestQueryRelayServers(t *testing.T) {
|
|||
err := testDB.P2PAddRelayServersForServer(context.Background(), server, relayServers)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, key, err := ed25519.GenerateKey(nil)
|
||||
assert.NoError(t, err)
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "relay",
|
||||
KeyID: "ed25519:1",
|
||||
PrivateKey: key,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -132,10 +141,14 @@ func TestRemoveRelayServers(t *testing.T) {
|
|||
err := testDB.P2PAddRelayServersForServer(context.Background(), server, relayServers)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, key, err := ed25519.GenerateKey(nil)
|
||||
assert.NoError(t, err)
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "relay",
|
||||
KeyID: "ed25519:1",
|
||||
PrivateKey: key,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -168,10 +181,14 @@ func TestRemoveRelayServers(t *testing.T) {
|
|||
func TestPerformDirectoryLookup(t *testing.T) {
|
||||
testDB := test.NewInMemoryFederationDatabase()
|
||||
|
||||
_, key, err := ed25519.GenerateKey(nil)
|
||||
assert.NoError(t, err)
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "relay",
|
||||
KeyID: "ed25519:1",
|
||||
PrivateKey: key,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -192,7 +209,7 @@ func TestPerformDirectoryLookup(t *testing.T) {
|
|||
ServerName: "server",
|
||||
}
|
||||
res := api.PerformDirectoryLookupResponse{}
|
||||
err := fedAPI.PerformDirectoryLookup(context.Background(), &req, &res)
|
||||
err = fedAPI.PerformDirectoryLookup(context.Background(), &req, &res)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -203,10 +220,14 @@ func TestPerformDirectoryLookupRelaying(t *testing.T) {
|
|||
testDB.SetServerAssumedOffline(context.Background(), server)
|
||||
testDB.P2PAddRelayServersForServer(context.Background(), server, []spec.ServerName{"relay"})
|
||||
|
||||
_, key, err := ed25519.GenerateKey(nil)
|
||||
assert.NoError(t, err)
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: server,
|
||||
ServerName: "relay",
|
||||
KeyID: "ed25519:1",
|
||||
PrivateKey: key,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -227,6 +248,6 @@ func TestPerformDirectoryLookupRelaying(t *testing.T) {
|
|||
ServerName: server,
|
||||
}
|
||||
res := api.PerformDirectoryLookupResponse{}
|
||||
err := fedAPI.PerformDirectoryLookup(context.Background(), &req, &res)
|
||||
err = fedAPI.PerformDirectoryLookup(context.Background(), &req, &res)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ func InviteV3(
|
|||
SenderIDQuerier: func(roomID spec.RoomID, userID spec.UserID) (spec.SenderID, error) {
|
||||
return rsAPI.QuerySenderIDForUser(httpReq.Context(), roomID, userID)
|
||||
},
|
||||
SenderIDCreator: func(ctx context.Context, userID spec.UserID, roomID spec.RoomID, roomVersion string) (spec.SenderID, ed25519.PrivateKey, error) {
|
||||
GetOrCreateSenderID: func(ctx context.Context, userID spec.UserID, roomID spec.RoomID, roomVersion string) (spec.SenderID, ed25519.PrivateKey, error) {
|
||||
// assign a roomNID, otherwise we can't create a private key for the user
|
||||
_, nidErr := rsAPI.AssignRoomNID(ctx, roomID, gomatrixserverlib.RoomVersion(roomVersion))
|
||||
if nidErr != nil {
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -22,7 +22,7 @@ require (
|
|||
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
|
||||
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
|
||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230628230042-0bf682015041
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230630201258-2564ca79770c
|
||||
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a
|
||||
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
|
||||
github.com/mattn/go-sqlite3 v1.14.16
|
||||
|
|
|
|||
6
go.sum
6
go.sum
|
|
@ -323,10 +323,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 h1:s7fexw
|
|||
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo=
|
||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U=
|
||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230628194752-4bac719832e6 h1:VDJPi1u1KvkJTkpAGitvu38/0bzUBBghSsB8++Q4qKQ=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230628194752-4bac719832e6/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230628230042-0bf682015041 h1:nN0v72oM6to3mQkoXV2jdoPSHzyGFzrxvgCmF+E/OuE=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230628230042-0bf682015041/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230630201258-2564ca79770c h1:FgkrAhxHB0i+CDQAi/lq5KSMJO4ceqtbg4IK11+L4rc=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230630201258-2564ca79770c/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU=
|
||||
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A=
|
||||
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ=
|
||||
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=
|
||||
|
|
|
|||
|
|
@ -163,6 +163,14 @@ func (r *Inviter) PerformInvite(
|
|||
|
||||
isTargetLocal := r.Cfg.Matrix.IsLocalServerName(req.InviteInput.Invitee.Domain())
|
||||
|
||||
signingKey := req.InviteInput.PrivateKey
|
||||
if info.RoomVersion == gomatrixserverlib.RoomVersionPseudoIDs {
|
||||
signingKey, err = r.RSAPI.GetOrCreateUserRoomPrivateKey(ctx, req.InviteInput.Inviter, req.InviteInput.RoomID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
input := gomatrixserverlib.PerformInviteInput{
|
||||
RoomID: req.InviteInput.RoomID,
|
||||
RoomVersion: info.RoomVersion,
|
||||
|
|
@ -172,7 +180,7 @@ func (r *Inviter) PerformInvite(
|
|||
EventTemplate: proto,
|
||||
StrippedState: req.InviteRoomState,
|
||||
KeyID: req.InviteInput.KeyID,
|
||||
SigningKey: req.InviteInput.PrivateKey,
|
||||
SigningKey: signingKey,
|
||||
EventTime: req.InviteInput.EventTime,
|
||||
MembershipQuerier: &api.MembershipQuerier{Roomserver: r.RSAPI},
|
||||
StateQuerier: &QueryState{r.DB, r.RSAPI},
|
||||
|
|
@ -209,6 +217,13 @@ func (r *Inviter) PerformInvite(
|
|||
Depth: res.Depth,
|
||||
}, nil
|
||||
},
|
||||
StoreSenderIDFromPublicID: func(ctx context.Context, senderID spec.SenderID, userIDRaw string, roomID spec.RoomID) error {
|
||||
storeUserID, userErr := spec.NewUserID(userIDRaw, true)
|
||||
if userErr != nil {
|
||||
return userErr
|
||||
}
|
||||
return r.RSAPI.StoreUserRoomPublicKey(ctx, senderID, *storeUserID, roomID)
|
||||
},
|
||||
}
|
||||
|
||||
inviteEvent, err := gomatrixserverlib.PerformInvite(ctx, input, r.FSAPI)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import (
|
|||
// DefaultRoomVersion contains the room version that will, by
|
||||
// default, be used to create new rooms on this server.
|
||||
func DefaultRoomVersion() gomatrixserverlib.RoomVersion {
|
||||
//return gomatrixserverlib.RoomVersionPseudoIDs
|
||||
return gomatrixserverlib.RoomVersionV10
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ func (n *Notifier) OnNewEvent(
|
|||
// If this is an invite, also add in the invitee to this list.
|
||||
if ev.Type() == "m.room.member" && ev.StateKey() != nil {
|
||||
targetUserID, err := n.rsAPI.QueryUserIDForSender(context.Background(), *validRoomID, spec.SenderID(*ev.StateKey()))
|
||||
if err != nil {
|
||||
if err != nil || targetUserID == nil {
|
||||
log.WithError(err).WithField("event_id", ev.EventID()).Errorf(
|
||||
"Notifier.OnNewEvent: Failed to find the userID for this event",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -313,10 +313,12 @@ func (s *OutputRoomEventConsumer) processMessage(ctx context.Context, event *rst
|
|||
|
||||
sk := event.StateKey()
|
||||
if sk != nil && *sk != "" {
|
||||
skUserID, queryErr := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*event.StateKey()))
|
||||
skUserID, queryErr := s.rsAPI.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*sk))
|
||||
if queryErr == nil && skUserID != nil {
|
||||
skString := skUserID.String()
|
||||
sk = &skString
|
||||
} else {
|
||||
return fmt.Errorf("queryUserIDForSender: userID unknown for %s", *sk)
|
||||
}
|
||||
}
|
||||
cevent := synctypes.ToClientEvent(event, synctypes.FormatAll, sender, sk)
|
||||
|
|
|
|||
Loading…
Reference in a new issue