mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-13 21:02:25 +03:00
mas: added "admin's replacement without uia" endpoint
i.e. /_synapse/admin/v1/users/{userID}/_allow_cross_signing_replacement_without_uia
This commit is contained in:
parent
63a199cec3
commit
9d9841d02e
10 changed files with 168 additions and 29 deletions
|
@ -2,6 +2,7 @@ package routing
|
|||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -30,6 +31,8 @@ import (
|
|||
userapi "github.com/element-hq/dendrite/userapi/api"
|
||||
)
|
||||
|
||||
const replacementPeriod = 10 * time.Minute
|
||||
|
||||
var validRegistrationTokenRegex = regexp.MustCompile("^[[:ascii:][:digit:]_]*$")
|
||||
|
||||
func AdminCreateNewRegistrationToken(req *http.Request, cfg *config.ClientAPI, userAPI userapi.ClientUserAPI) util.JSONResponse {
|
||||
|
@ -607,6 +610,56 @@ func AdminHandleUserDeviceByUserID(
|
|||
|
||||
}
|
||||
|
||||
func AdminAllowCrossSigningReplacementWithoutUIA(
|
||||
req *http.Request,
|
||||
userAPI userapi.ClientUserAPI,
|
||||
) util.JSONResponse {
|
||||
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
||||
if err != nil {
|
||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||
}
|
||||
userIDstr, ok := vars["userID"]
|
||||
userID, err := spec.NewUserID(userIDstr, false)
|
||||
if !ok || err != nil {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusNotFound,
|
||||
JSON: spec.MissingParam("User not found."),
|
||||
}
|
||||
}
|
||||
|
||||
switch req.Method {
|
||||
case http.MethodPost:
|
||||
rq := userapi.PerformAllowingMasterCrossSigningKeyReplacementWithoutUIARequest{
|
||||
UserID: userID.String(),
|
||||
Duration: replacementPeriod,
|
||||
}
|
||||
var rs userapi.PerformAllowingMasterCrossSigningKeyReplacementWithoutUIAResponse
|
||||
err = userAPI.PerformAllowingMasterCrossSigningKeyReplacementWithoutUIA(req.Context(), &rq, &rs)
|
||||
if err == sql.ErrNoRows {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusNotFound,
|
||||
JSON: spec.MissingParam("User has no master cross-signing key"),
|
||||
}
|
||||
} else if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("userAPI.PerformAllowingMasterCrossSigningKeyReplacementWithoutUIA")
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusInternalServerError,
|
||||
JSON: spec.Unknown(err.Error()),
|
||||
}
|
||||
}
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
JSON: map[string]int64{"updatable_without_uia_before_ms": rs.Timestamp},
|
||||
}
|
||||
default:
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusMethodNotAllowed,
|
||||
JSON: spec.Unknown("Method not allowed."),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type adminExternalID struct {
|
||||
AuthProvider string `json:"auth_provider"`
|
||||
ExternalID string `json:"external_id"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue