Merge pull request #72 from HereNotThere/main-merge

Main merge back from Harmony
This commit is contained in:
Brian Meek 2023-02-08 17:06:20 -08:00 committed by GitHub
commit 3fc97630ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 148 additions and 88 deletions

View file

@ -25,6 +25,7 @@ import (
"github.com/matrix-org/dendrite/clientapi/userutil"
"github.com/matrix-org/dendrite/setup/config"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/sirupsen/logrus"
"github.com/spruceid/siwe-go"
)
@ -70,22 +71,27 @@ func (pk LoginPublicKeyEthereum) AccountExists(ctx context.Context) (string, *js
localPart, _, err := userutil.ParseUsernameParam(pk.UserId, pk.config.Matrix)
if err != nil {
// userId does not exist
return "", jsonerror.Forbidden("the address is incorrect, or the account does not exist.")
logrus.WithError(err).Error("the address is incorrect, userId does not exist", pk.UserId)
return "", jsonerror.Forbidden("the address is incorrect, userId does not exist")
}
if !pk.IsValidUserId(localPart) {
logrus.Warn("the username is not valid", pk.UserId, localPart)
return "", jsonerror.InvalidUsername("the username is not valid.")
}
res := userapi.QueryAccountAvailabilityResponse{}
if err := pk.userAPI.QueryAccountAvailability(ctx, &userapi.QueryAccountAvailabilityRequest{
Localpart: localPart,
ServerName: pk.config.Matrix.ServerName,
}, &res); err != nil {
return "", jsonerror.Unknown("failed to check availability: " + err.Error())
logrus.WithError(err).Error("failed to check availability")
return "", jsonerror.Unknown("failed to check availability")
}
if localPart == "" || res.Available {
return "", jsonerror.Forbidden("the address is incorrect, account does not exist")
logrus.Warn("the address is incorrect, or the account does not exist", pk.UserId, localPart, res)
return "", jsonerror.Forbidden("the address is incorrect, or the account does not exist")
}
return localPart, nil
@ -121,7 +127,7 @@ func (pk LoginPublicKeyEthereum) ValidateLoginResponse() (bool, *jsonerror.Matri
// Check signature to verify message was not tempered
_, err = message.Verify(pk.Signature, (*string)(&serverName), nil, nil)
if err != nil {
return false, jsonerror.InvalidSignature(err.Error() + " signature:" + pk.Signature + " server_name:" + string(serverName) + " messageDomain:" + message.GetDomain())
return false, jsonerror.InvalidSignature(fmt.Sprintf("%s signature:%+v server_name:%+v messsage_domain:%+v", err.Error(), pk.Signature, serverName, message.GetDomain()))
}
// Error if the user ID does not match the signed message.

View file

@ -110,6 +110,8 @@ func main() {
userAPI = base.UserAPIClient()
}
if traceInternal {
logrus.Warnf("The traceInternal option is enabled")
userAPI = &uapi.UserInternalAPITrace{
Impl: userAPI,
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long