|
|
|
@ -898,157 +898,171 @@ func Setup(
|
|
|
|
|
|
|
|
|
|
// Key Backup Versions (Metadata)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/room_keys/version/{version}",
|
|
|
|
|
httputil.MakeAuthAPI("get_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
|
}
|
|
|
|
|
return KeyBackupVersion(req, userAPI, device, vars["version"])
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/room_keys/version",
|
|
|
|
|
httputil.MakeAuthAPI("get_latest_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return KeyBackupVersion(req, userAPI, device, "")
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/room_keys/version/{version}",
|
|
|
|
|
httputil.MakeAuthAPI("put_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
|
}
|
|
|
|
|
return ModifyKeyBackupVersionAuthData(req, userAPI, device, vars["version"])
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
r0mux.Handle("/room_keys/version/{version}",
|
|
|
|
|
httputil.MakeAuthAPI("delete_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
|
}
|
|
|
|
|
return DeleteKeyBackupVersion(req, userAPI, device, vars["version"])
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodDelete)
|
|
|
|
|
r0mux.Handle("/room_keys/version",
|
|
|
|
|
httputil.MakeAuthAPI("post_new_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return CreateKeyBackupVersion(req, userAPI, device)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
getBackupKeysVersion := httputil.MakeAuthAPI("get_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
|
}
|
|
|
|
|
return KeyBackupVersion(req, userAPI, device, vars["version"])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
getLatestBackupKeysVersion := httputil.MakeAuthAPI("get_latest_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return KeyBackupVersion(req, userAPI, device, "")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
putBackupKeysVersion := httputil.MakeAuthAPI("put_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
|
}
|
|
|
|
|
return ModifyKeyBackupVersionAuthData(req, userAPI, device, vars["version"])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
deleteBackupKeysVersion := httputil.MakeAuthAPI("delete_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
|
}
|
|
|
|
|
return DeleteKeyBackupVersion(req, userAPI, device, vars["version"])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
postNewBackupKeysVersion := httputil.MakeAuthAPI("post_new_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return CreateKeyBackupVersion(req, userAPI, device)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/room_keys/version/{version}", getBackupKeysVersion).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/room_keys/version", getLatestBackupKeysVersion).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/room_keys/version/{version}", putBackupKeysVersion).Methods(http.MethodPut)
|
|
|
|
|
r0mux.Handle("/room_keys/version/{version}", deleteBackupKeysVersion).Methods(http.MethodDelete)
|
|
|
|
|
r0mux.Handle("/room_keys/version", postNewBackupKeysVersion).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
unstableMux.Handle("/room_keys/version/{version}", getBackupKeysVersion).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
unstableMux.Handle("/room_keys/version", getLatestBackupKeysVersion).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
unstableMux.Handle("/room_keys/version/{version}", putBackupKeysVersion).Methods(http.MethodPut)
|
|
|
|
|
unstableMux.Handle("/room_keys/version/{version}", deleteBackupKeysVersion).Methods(http.MethodDelete)
|
|
|
|
|
unstableMux.Handle("/room_keys/version", postNewBackupKeysVersion).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
// Inserting E2E Backup Keys
|
|
|
|
|
|
|
|
|
|
// Bulk room and session
|
|
|
|
|
r0mux.Handle("/room_keys/keys",
|
|
|
|
|
httputil.MakeAuthAPI("put_backup_keys", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
version := req.URL.Query().Get("version")
|
|
|
|
|
if version == "" {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
Code: 400,
|
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("version must be specified"),
|
|
|
|
|
}
|
|
|
|
|
putBackupKeys := httputil.MakeAuthAPI("put_backup_keys", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
version := req.URL.Query().Get("version")
|
|
|
|
|
if version == "" {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
Code: 400,
|
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("version must be specified"),
|
|
|
|
|
}
|
|
|
|
|
var reqBody keyBackupSessionRequest
|
|
|
|
|
resErr := clientutil.UnmarshalJSONRequest(req, &reqBody)
|
|
|
|
|
if resErr != nil {
|
|
|
|
|
return *resErr
|
|
|
|
|
}
|
|
|
|
|
return UploadBackupKeys(req, userAPI, device, version, &reqBody)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
}
|
|
|
|
|
var reqBody keyBackupSessionRequest
|
|
|
|
|
resErr := clientutil.UnmarshalJSONRequest(req, &reqBody)
|
|
|
|
|
if resErr != nil {
|
|
|
|
|
return *resErr
|
|
|
|
|
}
|
|
|
|
|
return UploadBackupKeys(req, userAPI, device, version, &reqBody)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Single room bulk session
|
|
|
|
|
r0mux.Handle("/room_keys/keys/{roomID}",
|
|
|
|
|
httputil.MakeAuthAPI("put_backup_keys_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
|
putBackupKeysRoom := httputil.MakeAuthAPI("put_backup_keys_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
|
}
|
|
|
|
|
version := req.URL.Query().Get("version")
|
|
|
|
|
if version == "" {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
Code: 400,
|
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("version must be specified"),
|
|
|
|
|
}
|
|
|
|
|
version := req.URL.Query().Get("version")
|
|
|
|
|
if version == "" {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
Code: 400,
|
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("version must be specified"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
roomID := vars["roomID"]
|
|
|
|
|
var reqBody keyBackupSessionRequest
|
|
|
|
|
reqBody.Rooms = make(map[string]struct {
|
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
|
})
|
|
|
|
|
reqBody.Rooms[roomID] = struct {
|
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
|
}{
|
|
|
|
|
Sessions: map[string]userapi.KeyBackupSession{},
|
|
|
|
|
}
|
|
|
|
|
body := reqBody.Rooms[roomID]
|
|
|
|
|
resErr := clientutil.UnmarshalJSONRequest(req, &body)
|
|
|
|
|
if resErr != nil {
|
|
|
|
|
return *resErr
|
|
|
|
|
}
|
|
|
|
|
reqBody.Rooms[roomID] = body
|
|
|
|
|
return UploadBackupKeys(req, userAPI, device, version, &reqBody)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
}
|
|
|
|
|
roomID := vars["roomID"]
|
|
|
|
|
var reqBody keyBackupSessionRequest
|
|
|
|
|
reqBody.Rooms = make(map[string]struct {
|
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
|
})
|
|
|
|
|
reqBody.Rooms[roomID] = struct {
|
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
|
}{
|
|
|
|
|
Sessions: map[string]userapi.KeyBackupSession{},
|
|
|
|
|
}
|
|
|
|
|
body := reqBody.Rooms[roomID]
|
|
|
|
|
resErr := clientutil.UnmarshalJSONRequest(req, &body)
|
|
|
|
|
if resErr != nil {
|
|
|
|
|
return *resErr
|
|
|
|
|
}
|
|
|
|
|
reqBody.Rooms[roomID] = body
|
|
|
|
|
return UploadBackupKeys(req, userAPI, device, version, &reqBody)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Single room, single session
|
|
|
|
|
r0mux.Handle("/room_keys/keys/{roomID}/{sessionID}",
|
|
|
|
|
httputil.MakeAuthAPI("put_backup_keys_room_session", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
|
putBackupKeysRoomSession := httputil.MakeAuthAPI("put_backup_keys_room_session", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
|
}
|
|
|
|
|
version := req.URL.Query().Get("version")
|
|
|
|
|
if version == "" {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
Code: 400,
|
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("version must be specified"),
|
|
|
|
|
}
|
|
|
|
|
version := req.URL.Query().Get("version")
|
|
|
|
|
if version == "" {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
Code: 400,
|
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("version must be specified"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var reqBody userapi.KeyBackupSession
|
|
|
|
|
resErr := clientutil.UnmarshalJSONRequest(req, &reqBody)
|
|
|
|
|
if resErr != nil {
|
|
|
|
|
return *resErr
|
|
|
|
|
}
|
|
|
|
|
roomID := vars["roomID"]
|
|
|
|
|
sessionID := vars["sessionID"]
|
|
|
|
|
var keyReq keyBackupSessionRequest
|
|
|
|
|
keyReq.Rooms = make(map[string]struct {
|
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
|
})
|
|
|
|
|
keyReq.Rooms[roomID] = struct {
|
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
|
}{
|
|
|
|
|
Sessions: make(map[string]userapi.KeyBackupSession),
|
|
|
|
|
}
|
|
|
|
|
keyReq.Rooms[roomID].Sessions[sessionID] = reqBody
|
|
|
|
|
return UploadBackupKeys(req, userAPI, device, version, &keyReq)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
}
|
|
|
|
|
var reqBody userapi.KeyBackupSession
|
|
|
|
|
resErr := clientutil.UnmarshalJSONRequest(req, &reqBody)
|
|
|
|
|
if resErr != nil {
|
|
|
|
|
return *resErr
|
|
|
|
|
}
|
|
|
|
|
roomID := vars["roomID"]
|
|
|
|
|
sessionID := vars["sessionID"]
|
|
|
|
|
var keyReq keyBackupSessionRequest
|
|
|
|
|
keyReq.Rooms = make(map[string]struct {
|
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
|
})
|
|
|
|
|
keyReq.Rooms[roomID] = struct {
|
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
|
}{
|
|
|
|
|
Sessions: make(map[string]userapi.KeyBackupSession),
|
|
|
|
|
}
|
|
|
|
|
keyReq.Rooms[roomID].Sessions[sessionID] = reqBody
|
|
|
|
|
return UploadBackupKeys(req, userAPI, device, version, &keyReq)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/room_keys/keys", putBackupKeys).Methods(http.MethodPut)
|
|
|
|
|
r0mux.Handle("/room_keys/keys/{roomID}", putBackupKeysRoom).Methods(http.MethodPut)
|
|
|
|
|
r0mux.Handle("/room_keys/keys/{roomID}/{sessionID}", putBackupKeysRoomSession).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
|
|
unstableMux.Handle("/room_keys/keys", putBackupKeys).Methods(http.MethodPut)
|
|
|
|
|
unstableMux.Handle("/room_keys/keys/{roomID}", putBackupKeysRoom).Methods(http.MethodPut)
|
|
|
|
|
unstableMux.Handle("/room_keys/keys/{roomID}/{sessionID}", putBackupKeysRoomSession).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
|
|
// Querying E2E Backup Keys
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/room_keys/keys",
|
|
|
|
|
httputil.MakeAuthAPI("get_backup_keys", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return GetBackupKeys(req, userAPI, device, req.URL.Query().Get("version"), "", "")
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/room_keys/keys/{roomID}",
|
|
|
|
|
httputil.MakeAuthAPI("get_backup_keys_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
|
}
|
|
|
|
|
return GetBackupKeys(req, userAPI, device, req.URL.Query().Get("version"), vars["roomID"], "")
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/room_keys/keys/{roomID}/{sessionID}",
|
|
|
|
|
httputil.MakeAuthAPI("get_backup_keys_room_session", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
|
}
|
|
|
|
|
return GetBackupKeys(req, userAPI, device, req.URL.Query().Get("version"), vars["roomID"], vars["sessionID"])
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
getBackupKeys := httputil.MakeAuthAPI("get_backup_keys", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return GetBackupKeys(req, userAPI, device, req.URL.Query().Get("version"), "", "")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
getBackupKeysRoom := httputil.MakeAuthAPI("get_backup_keys_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
|
}
|
|
|
|
|
return GetBackupKeys(req, userAPI, device, req.URL.Query().Get("version"), vars["roomID"], "")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
getBackupKeysRoomSession := httputil.MakeAuthAPI("get_backup_keys_room_session", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
|
}
|
|
|
|
|
return GetBackupKeys(req, userAPI, device, req.URL.Query().Get("version"), vars["roomID"], vars["sessionID"])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/room_keys/keys", getBackupKeys).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/room_keys/keys/{roomID}", getBackupKeysRoom).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/room_keys/keys/{roomID}/{sessionID}", getBackupKeysRoomSession).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
unstableMux.Handle("/room_keys/keys", getBackupKeys).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
unstableMux.Handle("/room_keys/keys/{roomID}", getBackupKeysRoom).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
unstableMux.Handle("/room_keys/keys/{roomID}/{sessionID}", getBackupKeysRoomSession).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
// Deleting E2E Backup Keys
|
|
|
|
|
|
|
|
|
|