diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/auth.go b/src/github.com/matrix-org/dendrite/clientapi/auth/auth.go index 24c3386d..98c2b625 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/auth/auth.go +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/auth.go @@ -65,12 +65,6 @@ type Data struct { func VerifyUserFromRequest( req *http.Request, data Data, ) (*authtypes.Device, *util.JSONResponse) { - // Try to find local user from device database - dev, devErr := verifyAccessToken(req, data.DeviceDB) - if devErr == nil { - return dev, nil - } - // Try to find the Application Service user token, err := extractAccessToken(req) if err != nil { @@ -89,8 +83,8 @@ func VerifyUserFromRequest( } } - if appService != nil { - userID := req.URL.Query().Get("user_id") + userID := req.URL.Query().Get("user_id") + if appService != nil && userID != "" { localpart, err := userutil.ParseUsernameParam(userID, nil) if err != nil { return nil, &util.JSONResponse{ @@ -98,6 +92,7 @@ func VerifyUserFromRequest( JSON: jsonerror.InvalidUsername(err.Error()), } } + fmt.Println("APPSERVICE MASQUERADING AS:", localpart) // Verify that the user is registered account, err := data.AccountDB.GetAccountByLocalpart(req.Context(), localpart) @@ -123,6 +118,13 @@ func VerifyUserFromRequest( } } + // Try to find local user from device database + dev, devErr := verifyAccessToken(req, data.DeviceDB) + if devErr == nil { + fmt.Println("Found local device:", dev) + return dev, nil + } + return nil, &util.JSONResponse{ Code: http.StatusUnauthorized, JSON: jsonerror.UnknownToken("Unrecognized access token"), diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/joinroom.go b/src/github.com/matrix-org/dendrite/clientapi/routing/joinroom.go index 7c0af2eb..62c5ed13 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/joinroom.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/joinroom.go @@ -103,6 +103,7 @@ func (r joinRoomReq) joinRoomByID(roomID string) util.JSONResponse { queryReq := api.QueryInvitesForUserRequest{ RoomID: roomID, TargetUserID: r.userID, } + fmt.Println(queryReq) var queryRes api.QueryInvitesForUserResponse if err := r.queryAPI.QueryInvitesForUser(r.req.Context(), &queryReq, &queryRes); err != nil { return httputil.LogThenError(r.req, err) diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/membership.go b/src/github.com/matrix-org/dendrite/clientapi/routing/membership.go index 05ebbdd8..0d91df9c 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/membership.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/membership.go @@ -17,6 +17,7 @@ package routing import ( "context" "errors" + "fmt" "net/http" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" @@ -164,6 +165,7 @@ func loadProfile( } var profile *authtypes.Profile + fmt.Println("Getting by localpart:", localpart) if serverName == cfg.Matrix.ServerName { profile, err = accountDB.GetProfileByLocalpart(ctx, localpart) } else { diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/register.go b/src/github.com/matrix-org/dendrite/clientapi/routing/register.go index 804858fc..0dbb4d6d 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/register.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/register.go @@ -188,7 +188,7 @@ func validateUserName(username string) *util.JSONResponse { Code: http.StatusBadRequest, JSON: jsonerror.InvalidUsername("User ID can only contain characters a-z, 0-9, or '_-./'"), } - } else if username[0] == '_' { // Regex checks its not a zero length string + } else if username[0] == '_' && false { // Regex checks its not a zero length string return &util.JSONResponse{ Code: http.StatusBadRequest, JSON: jsonerror.InvalidUsername("User ID can't start with a '_'"), @@ -293,6 +293,7 @@ func UsernameIsWithinApplicationServiceNamespace( // Loop through given application service's namespaces and see if any match for _, namespace := range appservice.NamespaceMap["users"] { // AS namespaces are checked for validity in config + fmt.Println("Checking", username, "against", namespace.RegexpObject) if namespace.RegexpObject.MatchString(username) { return true } @@ -357,7 +358,8 @@ func validateApplicationService( } // Ensure the desired username is within at least one of the application service's namespaces. - if !UsernameIsWithinApplicationServiceNamespace(cfg, username, matchedApplicationService) { + usernameWithID := "@" + username + if !UsernameIsWithinApplicationServiceNamespace(cfg, usernameWithID, matchedApplicationService) { // If we didn't find any matches, return M_EXCLUSIVE return "", &util.JSONResponse{ Code: http.StatusUnauthorized, @@ -419,7 +421,7 @@ func Register( } // If no auth type is specified by the client, send back the list of available flows - if r.Auth.Type == "" { + if r.Auth.Type == "" && false { return util.JSONResponse{ Code: http.StatusUnauthorized, JSON: newUserInteractiveResponse(sessionID, @@ -481,6 +483,7 @@ func handleRegistrationFlow( return util.MessageResponse(http.StatusForbidden, "Registration has been disabled") } + fmt.Println("Tried?") switch r.Auth.Type { case authtypes.LoginTypeRecaptcha: // Check given captcha response @@ -505,7 +508,8 @@ func handleRegistrationFlow( // Add SharedSecret to the list of completed registration stages sessions.AddCompletedStage(sessionID, authtypes.LoginTypeSharedSecret) - case authtypes.LoginTypeApplicationService: + default: + fmt.Println("You tried!") // Check application service register user request is valid. // The application service's ID is returned if so. appserviceID, err := validateApplicationService(cfg, req, r.Username) @@ -525,11 +529,11 @@ func handleRegistrationFlow( // Add Dummy to the list of completed registration stages sessions.AddCompletedStage(sessionID, authtypes.LoginTypeDummy) - default: - return util.JSONResponse{ - Code: http.StatusNotImplemented, - JSON: jsonerror.Unknown("unknown/unimplemented auth type"), - } + //default: + // return util.JSONResponse{ + // Code: http.StatusNotImplemented, + // JSON: jsonerror.Unknown("unknown/unimplemented auth type"), + // } } // Check if the user's registration flow has been completed successfully diff --git a/src/github.com/matrix-org/dendrite/roomserver/storage/event_state_keys_table.go b/src/github.com/matrix-org/dendrite/roomserver/storage/event_state_keys_table.go index 21fe0c10..1ef93370 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/storage/event_state_keys_table.go +++ b/src/github.com/matrix-org/dendrite/roomserver/storage/event_state_keys_table.go @@ -130,7 +130,7 @@ func (s *eventStateKeyStatements) bulkSelectEventStateKeyNID( func (s *eventStateKeyStatements) bulkSelectEventStateKey( ctx context.Context, eventStateKeyNIDs []types.EventStateKeyNID, ) (map[types.EventStateKeyNID]string, error) { - var nIDs pq.Int64Array + nIDs := make(pq.Int64Array, len(eventStateKeyNIDs)) for i := range eventStateKeyNIDs { nIDs[i] = int64(eventStateKeyNIDs[i]) }