refactor: remove one usage of our bcrypt fork (#15154)

This commit is contained in:
Facundo Medica 2023-02-24 14:52:05 -03:00 committed by GitHub
parent 41690532be
commit 8e01d3f90f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 4 deletions

View File

@ -12,17 +12,17 @@ import (
"github.com/99designs/keyring"
"github.com/cockroachdb/errors"
cmtcrypto "github.com/cometbft/cometbft/crypto"
"github.com/cosmos/go-bip39"
errorsmod "cosmossdk.io/errors"
"golang.org/x/crypto/bcrypt"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keys/bcrypt"
"github.com/cosmos/cosmos-sdk/crypto/ledger"
"github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -751,8 +751,7 @@ func newRealPrompt(dir string, buf io.Reader) func(string) (string, error) {
continue
}
saltBytes := cmtcrypto.CRandBytes(16)
passwordHash, err := bcrypt.GenerateFromPassword(saltBytes, []byte(pass), 2)
passwordHash, err := bcrypt.GenerateFromPassword([]byte(pass), 2)
if err != nil {
fmt.Fprintln(os.Stderr, err)
continue

View File

@ -12,13 +12,16 @@ import (
"testing"
"github.com/99designs/keyring"
cmtcrypto "github.com/cometbft/cometbft/crypto"
"github.com/stretchr/testify/require"
"golang.org/x/crypto/bcrypt"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/hd"
cosmosbcrypt "github.com/cosmos/cosmos-sdk/crypto/keys/bcrypt"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
@ -1949,6 +1952,32 @@ func TestRenameKey(t *testing.T) {
}
}
// TestChangeBcrypt tests the compatibility from upstream Bcrypt and our own
func TestChangeBcrypt(t *testing.T) {
pw := []byte("somepasswword!")
saltBytes := cmtcrypto.CRandBytes(16)
cosmosHash, err := cosmosbcrypt.GenerateFromPassword(saltBytes, pw, 2)
require.NoError(t, err)
bcryptHash, err := bcrypt.GenerateFromPassword(pw, 2)
require.NoError(t, err)
// Check the new hash with the old bcrypt, vice-versa and with the same
// bcrypt version just because.
err = cosmosbcrypt.CompareHashAndPassword(bcryptHash, pw)
require.NoError(t, err)
err = cosmosbcrypt.CompareHashAndPassword(cosmosHash, pw)
require.NoError(t, err)
err = bcrypt.CompareHashAndPassword(cosmosHash, pw)
require.NoError(t, err)
err = bcrypt.CompareHashAndPassword(bcryptHash, pw)
require.NoError(t, err)
}
func requireEqualRenamedKey(t *testing.T, key *Record, mnemonic *Record, nameMatch bool) {
if nameMatch {
require.Equal(t, key.Name, mnemonic.Name)