diff --git a/authutils/auth_service.go b/authutils/auth_service.go index a6899df1..a9d97364 100755 --- a/authutils/auth_service.go +++ b/authutils/auth_service.go @@ -18,6 +18,11 @@ import ( // Extracts the signer address from signature given the signature // It returns signer address and error. nil error indicates the successful function execution + +const ( + AllowedBlockChainDifference = 5 +) + func GetSignerAddressFromMessage(message, signature []byte) (signer *common.Address, err error) { log := log.WithFields(log.Fields{ "message": blockchain.BytesToBase64(message), @@ -71,8 +76,8 @@ func CompareWithLatestBlockNumber(blockNumberPassed *big.Int) error { return err } differenceInBlockNumber := blockNumberPassed.Sub(blockNumberPassed, latestBlockNumber) - if differenceInBlockNumber.Abs(differenceInBlockNumber).Uint64() > 5 { - return fmt.Errorf("difference between the latest block chain number and the block number passed is %v ", differenceInBlockNumber) + if differenceInBlockNumber.Abs(differenceInBlockNumber).Uint64() > AllowedBlockChainDifference { + return fmt.Errorf("authentication failed as the signature passed has expired") } return nil } diff --git a/authutils/auth_service_test.go b/authutils/auth_service_test.go index e6a974b6..6bf9271c 100644 --- a/authutils/auth_service_test.go +++ b/authutils/auth_service_test.go @@ -10,9 +10,10 @@ import ( func TestCompareWithLatestBlockNumber(t *testing.T) { config.Vip().Set(config.EthereumJsonRpcEndpointKey, "https://ropsten.infura.io") + config.Validate() currentBlockNum, _ := CurrentBlock() err := CompareWithLatestBlockNumber(currentBlockNum.Add(currentBlockNum, big.NewInt(13))) - assert.Equal(t, err.Error(), "difference between the latest block chain number and the block number passed is 13 ") + assert.Equal(t, err.Error(), "authentication failed as the signature passed has expired") currentBlockNum, _ = CurrentBlock() err = CompareWithLatestBlockNumber(currentBlockNum.Add(currentBlockNum, big.NewInt(1)))