2020-07-13 17:02:35 +02:00
|
|
|
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package inthttp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/matrix-org/dendrite/internal/httputil"
|
|
|
|
"github.com/matrix-org/dendrite/keyserver/api"
|
2020-07-30 19:00:56 +02:00
|
|
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
2020-07-13 17:02:35 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// HTTP paths for the internal HTTP APIs
|
|
|
|
const (
|
2021-08-04 18:56:29 +02:00
|
|
|
InputDeviceListUpdatePath = "/keyserver/inputDeviceListUpdate"
|
|
|
|
PerformUploadKeysPath = "/keyserver/performUploadKeys"
|
|
|
|
PerformClaimKeysPath = "/keyserver/performClaimKeys"
|
2021-08-18 13:07:09 +02:00
|
|
|
PerformDeleteKeysPath = "/keyserver/performDeleteKeys"
|
2021-08-04 18:56:29 +02:00
|
|
|
PerformUploadDeviceKeysPath = "/keyserver/performUploadDeviceKeys"
|
|
|
|
PerformUploadDeviceSignaturesPath = "/keyserver/performUploadDeviceSignatures"
|
|
|
|
QueryKeysPath = "/keyserver/queryKeys"
|
|
|
|
QueryKeyChangesPath = "/keyserver/queryKeyChanges"
|
|
|
|
QueryOneTimeKeysPath = "/keyserver/queryOneTimeKeys"
|
|
|
|
QueryDeviceMessagesPath = "/keyserver/queryDeviceMessages"
|
2021-08-06 11:13:35 +02:00
|
|
|
QuerySignaturesPath = "/keyserver/querySignatures"
|
2022-09-20 11:32:03 +02:00
|
|
|
PerformMarkAsStalePath = "/keyserver/markAsStale"
|
2020-07-13 17:02:35 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewKeyServerClient creates a KeyInternalAPI implemented by talking to a HTTP POST API.
|
|
|
|
// If httpClient is nil an error is returned
|
|
|
|
func NewKeyServerClient(
|
|
|
|
apiURL string,
|
|
|
|
httpClient *http.Client,
|
|
|
|
) (api.KeyInternalAPI, error) {
|
|
|
|
if httpClient == nil {
|
|
|
|
return nil, errors.New("NewKeyServerClient: httpClient is <nil>")
|
|
|
|
}
|
|
|
|
return &httpKeyInternalAPI{
|
|
|
|
apiURL: apiURL,
|
|
|
|
httpClient: httpClient,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type httpKeyInternalAPI struct {
|
|
|
|
apiURL string
|
|
|
|
httpClient *http.Client
|
|
|
|
}
|
|
|
|
|
2022-05-06 13:39:26 +02:00
|
|
|
func (h *httpKeyInternalAPI) SetUserAPI(i userapi.KeyserverUserAPI) {
|
2020-07-30 19:00:56 +02:00
|
|
|
// no-op: doesn't need it
|
|
|
|
}
|
|
|
|
|
2020-07-13 17:02:35 +02:00
|
|
|
func (h *httpKeyInternalAPI) PerformClaimKeys(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformClaimKeysRequest,
|
|
|
|
response *api.PerformClaimKeysResponse,
|
2022-08-11 16:29:33 +02:00
|
|
|
) error {
|
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"PerformClaimKeys", h.apiURL+PerformClaimKeysPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2020-07-13 17:02:35 +02:00
|
|
|
}
|
|
|
|
|
2021-08-18 13:07:09 +02:00
|
|
|
func (h *httpKeyInternalAPI) PerformDeleteKeys(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformDeleteKeysRequest,
|
|
|
|
response *api.PerformDeleteKeysResponse,
|
2022-08-11 16:29:33 +02:00
|
|
|
) error {
|
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"PerformDeleteKeys", h.apiURL+PerformDeleteKeysPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2021-08-18 13:07:09 +02:00
|
|
|
}
|
|
|
|
|
2020-07-13 17:02:35 +02:00
|
|
|
func (h *httpKeyInternalAPI) PerformUploadKeys(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformUploadKeysRequest,
|
|
|
|
response *api.PerformUploadKeysResponse,
|
2022-08-11 16:29:33 +02:00
|
|
|
) error {
|
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"PerformUploadKeys", h.apiURL+PerformUploadKeysPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2020-07-13 17:02:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpKeyInternalAPI) QueryKeys(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryKeysRequest,
|
|
|
|
response *api.QueryKeysResponse,
|
2022-08-11 16:29:33 +02:00
|
|
|
) error {
|
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"QueryKeys", h.apiURL+QueryKeysPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2020-07-13 17:02:35 +02:00
|
|
|
}
|
2020-07-28 19:25:16 +02:00
|
|
|
|
2020-08-03 13:29:58 +02:00
|
|
|
func (h *httpKeyInternalAPI) QueryOneTimeKeys(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryOneTimeKeysRequest,
|
|
|
|
response *api.QueryOneTimeKeysResponse,
|
2022-08-11 16:29:33 +02:00
|
|
|
) error {
|
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"QueryOneTimeKeys", h.apiURL+QueryOneTimeKeysPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2020-08-03 13:29:58 +02:00
|
|
|
}
|
|
|
|
|
2020-08-04 12:32:14 +02:00
|
|
|
func (h *httpKeyInternalAPI) QueryDeviceMessages(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryDeviceMessagesRequest,
|
|
|
|
response *api.QueryDeviceMessagesResponse,
|
2022-08-11 16:29:33 +02:00
|
|
|
) error {
|
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"QueryDeviceMessages", h.apiURL+QueryDeviceMessagesPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2020-08-04 12:32:14 +02:00
|
|
|
}
|
|
|
|
|
2020-07-28 19:25:16 +02:00
|
|
|
func (h *httpKeyInternalAPI) QueryKeyChanges(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryKeyChangesRequest,
|
|
|
|
response *api.QueryKeyChangesResponse,
|
2022-08-11 16:29:33 +02:00
|
|
|
) error {
|
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"QueryKeyChanges", h.apiURL+QueryKeyChangesPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2020-07-28 19:25:16 +02:00
|
|
|
}
|
2021-08-04 18:56:29 +02:00
|
|
|
|
|
|
|
func (h *httpKeyInternalAPI) PerformUploadDeviceKeys(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformUploadDeviceKeysRequest,
|
|
|
|
response *api.PerformUploadDeviceKeysResponse,
|
2022-08-11 16:29:33 +02:00
|
|
|
) error {
|
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"PerformUploadDeviceKeys", h.apiURL+PerformUploadDeviceKeysPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2021-08-04 18:56:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpKeyInternalAPI) PerformUploadDeviceSignatures(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformUploadDeviceSignaturesRequest,
|
|
|
|
response *api.PerformUploadDeviceSignaturesResponse,
|
2022-08-11 16:29:33 +02:00
|
|
|
) error {
|
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"PerformUploadDeviceSignatures", h.apiURL+PerformUploadDeviceSignaturesPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2021-08-04 18:56:29 +02:00
|
|
|
}
|
2021-08-06 11:13:35 +02:00
|
|
|
|
|
|
|
func (h *httpKeyInternalAPI) QuerySignatures(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QuerySignaturesRequest,
|
|
|
|
response *api.QuerySignaturesResponse,
|
2022-08-11 16:29:33 +02:00
|
|
|
) error {
|
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"QuerySignatures", h.apiURL+QuerySignaturesPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2021-08-06 11:13:35 +02:00
|
|
|
}
|
2022-09-20 11:32:03 +02:00
|
|
|
|
|
|
|
func (h *httpKeyInternalAPI) PerformMarkAsStaleIfNeeded(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformMarkAsStaleRequest,
|
|
|
|
response *struct{},
|
|
|
|
) error {
|
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"MarkAsStale", h.apiURL+PerformMarkAsStalePath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
|
|
|
}
|