Use client pseudoid during create room

This commit is contained in:
Devon Hudson 2023-11-02 10:56:25 -06:00
parent b7d320f8d1
commit 7f7ac0f4fe
No known key found for this signature in database
GPG key ID: CD06B18E77F6A628
2 changed files with 26 additions and 15 deletions

View file

@ -115,15 +115,32 @@ func SendPDUs(
JSON: spec.InternalServerError{Err: err.Error()},
}
}
key, err := rsAPI.GetOrCreateUserRoomPrivateKey(req.Context(), *userID, pdu.RoomID())
util.GetLogger(req.Context()).Infof("Processing %s event (%s): %s", pdu.Type(), pdu.EventID(), pdu.JSON())
// Check that the event is signed by the server sending the request.
redacted, err := verImpl.RedactEventJSON(pdu.JSON())
if err != nil {
return util.JSONResponse{
Code: http.StatusInternalServerError,
JSON: spec.InternalServerError{Err: err.Error()},
}
util.GetLogger(req.Context()).WithError(err).Error("RedactEventJSON failed")
continue
}
verifier := gomatrixserverlib.JSONVerifierSelf{}
verifyRequests := []gomatrixserverlib.VerifyJSONRequest{{
ServerName: spec.ServerName(pdu.SenderID()),
Message: redacted,
AtTS: pdu.OriginServerTS(),
ValidityCheckingFunc: gomatrixserverlib.StrictValiditySignatureCheck,
}}
verifyResults, err := verifier.VerifyJSONs(req.Context(), verifyRequests)
if err != nil {
util.GetLogger(req.Context()).WithError(err).Error("keys.VerifyJSONs failed")
continue
}
if verifyResults[0].Error != nil {
util.GetLogger(req.Context()).WithError(verifyResults[0].Error).Error("Signature check failed: ")
continue
}
pdu = pdu.Sign(string(pdu.SenderID()), "ed25519:1", key)
util.GetLogger(req.Context()).Infof("Processing %s event (%s)", pdu.Type(), pdu.EventID())
switch pdu.Type() {
case spec.MRoomCreate:

View file

@ -80,17 +80,11 @@ func (c *Creator) PerformCreateRoomCryptoIDs(ctx context.Context, userID spec.Us
return nil, spec.BadJSON("SenderID is not a valid ed25519 public key")
}
// TODO: cryptoIDs - Swap this out for only storing the public key
key, keyErr := c.RSAPI.GetOrCreateUserRoomPrivateKey(ctx, userID, roomID)
keyErr := c.RSAPI.StoreUserRoomPublicKey(ctx, senderID, userID, roomID)
if keyErr != nil {
util.GetLogger(ctx).WithError(keyErr).Error("GetOrCreateUserRoomPrivateKey failed")
util.GetLogger(ctx).WithError(keyErr).Error("StoreUserRoomPublicKey failed")
return nil, spec.InternalServerError{Err: keyErr.Error()}
}
senderID = spec.SenderIDFromPseudoIDKey(key)
//err := c.RSAPI.StoreUserRoomPublicKey(ctx, senderID, userID, roomID)
//if err != nil {
// return nil, spec.InternalServerError{Err: err.Error()}
//}
}
createContent["creator"] = senderID