Tak/pull-dendrite-changes (#245)

* Fix issues with migrations not getting executed (#2628)

* Fix issues with migrations not getting executed

* Check actual postgres error

* Return error if it's not "column does not exist"

* Remove nonce generation for eip4361 signin (#25)

Co-authored-by: Tak Wai Wong <tak@hntlabs.com>
This commit is contained in:
Tak Wai Wong 2022-08-09 15:23:56 -07:00
parent b41086e758
commit cc98ffb362
No known key found for this signature in database
GPG key ID: 222E4AF2AA1F467D
3 changed files with 2 additions and 31 deletions

View file

@ -61,7 +61,6 @@ func TestLoginPublicKeyNewSession(t *testing.T) {
"err.Code actual: %v, expected: %v", err.Code, http.StatusUnauthorized) "err.Code actual: %v, expected: %v", err.Code, http.StatusUnauthorized)
challenge := err.JSON.(Challenge) challenge := err.JSON.(Challenge)
assert.NotEmptyf(challenge.Session, "challenge.Session") assert.NotEmptyf(challenge.Session, "challenge.Session")
assert.NotEmptyf(challenge.Completed, "challenge.Completed")
assert.Truef( assert.Truef(
authtypes.LoginTypePublicKeyEthereum == challenge.Flows[0].Stages[0], authtypes.LoginTypePublicKeyEthereum == challenge.Flows[0].Stages[0],
"challenge.Flows[0].Stages[0] actual: %v, expected: %v", challenge.Flows[0].Stages[0], authtypes.LoginTypePublicKeyEthereum) "challenge.Flows[0].Stages[0] actual: %v, expected: %v", challenge.Flows[0].Stages[0], authtypes.LoginTypePublicKeyEthereum)
@ -74,7 +73,6 @@ func TestLoginPublicKeyNewSession(t *testing.T) {
"[object]") "[object]")
ethParams := params.(config.EthereumAuthParams) ethParams := params.(config.EthereumAuthParams)
assert.NotEmptyf(ethParams.ChainIDs, "ChainIDs actual: empty, expected not empty") assert.NotEmptyf(ethParams.ChainIDs, "ChainIDs actual: empty, expected not empty")
assert.NotEmptyf(ethParams.Nonce, "Nonce actual: \"\", expected: not empty")
assert.NotEmptyf(ethParams.Version, "Version actual: \"\", expected: not empty") assert.NotEmptyf(ethParams.Version, "Version actual: \"\", expected: not empty")
} }

View file

@ -340,7 +340,6 @@ func TestNewRegistrationSession(t *testing.T) {
"[object]") "[object]")
ethParams := params.(config.EthereumAuthParams) ethParams := params.(config.EthereumAuthParams)
assert.NotEmptyf(ethParams.ChainIDs, "ChainIDs actual: empty, expected not empty") assert.NotEmptyf(ethParams.ChainIDs, "ChainIDs actual: empty, expected not empty")
assert.NotEmptyf(ethParams.Nonce, "Nonce actual: \"\", expected: not empty")
assert.NotEmptyf(ethParams.Version, "Version actual: \"\", expected: not empty") assert.NotEmptyf(ethParams.Version, "Version actual: \"\", expected: not empty")
} }

View file

@ -1,37 +1,25 @@
package config package config
import ( import (
"math/rand"
"time"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/authtypes"
) )
var nonceLength = 32
type AuthParams interface { type AuthParams interface {
GetParams() interface{} GetParams() interface{}
GetNonce() string
} }
type EthereumAuthParams struct { type EthereumAuthParams struct {
Version uint `json:"version"` Version uint `json:"version"`
ChainIDs []int `json:"chain_ids"` ChainIDs []int `json:"chain_ids"`
Nonce string `json:"nonce"`
} }
func (p EthereumAuthParams) GetParams() interface{} { func (p EthereumAuthParams) GetParams() interface{} {
copyP := p copyP := p
copyP.ChainIDs = make([]int, len(p.ChainIDs)) copyP.ChainIDs = make([]int, len(p.ChainIDs))
copy(copyP.ChainIDs, p.ChainIDs) copy(copyP.ChainIDs, p.ChainIDs)
copyP.Nonce = newNonce(nonceLength)
return copyP return copyP
} }
func (p EthereumAuthParams) GetNonce() string {
return p.Nonce
}
type EthereumAuthConfig struct { type EthereumAuthConfig struct {
Enabled bool `yaml:"enabled"` Enabled bool `yaml:"enabled"`
Version uint `yaml:"version"` Version uint `yaml:"version"`
@ -61,23 +49,9 @@ func (pk *PublicKeyAuthentication) GetPublicKeyRegistrationParams() map[string]i
p := EthereumAuthParams{ p := EthereumAuthParams{
Version: pk.Ethereum.Version, Version: pk.Ethereum.Version,
ChainIDs: pk.Ethereum.ChainIDs, ChainIDs: pk.Ethereum.ChainIDs,
Nonce: "",
} }
params[authtypes.LoginTypePublicKeyEthereum] = p params[authtypes.LoginTypePublicKeyEthereum] = p
} }
return params return params
} }
const lettersAndNumbers = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
func newNonce(n int) string {
nonce := make([]byte, n)
rand.Seed(time.Now().UnixNano())
for i := range nonce {
nonce[i] = lettersAndNumbers[rand.Int63()%int64(len(lettersAndNumbers))]
}
return string(nonce)
}