Fix keyserver
This commit is contained in:
parent
0013459677
commit
774d69411f
|
@ -33,12 +33,13 @@ import (
|
||||||
"github.com/matrix-org/dendrite/keyserver/api"
|
"github.com/matrix-org/dendrite/keyserver/api"
|
||||||
"github.com/matrix-org/dendrite/keyserver/producers"
|
"github.com/matrix-org/dendrite/keyserver/producers"
|
||||||
"github.com/matrix-org/dendrite/keyserver/storage"
|
"github.com/matrix-org/dendrite/keyserver/storage"
|
||||||
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
type KeyInternalAPI struct {
|
type KeyInternalAPI struct {
|
||||||
DB storage.Database
|
DB storage.Database
|
||||||
ThisServer gomatrixserverlib.ServerName
|
Cfg *config.KeyServer
|
||||||
FedClient fedsenderapi.KeyserverFederationAPI
|
FedClient fedsenderapi.KeyserverFederationAPI
|
||||||
UserAPI userapi.KeyserverUserAPI
|
UserAPI userapi.KeyserverUserAPI
|
||||||
Producer *producers.KeyChange
|
Producer *producers.KeyChange
|
||||||
|
@ -95,8 +96,11 @@ func (a *KeyInternalAPI) PerformClaimKeys(ctx context.Context, req *api.PerformC
|
||||||
nested[userID] = val
|
nested[userID] = val
|
||||||
domainToDeviceKeys[string(serverName)] = nested
|
domainToDeviceKeys[string(serverName)] = nested
|
||||||
}
|
}
|
||||||
|
for domain, local := range domainToDeviceKeys {
|
||||||
|
if !a.Cfg.Matrix.IsLocalServerName(gomatrixserverlib.ServerName(domain)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
// claim local keys
|
// claim local keys
|
||||||
if local, ok := domainToDeviceKeys[string(a.ThisServer)]; ok {
|
|
||||||
keys, err := a.DB.ClaimKeys(ctx, local)
|
keys, err := a.DB.ClaimKeys(ctx, local)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
|
@ -117,7 +121,7 @@ func (a *KeyInternalAPI) PerformClaimKeys(ctx context.Context, req *api.PerformC
|
||||||
res.OneTimeKeys[key.UserID][key.DeviceID][keyID] = keyJSON
|
res.OneTimeKeys[key.UserID][key.DeviceID][keyID] = keyJSON
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete(domainToDeviceKeys, string(a.ThisServer))
|
delete(domainToDeviceKeys, domain)
|
||||||
}
|
}
|
||||||
if len(domainToDeviceKeys) > 0 {
|
if len(domainToDeviceKeys) > 0 {
|
||||||
a.claimRemoteKeys(ctx, req.Timeout, res, domainToDeviceKeys)
|
a.claimRemoteKeys(ctx, req.Timeout, res, domainToDeviceKeys)
|
||||||
|
@ -258,7 +262,7 @@ func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysReques
|
||||||
}
|
}
|
||||||
domain := string(serverName)
|
domain := string(serverName)
|
||||||
// query local devices
|
// query local devices
|
||||||
if serverName == a.ThisServer {
|
if a.Cfg.Matrix.IsLocalServerName(serverName) {
|
||||||
deviceKeys, err := a.DB.DeviceKeysForUser(ctx, userID, deviceIDs, false)
|
deviceKeys, err := a.DB.DeviceKeysForUser(ctx, userID, deviceIDs, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
|
@ -437,13 +441,13 @@ func (a *KeyInternalAPI) queryRemoteKeys(
|
||||||
|
|
||||||
domains := map[string]struct{}{}
|
domains := map[string]struct{}{}
|
||||||
for domain := range domainToDeviceKeys {
|
for domain := range domainToDeviceKeys {
|
||||||
if domain == string(a.ThisServer) {
|
if a.Cfg.Matrix.IsLocalServerName(gomatrixserverlib.ServerName(domain)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
domains[domain] = struct{}{}
|
domains[domain] = struct{}{}
|
||||||
}
|
}
|
||||||
for domain := range domainToCrossSigningKeys {
|
for domain := range domainToCrossSigningKeys {
|
||||||
if domain == string(a.ThisServer) {
|
if a.Cfg.Matrix.IsLocalServerName(gomatrixserverlib.ServerName(domain)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
domains[domain] = struct{}{}
|
domains[domain] = struct{}{}
|
||||||
|
@ -689,7 +693,7 @@ func (a *KeyInternalAPI) uploadLocalDeviceKeys(ctx context.Context, req *api.Per
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue // ignore invalid users
|
continue // ignore invalid users
|
||||||
}
|
}
|
||||||
if serverName != a.ThisServer {
|
if !a.Cfg.Matrix.IsLocalServerName(serverName) {
|
||||||
continue // ignore remote users
|
continue // ignore remote users
|
||||||
}
|
}
|
||||||
if len(key.KeyJSON) == 0 {
|
if len(key.KeyJSON) == 0 {
|
||||||
|
|
|
@ -54,7 +54,7 @@ func NewInternalAPI(
|
||||||
}
|
}
|
||||||
ap := &internal.KeyInternalAPI{
|
ap := &internal.KeyInternalAPI{
|
||||||
DB: db,
|
DB: db,
|
||||||
ThisServer: cfg.Matrix.ServerName,
|
Cfg: cfg,
|
||||||
FedClient: fedClient,
|
FedClient: fedClient,
|
||||||
Producer: keyChangeProducer,
|
Producer: keyChangeProducer,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue