mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-28 16:08: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{}
|
uploadReq := &api.PerformUploadDeviceSignaturesRequest{}
|
||||||
uploadRes := &api.PerformUploadDeviceSignaturesResponse{}
|
uploadRes := &api.PerformUploadDeviceSignaturesResponse{}
|
||||||
|
|
||||||
if err := httputil.UnmarshalJSONRequest(req, &uploadReq.CrossSigningSignatures); err != nil {
|
if err := httputil.UnmarshalJSONRequest(req, &uploadReq.Signatures); err != nil {
|
||||||
return *err
|
return *err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,8 +76,8 @@ type InputReceiptEventRequest struct {
|
||||||
type InputReceiptEventResponse struct{}
|
type InputReceiptEventResponse struct{}
|
||||||
|
|
||||||
type SigningKeyUpdate struct {
|
type SigningKeyUpdate struct {
|
||||||
MasterKey gomatrixserverlib.CrossSigningKey `json:"master_key"`
|
MasterKey gomatrixserverlib.CrossSigningForKey `json:"master_key"`
|
||||||
SelfSigningKey gomatrixserverlib.CrossSigningKey `json:"cross_signing_key"`
|
SelfSigningKey gomatrixserverlib.CrossSigningForKey `json:"cross_signing_key"`
|
||||||
UserID string `json:"user_id"`
|
UserID string `json:"user_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ func SendSigningKeyUpdate(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
eduAPI EDUServerInputAPI,
|
eduAPI EDUServerInputAPI,
|
||||||
userID string,
|
userID string,
|
||||||
masterKey, selfSigningKey gomatrixserverlib.CrossSigningKey,
|
masterKey, selfSigningKey gomatrixserverlib.CrossSigningForKey,
|
||||||
) error {
|
) error {
|
||||||
request := InputSigningKeyUpdateRequest{
|
request := InputSigningKeyUpdateRequest{
|
||||||
SigningKeyUpdate: SigningKeyUpdate{
|
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-http-js-libp2p v0.0.0-20200518170932-783164aeeda4
|
||||||
github.com/matrix-org/go-sqlite3-js v0.0.0-20210709140738-b0d1ba599a6d
|
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/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/naffka v0.0.0-20210623111924-14ff508b58e0
|
||||||
github.com/matrix-org/pinecone v0.0.0-20210623102758-74f885644c1b
|
github.com/matrix-org/pinecone v0.0.0-20210623102758-74f885644c1b
|
||||||
github.com/matrix-org/util v0.0.0-20200807132607-55161520e1d4
|
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-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 h1:ZtO5uywdd5dLDCud4r0r55eP4j9FuUNpl60Gmntcop4=
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
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-20210729144422-16ebeb5d0788 h1:wnMa7rHryaAQMke++Y9rJtrVIvRbFzbPxPYimpctx6Y=
|
||||||
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/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 h1:HZCzy4oVzz55e+cOMiX/JtSF2UOY1evBl2raaE7ACcU=
|
||||||
github.com/matrix-org/naffka v0.0.0-20210623111924-14ff508b58e0/go.mod h1:sjyPyRxKM5uw1nD2cJ6O2OxI6GOqyVBfNXqKjBZTBZE=
|
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=
|
github.com/matrix-org/pinecone v0.0.0-20210623102758-74f885644c1b h1:5X5vdWQ13xrNkJVqaJHPsrt7rKkMJH5iac0EtfOuxSg=
|
||||||
|
|
|
@ -174,7 +174,7 @@ type PerformUploadDeviceKeysResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PerformUploadDeviceSignaturesRequest 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.
|
// The user that uploaded the sig, should be populated by the clientapi.
|
||||||
UserID string `json:"user_id"`
|
UserID string `json:"user_id"`
|
||||||
}
|
}
|
||||||
|
@ -198,9 +198,9 @@ type QueryKeysResponse struct {
|
||||||
// Map of user_id to device_id to device_key
|
// Map of user_id to device_id to device_key
|
||||||
DeviceKeys map[string]map[string]json.RawMessage
|
DeviceKeys map[string]map[string]json.RawMessage
|
||||||
// Maps of user_id to cross signing key
|
// Maps of user_id to cross signing key
|
||||||
MasterKeys map[string]gomatrixserverlib.CrossSigningKey
|
MasterKeys map[string]gomatrixserverlib.CrossSigningForKey
|
||||||
SelfSigningKeys map[string]gomatrixserverlib.CrossSigningKey
|
SelfSigningKeys map[string]gomatrixserverlib.CrossSigningForKey
|
||||||
UserSigningKeys map[string]gomatrixserverlib.CrossSigningKey
|
UserSigningKeys map[string]gomatrixserverlib.CrossSigningForKey
|
||||||
// Set if there was a fatal error processing this query
|
// Set if there was a fatal error processing this query
|
||||||
Error *KeyError
|
Error *KeyError
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"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?
|
// Is there exactly one key?
|
||||||
if len(key.Keys) != 1 {
|
if len(key.Keys) != 1 {
|
||||||
return fmt.Errorf("should contain exactly one key")
|
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()))
|
masterKeyID := gomatrixserverlib.KeyID(fmt.Sprintf("ed25519:%s", masterKey.Encode()))
|
||||||
|
|
||||||
// Work out which things we need to verify the signatures for.
|
// 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{}
|
toStore := api.CrossSigningKeyMap{}
|
||||||
if len(req.MasterKey.Keys) > 0 {
|
if len(req.MasterKey.Keys) > 0 {
|
||||||
toVerify[gomatrixserverlib.CrossSigningKeyPurposeMaster] = req.MasterKey
|
toVerify[gomatrixserverlib.CrossSigningKeyPurposeMaster] = req.MasterKey
|
||||||
|
@ -160,10 +160,14 @@ func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.P
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *KeyInternalAPI) PerformUploadDeviceSignatures(ctx context.Context, req *api.PerformUploadDeviceSignaturesRequest, res *api.PerformUploadDeviceSignaturesResponse) {
|
func (a *KeyInternalAPI) PerformUploadDeviceSignatures(ctx context.Context, req *api.PerformUploadDeviceSignaturesRequest, res *api.PerformUploadDeviceSignaturesResponse) {
|
||||||
for targetUserID, forTarget := range req.CrossSigningSignatures {
|
/*
|
||||||
|
for targetUserID, forTarget := range req.Signatures {
|
||||||
for targetID, signable := range forTarget {
|
for targetID, signable := range forTarget {
|
||||||
|
// Work out which type of thingy it is.
|
||||||
|
|
||||||
|
|
||||||
switch obj := signable.(type) {
|
switch obj := signable.(type) {
|
||||||
case *gomatrixserverlib.CrossSigningKey: // signing a key
|
case *gomatrixserverlib.CrossSigningForKey: // signing a key
|
||||||
// Check to see if we know about the target user ID and key ID. If we
|
// 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.
|
// don't then we'll just drop the signatures.
|
||||||
keys, err := a.DB.CrossSigningKeysForUser(ctx, targetUserID)
|
keys, err := a.DB.CrossSigningKeysForUser(ctx, targetUserID)
|
||||||
|
@ -180,28 +184,9 @@ func (a *KeyInternalAPI) PerformUploadDeviceSignatures(ctx context.Context, req
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
keyJSON, err := json.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
res.Error = &api.KeyError{
|
|
||||||
Err: fmt.Sprintf("The JSON of the signable object is invalid: %s", err.Error()),
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
for originUserID, forOriginUserID := range obj.Signatures {
|
for originUserID, forOriginUserID := range obj.Signatures {
|
||||||
for originKeyID, signature := range forOriginUserID {
|
for originKeyID, signature := range forOriginUserID {
|
||||||
// TODO: sig checking
|
// TODO: check signatures
|
||||||
/*
|
|
||||||
if err := gomatrixserverlib.VerifyJSON(originUserID, originKeyID, ed25519.PublicKey(masterKey), keyJSON); err != nil {
|
|
||||||
res.Error = &api.KeyError{
|
|
||||||
Err: fmt.Sprintf("The %q sub-key failed master key signature verification: %s", purpose, err.Error()),
|
|
||||||
IsInvalidSignature: true,
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
err := a.DB.StoreCrossSigningSigsForTarget(ctx, originUserID, originKeyID, targetUserID, gomatrixserverlib.KeyID(targetID), signature)
|
err := a.DB.StoreCrossSigningSigsForTarget(ctx, originUserID, originKeyID, targetUserID, gomatrixserverlib.KeyID(targetID), signature)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -213,7 +198,7 @@ func (a *KeyInternalAPI) PerformUploadDeviceSignatures(ctx context.Context, req
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case *gomatrixserverlib.CrossSigningSignature: // signing a device
|
case *gomatrixserverlib.CrossSigningForDevice: // signing a device
|
||||||
// TODO: signatures for devices
|
// TODO: signatures for devices
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -225,7 +210,7 @@ func (a *KeyInternalAPI) PerformUploadDeviceSignatures(ctx context.Context, req
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: "Not supported yet",
|
Err: "Not supported yet",
|
||||||
}
|
}
|
||||||
|
@ -244,7 +229,7 @@ func (a *KeyInternalAPI) crossSigningKeys(
|
||||||
for keyType, keyData := range keys {
|
for keyType, keyData := range keys {
|
||||||
b64 := keyData.Encode()
|
b64 := keyData.Encode()
|
||||||
keyID := gomatrixserverlib.KeyID("ed25519:" + b64)
|
keyID := gomatrixserverlib.KeyID("ed25519:" + b64)
|
||||||
key := gomatrixserverlib.CrossSigningKey{
|
key := gomatrixserverlib.CrossSigningForKey{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
Usage: []gomatrixserverlib.CrossSigningKeyPurpose{
|
Usage: []gomatrixserverlib.CrossSigningKeyPurpose{
|
||||||
keyType,
|
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) {
|
func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysRequest, res *api.QueryKeysResponse) {
|
||||||
res.DeviceKeys = make(map[string]map[string]json.RawMessage)
|
res.DeviceKeys = make(map[string]map[string]json.RawMessage)
|
||||||
res.MasterKeys = make(map[string]gomatrixserverlib.CrossSigningKey)
|
res.MasterKeys = make(map[string]gomatrixserverlib.CrossSigningForKey)
|
||||||
res.SelfSigningKeys = make(map[string]gomatrixserverlib.CrossSigningKey)
|
res.SelfSigningKeys = make(map[string]gomatrixserverlib.CrossSigningForKey)
|
||||||
res.UserSigningKeys = make(map[string]gomatrixserverlib.CrossSigningKey)
|
res.UserSigningKeys = make(map[string]gomatrixserverlib.CrossSigningForKey)
|
||||||
res.Failures = make(map[string]interface{})
|
res.Failures = make(map[string]interface{})
|
||||||
|
|
||||||
// get cross-signing keys from the database
|
// 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 {
|
httputil.MakeInternalAPI("performUploadDeviceSignatures", func(req *http.Request) util.JSONResponse {
|
||||||
request := api.PerformUploadDeviceSignaturesRequest{}
|
request := api.PerformUploadDeviceSignaturesRequest{}
|
||||||
response := api.PerformUploadDeviceSignaturesResponse{}
|
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())
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
s.PerformUploadDeviceSignatures(req.Context(), &request, &response)
|
s.PerformUploadDeviceSignatures(req.Context(), &request, &response)
|
||||||
|
|
Loading…
Reference in a new issue