mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 07:28:27 +00:00
Some refactoring
This commit is contained in:
parent
b37b7c70b7
commit
39d66ed9d6
9 changed files with 55 additions and 70 deletions
|
@ -104,7 +104,7 @@ func UploadCrossSigningDeviceSignatures(req *http.Request, keyserverAPI api.KeyI
|
|||
uploadReq := &api.PerformUploadDeviceSignaturesRequest{}
|
||||
uploadRes := &api.PerformUploadDeviceSignaturesResponse{}
|
||||
|
||||
if err := httputil.UnmarshalJSONRequest(req, &uploadReq.CrossSigningSignatures); err != nil {
|
||||
if err := httputil.UnmarshalJSONRequest(req, &uploadReq.Signatures); err != nil {
|
||||
return *err
|
||||
}
|
||||
|
||||
|
|
|
@ -76,9 +76,9 @@ type InputReceiptEventRequest struct {
|
|||
type InputReceiptEventResponse struct{}
|
||||
|
||||
type SigningKeyUpdate struct {
|
||||
MasterKey gomatrixserverlib.CrossSigningKey `json:"master_key"`
|
||||
SelfSigningKey gomatrixserverlib.CrossSigningKey `json:"cross_signing_key"`
|
||||
UserID string `json:"user_id"`
|
||||
MasterKey gomatrixserverlib.CrossSigningForKey `json:"master_key"`
|
||||
SelfSigningKey gomatrixserverlib.CrossSigningForKey `json:"cross_signing_key"`
|
||||
UserID string `json:"user_id"`
|
||||
}
|
||||
|
||||
type InputSigningKeyUpdateRequest struct {
|
||||
|
|
|
@ -91,7 +91,7 @@ func SendSigningKeyUpdate(
|
|||
ctx context.Context,
|
||||
eduAPI EDUServerInputAPI,
|
||||
userID string,
|
||||
masterKey, selfSigningKey gomatrixserverlib.CrossSigningKey,
|
||||
masterKey, selfSigningKey gomatrixserverlib.CrossSigningForKey,
|
||||
) error {
|
||||
request := InputSigningKeyUpdateRequest{
|
||||
SigningKeyUpdate: SigningKeyUpdate{
|
||||
|
|
2
go.mod
2
go.mod
|
@ -31,7 +31,7 @@ require (
|
|||
github.com/matrix-org/go-http-js-libp2p v0.0.0-20200518170932-783164aeeda4
|
||||
github.com/matrix-org/go-sqlite3-js v0.0.0-20210709140738-b0d1ba599a6d
|
||||
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20210729085730-a2fa40ca935a
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20210729144422-16ebeb5d0788
|
||||
github.com/matrix-org/naffka v0.0.0-20210623111924-14ff508b58e0
|
||||
github.com/matrix-org/pinecone v0.0.0-20210623102758-74f885644c1b
|
||||
github.com/matrix-org/util v0.0.0-20200807132607-55161520e1d4
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1027,8 +1027,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20210709140738-b0d1ba599a6d/go.mod h1
|
|||
github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0=
|
||||
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16 h1:ZtO5uywdd5dLDCud4r0r55eP4j9FuUNpl60Gmntcop4=
|
||||
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20210729085730-a2fa40ca935a h1:92J1k94mu9CfGjtjzKj3WGhedqadnUyHNhPa2w8O6z4=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20210729085730-a2fa40ca935a/go.mod h1:JsAzE1Ll3+gDWS9JSUHPJiiyAksvOOnGWF2nXdg4ZzU=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20210729144422-16ebeb5d0788 h1:wnMa7rHryaAQMke++Y9rJtrVIvRbFzbPxPYimpctx6Y=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20210729144422-16ebeb5d0788/go.mod h1:JsAzE1Ll3+gDWS9JSUHPJiiyAksvOOnGWF2nXdg4ZzU=
|
||||
github.com/matrix-org/naffka v0.0.0-20210623111924-14ff508b58e0 h1:HZCzy4oVzz55e+cOMiX/JtSF2UOY1evBl2raaE7ACcU=
|
||||
github.com/matrix-org/naffka v0.0.0-20210623111924-14ff508b58e0/go.mod h1:sjyPyRxKM5uw1nD2cJ6O2OxI6GOqyVBfNXqKjBZTBZE=
|
||||
github.com/matrix-org/pinecone v0.0.0-20210623102758-74f885644c1b h1:5X5vdWQ13xrNkJVqaJHPsrt7rKkMJH5iac0EtfOuxSg=
|
||||
|
|
|
@ -174,7 +174,7 @@ type PerformUploadDeviceKeysResponse struct {
|
|||
}
|
||||
|
||||
type PerformUploadDeviceSignaturesRequest struct {
|
||||
gomatrixserverlib.CrossSigningSignatures
|
||||
Signatures map[string]map[gomatrixserverlib.KeyID]json.RawMessage
|
||||
// The user that uploaded the sig, should be populated by the clientapi.
|
||||
UserID string `json:"user_id"`
|
||||
}
|
||||
|
@ -198,9 +198,9 @@ type QueryKeysResponse struct {
|
|||
// Map of user_id to device_id to device_key
|
||||
DeviceKeys map[string]map[string]json.RawMessage
|
||||
// Maps of user_id to cross signing key
|
||||
MasterKeys map[string]gomatrixserverlib.CrossSigningKey
|
||||
SelfSigningKeys map[string]gomatrixserverlib.CrossSigningKey
|
||||
UserSigningKeys map[string]gomatrixserverlib.CrossSigningKey
|
||||
MasterKeys map[string]gomatrixserverlib.CrossSigningForKey
|
||||
SelfSigningKeys map[string]gomatrixserverlib.CrossSigningForKey
|
||||
UserSigningKeys map[string]gomatrixserverlib.CrossSigningForKey
|
||||
// Set if there was a fatal error processing this query
|
||||
Error *KeyError
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func sanityCheckKey(key gomatrixserverlib.CrossSigningKey, userID string, purpose gomatrixserverlib.CrossSigningKeyPurpose) error {
|
||||
func sanityCheckKey(key gomatrixserverlib.CrossSigningForKey, userID string, purpose gomatrixserverlib.CrossSigningKeyPurpose) error {
|
||||
// Is there exactly one key?
|
||||
if len(key.Keys) != 1 {
|
||||
return fmt.Errorf("should contain exactly one key")
|
||||
|
@ -108,7 +108,7 @@ func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.P
|
|||
masterKeyID := gomatrixserverlib.KeyID(fmt.Sprintf("ed25519:%s", masterKey.Encode()))
|
||||
|
||||
// Work out which things we need to verify the signatures for.
|
||||
toVerify := make(map[gomatrixserverlib.CrossSigningKeyPurpose]gomatrixserverlib.CrossSigningKey, 3)
|
||||
toVerify := make(map[gomatrixserverlib.CrossSigningKeyPurpose]gomatrixserverlib.CrossSigningForKey, 3)
|
||||
toStore := api.CrossSigningKeyMap{}
|
||||
if len(req.MasterKey.Keys) > 0 {
|
||||
toVerify[gomatrixserverlib.CrossSigningKeyPurposeMaster] = req.MasterKey
|
||||
|
@ -160,72 +160,57 @@ func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.P
|
|||
}
|
||||
|
||||
func (a *KeyInternalAPI) PerformUploadDeviceSignatures(ctx context.Context, req *api.PerformUploadDeviceSignaturesRequest, res *api.PerformUploadDeviceSignaturesResponse) {
|
||||
for targetUserID, forTarget := range req.CrossSigningSignatures {
|
||||
for targetID, signable := range forTarget {
|
||||
switch obj := signable.(type) {
|
||||
case *gomatrixserverlib.CrossSigningKey: // signing a key
|
||||
// Check to see if we know about the target user ID and key ID. If we
|
||||
// don't then we'll just drop the signatures.
|
||||
keys, err := a.DB.CrossSigningKeysForUser(ctx, targetUserID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
foundMatchingKey := false
|
||||
for _, key := range keys {
|
||||
if key.Encode() == targetID {
|
||||
foundMatchingKey = true
|
||||
}
|
||||
}
|
||||
if !foundMatchingKey {
|
||||
continue
|
||||
}
|
||||
/*
|
||||
for targetUserID, forTarget := range req.Signatures {
|
||||
for targetID, signable := range forTarget {
|
||||
// Work out which type of thingy it is.
|
||||
|
||||
/*
|
||||
keyJSON, err := json.Marshal(obj)
|
||||
|
||||
switch obj := signable.(type) {
|
||||
case *gomatrixserverlib.CrossSigningForKey: // signing a key
|
||||
// Check to see if we know about the target user ID and key ID. If we
|
||||
// don't then we'll just drop the signatures.
|
||||
keys, err := a.DB.CrossSigningKeysForUser(ctx, targetUserID)
|
||||
if err != nil {
|
||||
res.Error = &api.KeyError{
|
||||
Err: fmt.Sprintf("The JSON of the signable object is invalid: %s", err.Error()),
|
||||
}
|
||||
return
|
||||
continue
|
||||
}
|
||||
foundMatchingKey := false
|
||||
for _, key := range keys {
|
||||
if key.Encode() == targetID {
|
||||
foundMatchingKey = true
|
||||
}
|
||||
}
|
||||
if !foundMatchingKey {
|
||||
continue
|
||||
}
|
||||
*/
|
||||
|
||||
for originUserID, forOriginUserID := range obj.Signatures {
|
||||
for originKeyID, signature := range forOriginUserID {
|
||||
// TODO: sig checking
|
||||
/*
|
||||
if err := gomatrixserverlib.VerifyJSON(originUserID, originKeyID, ed25519.PublicKey(masterKey), keyJSON); err != nil {
|
||||
for originUserID, forOriginUserID := range obj.Signatures {
|
||||
for originKeyID, signature := range forOriginUserID {
|
||||
// TODO: check signatures
|
||||
|
||||
err := a.DB.StoreCrossSigningSigsForTarget(ctx, originUserID, originKeyID, targetUserID, gomatrixserverlib.KeyID(targetID), signature)
|
||||
if err != nil {
|
||||
res.Error = &api.KeyError{
|
||||
Err: fmt.Sprintf("The %q sub-key failed master key signature verification: %s", purpose, err.Error()),
|
||||
IsInvalidSignature: true,
|
||||
Err: "Failed to store cross-signing keys for target: " + err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
err := a.DB.StoreCrossSigningSigsForTarget(ctx, originUserID, originKeyID, targetUserID, gomatrixserverlib.KeyID(targetID), signature)
|
||||
if err != nil {
|
||||
res.Error = &api.KeyError{
|
||||
Err: "Failed to store cross-signing keys for target: " + err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case *gomatrixserverlib.CrossSigningSignature: // signing a device
|
||||
// TODO: signatures for devices
|
||||
continue
|
||||
case *gomatrixserverlib.CrossSigningForDevice: // signing a device
|
||||
// TODO: signatures for devices
|
||||
continue
|
||||
|
||||
default:
|
||||
res.Error = &api.KeyError{
|
||||
Err: "Found an unexpected item type",
|
||||
default:
|
||||
res.Error = &api.KeyError{
|
||||
Err: "Found an unexpected item type",
|
||||
}
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
res.Error = &api.KeyError{
|
||||
Err: "Not supported yet",
|
||||
}
|
||||
|
@ -244,7 +229,7 @@ func (a *KeyInternalAPI) crossSigningKeys(
|
|||
for keyType, keyData := range keys {
|
||||
b64 := keyData.Encode()
|
||||
keyID := gomatrixserverlib.KeyID("ed25519:" + b64)
|
||||
key := gomatrixserverlib.CrossSigningKey{
|
||||
key := gomatrixserverlib.CrossSigningForKey{
|
||||
UserID: userID,
|
||||
Usage: []gomatrixserverlib.CrossSigningKeyPurpose{
|
||||
keyType,
|
||||
|
|
|
@ -221,9 +221,9 @@ func (a *KeyInternalAPI) QueryDeviceMessages(ctx context.Context, req *api.Query
|
|||
|
||||
func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysRequest, res *api.QueryKeysResponse) {
|
||||
res.DeviceKeys = make(map[string]map[string]json.RawMessage)
|
||||
res.MasterKeys = make(map[string]gomatrixserverlib.CrossSigningKey)
|
||||
res.SelfSigningKeys = make(map[string]gomatrixserverlib.CrossSigningKey)
|
||||
res.UserSigningKeys = make(map[string]gomatrixserverlib.CrossSigningKey)
|
||||
res.MasterKeys = make(map[string]gomatrixserverlib.CrossSigningForKey)
|
||||
res.SelfSigningKeys = make(map[string]gomatrixserverlib.CrossSigningForKey)
|
||||
res.UserSigningKeys = make(map[string]gomatrixserverlib.CrossSigningForKey)
|
||||
res.Failures = make(map[string]interface{})
|
||||
|
||||
// get cross-signing keys from the database
|
||||
|
|
|
@ -73,7 +73,7 @@ func AddRoutes(internalAPIMux *mux.Router, s api.KeyInternalAPI) {
|
|||
httputil.MakeInternalAPI("performUploadDeviceSignatures", func(req *http.Request) util.JSONResponse {
|
||||
request := api.PerformUploadDeviceSignaturesRequest{}
|
||||
response := api.PerformUploadDeviceSignaturesResponse{}
|
||||
if err := json.NewDecoder(req.Body).Decode(&request.CrossSigningSignatures); err != nil {
|
||||
if err := json.NewDecoder(req.Body).Decode(&request.Signatures); err != nil {
|
||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||
}
|
||||
s.PerformUploadDeviceSignatures(req.Context(), &request, &response)
|
||||
|
|
Loading…
Reference in a new issue