Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate Keystores Validator Client RPC Endpoint #9799

Merged
merged 9 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,337 changes: 706 additions & 631 deletions proto/prysm/v1alpha1/validator-client/web_api.pb.go

Large diffs are not rendered by default.

80 changes: 48 additions & 32 deletions proto/prysm/v1alpha1/validator-client/web_api.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions proto/prysm/v1alpha1/validator-client/web_api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ service Wallet {
get: "/v2/validator/wallet"
};
}
rpc GenerateMnemonic(google.protobuf.Empty) returns (GenerateMnemonicResponse) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unused and no plans to ever bring it back

rpc ImportKeystores(ImportKeystoresRequest) returns (ImportKeystoresResponse) {
option (google.api.http) = {
get: "/v2/validator/mnemonic/generate"
post: "/v2/validator/wallet/keystores/import",
body: "*"
};
}
rpc ImportKeystores(ImportKeystoresRequest) returns (ImportKeystoresResponse) {
rpc ValidateKeystores(ValidateKeystoresRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
post: "/v2/validator/wallet/keystores/import",
post: "/v2/validator/wallet/keystores/validate",
body: "*"
};
}
Expand Down Expand Up @@ -248,6 +249,14 @@ message RecoverWalletRequest {
string mnemonic25th_word = 5;
}

message ValidateKeystoresRequest {
// JSON-encoded keystore files to validate.
repeated string keystores = 1;

// Password for the keystore files.
string keystores_password = 2;
}

message ListAccountsRequest {
// Whether or not to return the raw RLP deposit tx data.
bool get_deposit_tx_data = 1;
Expand Down
2 changes: 1 addition & 1 deletion validator/accounts/accounts_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func ListAccountsCli(cliCtx *cli.Context) error {
return errors.Wrap(err, "could not open wallet")
}
km, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
if err != nil && strings.Contains(err.Error(), "invalid checksum") {
if err != nil && strings.Contains(err.Error(), keymanager.IncorrectPasswordErrMsg) {
return errors.New("wrong wallet password entered")
}
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions validator/keymanager/imported/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (km *Keymanager) attemptDecryptKeystore(
var privKeyBytes []byte
var err error
privKeyBytes, err = enc.Decrypt(keystore.Crypto, password)
doesNotDecrypt := err != nil && strings.Contains(err.Error(), "invalid checksum")
doesNotDecrypt := err != nil && strings.Contains(err.Error(), keymanager.IncorrectPasswordErrMsg)
for doesNotDecrypt {
password, err = prompt.PasswordPrompt(
fmt.Sprintf("Password incorrect for key 0x%s, input correct password", keystore.Pubkey), prompt.NotEmpty,
Expand All @@ -94,12 +94,12 @@ func (km *Keymanager) attemptDecryptKeystore(
return nil, nil, "", fmt.Errorf("could not read keystore password: %w", err)
}
privKeyBytes, err = enc.Decrypt(keystore.Crypto, password)
doesNotDecrypt = err != nil && strings.Contains(err.Error(), "invalid checksum")
if err != nil && !strings.Contains(err.Error(), "invalid checksum") {
doesNotDecrypt = err != nil && strings.Contains(err.Error(), keymanager.IncorrectPasswordErrMsg)
if err != nil && !strings.Contains(err.Error(), keymanager.IncorrectPasswordErrMsg) {
return nil, nil, "", errors.Wrap(err, "could not decrypt keystore")
}
}
if err != nil && !strings.Contains(err.Error(), "invalid checksum") {
if err != nil && !strings.Contains(err.Error(), keymanager.IncorrectPasswordErrMsg) {
return nil, nil, "", errors.Wrap(err, "could not decrypt keystore")
}
var pubKeyBytes []byte
Expand Down
3 changes: 2 additions & 1 deletion validator/keymanager/imported/keymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/prysmaticlabs/prysm/runtime/interop"
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
"github.com/prysmaticlabs/prysm/validator/accounts/petnames"
"github.com/prysmaticlabs/prysm/validator/keymanager"
"github.com/sirupsen/logrus"
keystorev4 "github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4"
"go.opencensus.io/trace"
Expand Down Expand Up @@ -271,7 +272,7 @@ func (km *Keymanager) initializeAccountKeystore(ctx context.Context) error {
password := km.wallet.Password()
decryptor := keystorev4.New()
enc, err := decryptor.Decrypt(keystoreFile.Crypto, password)
if err != nil && strings.Contains(err.Error(), "invalid checksum") {
if err != nil && strings.Contains(err.Error(), keymanager.IncorrectPasswordErrMsg) {
return errors.Wrap(err, "wrong password for wallet entered")
} else if err != nil {
return errors.Wrap(err, "could not decrypt keystore")
Expand Down
4 changes: 4 additions & 0 deletions validator/keymanager/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const (
Remote
)

// IncorrectPasswordErrMsg defines a common error string representing an EIP-2335
// keystore password was incorrect.
const IncorrectPasswordErrMsg = "invalid checksum"

// String marshals a keymanager kind to a string value.
func (k Kind) String() string {
switch k {
Expand Down
3 changes: 3 additions & 0 deletions validator/rpc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ go_library(
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_tyler_smith_go_bip39//:go_default_library",
"@com_github_tyler_smith_go_bip39//wordlists:go_default_library",
"@com_github_wealdtech_go_eth2_wallet_encryptor_keystorev4//:go_default_library",
"@io_bazel_rules_go//proto/wkt:empty_go_proto",
"@io_opencensus_go//plugin/ocgrpc:go_default_library",
"@org_golang_google_grpc//:go_default_library",
Expand Down Expand Up @@ -82,6 +83,7 @@ go_test(
"//cmd/validator/flags:go_default_library",
"//config/features:go_default_library",
"//crypto/bls:go_default_library",
"//crypto/rand:go_default_library",
"//encoding/bytesutil:go_default_library",
"//io/file:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
Expand All @@ -105,6 +107,7 @@ go_test(
"@com_github_golang_mock//gomock:go_default_library",
"@com_github_google_uuid//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_tyler_smith_go_bip39//:go_default_library",
"@com_github_wealdtech_go_eth2_wallet_encryptor_keystorev4//:go_default_library",
"@io_bazel_rules_go//proto/wkt:empty_go_proto",
"@org_golang_google_grpc//:go_default_library",
Expand Down
Loading