( ctx context.Context, isInviteV2 bool, event *gomatrixserverlib.Event, roomVer gomatrixserverlib.RoomVersion, strippedState []gomatrixserverlib.InviteV2StrippedState, roomID string, eventID string, cfg *config.FederationAPI, rsAPI api.FederationRoomserverAPI, keys gomatrixserverlib.JSONVerifier, )
| 104 | } |
| 105 | |
| 106 | func processInvite( |
| 107 | ctx context.Context, |
| 108 | isInviteV2 bool, |
| 109 | event *gomatrixserverlib.Event, |
| 110 | roomVer gomatrixserverlib.RoomVersion, |
| 111 | strippedState []gomatrixserverlib.InviteV2StrippedState, |
| 112 | roomID string, |
| 113 | eventID string, |
| 114 | cfg *config.FederationAPI, |
| 115 | rsAPI api.FederationRoomserverAPI, |
| 116 | keys gomatrixserverlib.JSONVerifier, |
| 117 | ) util.JSONResponse { |
| 118 | |
| 119 | // Check that we can accept invites for this room version. |
| 120 | if _, err := roomserverVersion.SupportedRoomVersion(roomVer); err != nil { |
| 121 | return util.JSONResponse{ |
| 122 | Code: http.StatusBadRequest, |
| 123 | JSON: jsonerror.UnsupportedRoomVersion( |
| 124 | fmt.Sprintf("Room version %q is not supported by this server.", roomVer), |
| 125 | ), |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | // Check that the room ID is correct. |
| 130 | if event.RoomID() != roomID { |
| 131 | return util.JSONResponse{ |
| 132 | Code: http.StatusBadRequest, |
| 133 | JSON: jsonerror.BadJSON("The room ID in the request path must match the room ID in the invite event JSON"), |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | // Check that the event ID is correct. |
| 138 | if event.EventID() != eventID { |
| 139 | return util.JSONResponse{ |
| 140 | Code: http.StatusBadRequest, |
| 141 | JSON: jsonerror.BadJSON("The event ID in the request path must match the event ID in the invite event JSON"), |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | // Check that the event is signed by the server sending the request. |
| 146 | redacted, err := gomatrixserverlib.RedactEventJSON(event.JSON(), event.Version()) |
| 147 | if err != nil { |
| 148 | return util.JSONResponse{ |
| 149 | Code: http.StatusBadRequest, |
| 150 | JSON: jsonerror.BadJSON("The event JSON could not be redacted"), |
| 151 | } |
| 152 | } |
| 153 | verifyRequests := []gomatrixserverlib.VerifyJSONRequest{{ |
| 154 | ServerName: event.Origin(), |
| 155 | Message: redacted, |
| 156 | AtTS: event.OriginServerTS(), |
| 157 | StrictValidityChecking: true, |
| 158 | }} |
| 159 | verifyResults, err := keys.VerifyJSONs(ctx, verifyRequests) |
| 160 | if err != nil { |
| 161 | util.GetLogger(ctx).WithError(err).Error("keys.VerifyJSONs failed") |
| 162 | return jsonerror.InternalServerError() |
| 163 | } |
no test coverage detected