This commit is contained in:
Anant Prakash 2018-06-22 10:55:06 +00:00 committed by GitHub
commit cae49a5da4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 47 deletions

View file

@ -17,9 +17,7 @@ package routing
import (
"context"
"net/http"
"time"
"github.com/matrix-org/dendrite/common/config"
"github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
@ -29,10 +27,7 @@ import (
func GetEvent(
ctx context.Context,
request *gomatrixserverlib.FederationRequest,
_ config.Dendrite,
query api.RoomserverQueryAPI,
_ time.Time,
_ gomatrixserverlib.KeyRing,
eventID string,
) util.JSONResponse {
event, err := getEvent(ctx, request, query, eventID)

View file

@ -34,7 +34,6 @@ func Invite(
eventID string,
cfg config.Dendrite,
producer *producers.RoomserverProducer,
keys gomatrixserverlib.KeyRing,
) util.JSONResponse {
// Decode the event JSON from the request.
@ -70,30 +69,13 @@ func Invite(
}
}
// Check that the event is signed by the server sending the request.
verifyRequests := []gomatrixserverlib.VerifyJSONRequest{{
ServerName: event.Origin(),
Message: event.Redact().JSON(),
AtTS: event.OriginServerTS(),
}}
verifyResults, err := keys.VerifyJSONs(httpReq.Context(), verifyRequests)
if err != nil {
return httputil.LogThenError(httpReq, err)
}
if verifyResults[0].Error != nil {
return util.JSONResponse{
Code: http.StatusForbidden,
JSON: jsonerror.Forbidden("The invite must be signed by the server it originated on"),
}
}
// Sign the event so that other servers will know that we have received the invite.
signedEvent := event.Sign(
string(cfg.Matrix.ServerName), cfg.Matrix.KeyID, cfg.Matrix.PrivateKey,
)
// Add the invite event to the roomserver.
if err = producer.SendInvite(httpReq.Context(), signedEvent); err != nil {
if err := producer.SendInvite(httpReq.Context(), signedEvent); err != nil {
return httputil.LogThenError(httpReq, err)
}

View file

@ -102,7 +102,6 @@ func SendJoin(
cfg config.Dendrite,
query api.RoomserverQueryAPI,
producer *producers.RoomserverProducer,
keys gomatrixserverlib.KeyRing,
roomID, eventID string,
) util.JSONResponse {
var event gomatrixserverlib.Event
@ -137,27 +136,10 @@ func SendJoin(
}
}
// Check that the event is signed by the server sending the request.
verifyRequests := []gomatrixserverlib.VerifyJSONRequest{{
ServerName: event.Origin(),
Message: event.Redact().JSON(),
AtTS: event.OriginServerTS(),
}}
verifyResults, err := keys.VerifyJSONs(ctx, verifyRequests)
if err != nil {
return httputil.LogThenError(httpReq, err)
}
if verifyResults[0].Error != nil {
return util.JSONResponse{
Code: http.StatusForbidden,
JSON: jsonerror.Forbidden("The join must be signed by the server it originated on"),
}
}
// Fetch the state and auth chain. We do this before we send the events
// on, in case this fails.
var stateAndAuthChainRepsonse api.QueryStateAndAuthChainResponse
err = query.QueryStateAndAuthChain(ctx, &api.QueryStateAndAuthChainRequest{
err := query.QueryStateAndAuthChain(ctx, &api.QueryStateAndAuthChainRequest{
PrevEventIDs: event.PrevEventIDs(),
AuthEventIDs: event.AuthEventIDs(),
RoomID: roomID,

View file

@ -16,7 +16,6 @@ package routing
import (
"net/http"
"time"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
@ -75,7 +74,7 @@ func Setup(
vars := mux.Vars(httpReq)
return Invite(
httpReq, request, vars["roomID"], vars["eventID"],
cfg, producer, keys,
cfg, producer,
)
},
)).Methods(http.MethodPut, http.MethodOptions)
@ -101,7 +100,7 @@ func Setup(
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
vars := mux.Vars(httpReq)
return GetEvent(
httpReq.Context(), request, cfg, query, time.Now(), keys, vars["eventID"],
httpReq.Context(), request, query, vars["eventID"],
)
},
)).Methods(http.MethodGet)
@ -165,7 +164,7 @@ func Setup(
roomID := vars["roomID"]
userID := vars["userID"]
return SendJoin(
httpReq.Context(), httpReq, request, cfg, query, producer, keys, roomID, userID,
httpReq.Context(), httpReq, request, cfg, query, producer, roomID, userID,
)
},
)).Methods(http.MethodPut)