Skip to content

Commit

Permalink
Trim whitespace from passwords by default
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Broadhurst <[email protected]>
  • Loading branch information
peterbroadhurst committed Oct 5, 2022
1 parent f9bcfa8 commit 8b6cfe4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ nav_order: 2
|---|-----------|----|-------------|
|passwordExt|Optional to use to look up password files, that sit next to the key files directly. Alternative to metadata when you have a password per keystore|string|`<nil>`
|passwordPath|Optional directory in which to look for the password files, when passwordExt is configured. Default is the wallet directory|string|`<nil>`
|passwordTrimSpace|Whether to trim leading/trailing whitespace (such as a newline) from the password when loaded from file|boolean|`true`
|primaryExt|Extension for key/metadata files named by <ADDRESS>.<EXT>|string|`<nil>`
|primaryMatchRegex|Regular expression run against key/metadata filenames to extract the address (takes precedence over primaryExt)|regexp|`<nil>`
|with0xPrefix|When true and passwordExt is used, password filenames will be generated with an 0x prefix|boolean|`<nil>`
Expand Down
1 change: 1 addition & 0 deletions internal/signermsgs/en_config_descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
ConfigFileWalletFilenamesPrimaryExt = ffc("config.fileWallet.filenames.primaryExt", "Extension for key/metadata files named by <ADDRESS>.<EXT>", "string")
ConfigFileWalletFilenamesPasswordExt = ffc("config.fileWallet.filenames.passwordExt", "Optional to use to look up password files, that sit next to the key files directly. Alternative to metadata when you have a password per keystore", "string")
ConfigFileWalletFilenamesPasswordPath = ffc("config.fileWallet.filenames.passwordPath", "Optional directory in which to look for the password files, when passwordExt is configured. Default is the wallet directory", "string")
ConfigFileWalletFilenamesPasswordTrimSpace = ffc("config.fileWallet.filenames.passwordTrimSpace", "Whether to trim leading/trailing whitespace (such as a newline) from the password when loaded from file", "boolean")
ConfigFileWalletDefaultPasswordFile = ffc("config.fileWallet.defaultPasswordFile", "Optional default password file to use, if one is not specified individually for the key (via metadata, or file extension)", "string")
ConfigFileWalletDisableListener = ffc("config.fileWallet.disableListener", "Disable the filesystem listener that automatically detects the creation of new keystore files", "boolean")
ConfigFileWalletSignerCacheSize = ffc("config.fileWallet.signerCacheSize", "Maximum of signing keys to hold in memory", "number")
Expand Down
5 changes: 5 additions & 0 deletions pkg/fswallet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const (
ConfigFilenamesPasswordExt = "filenames.passwordExt"
// ConfigFilenamesPasswordPath directory path where the password files should be found - default is the same path as the primary file
ConfigFilenamesPasswordPath = "filenames.passwordPath"
// ConfigFilenamesPasswordTrimSpace whether to trim whitespace from passwords loaded from files (such as trailing newline characters)
ConfigFilenamesPasswordTrimSpace = "filenames.passwordTrimSpace"
// ConfigDefaultPasswordFile default password file to use if neither the metadata, or passwordExtension find a password
ConfigDefaultPasswordFile = "defaultPasswordFile"
// ConfigDisableListener disable the filesystem listener that detects newly added keys automatically
Expand Down Expand Up @@ -64,6 +66,7 @@ type FilenamesConfig struct {
PrimaryExt string
PasswordExt string
PasswordPath string
PasswordTrimSpace bool
With0xPrefix bool
}

Expand All @@ -79,6 +82,7 @@ func InitConfig(section config.Section) {
section.AddKnownKey(ConfigFilenamesPrimaryMatchRegex)
section.AddKnownKey(ConfigFilenamesPasswordExt)
section.AddKnownKey(ConfigFilenamesPasswordPath)
section.AddKnownKey(ConfigFilenamesPasswordTrimSpace, true)
section.AddKnownKey(ConfigFilenamesWith0xPrefix)
section.AddKnownKey(ConfigDisableListener)
section.AddKnownKey(ConfigDefaultPasswordFile)
Expand All @@ -101,6 +105,7 @@ func ReadConfig(section config.Section) *Config {
PrimaryMatchRegex: section.GetString(ConfigFilenamesPrimaryMatchRegex),
PasswordExt: section.GetString(ConfigFilenamesPasswordExt),
PasswordPath: section.GetString(ConfigFilenamesPasswordPath),
PasswordTrimSpace: section.GetBool(ConfigFilenamesPasswordTrimSpace),
With0xPrefix: section.GetBool(ConfigFilenamesWith0xPrefix),
},
Metadata: MetadataConfig{
Expand Down
2 changes: 2 additions & 0 deletions pkg/fswallet/fswallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ func (w *fsWallet) loadWalletFile(ctx context.Context, addr ethtypes.Address0xHe
password, err = ioutil.ReadFile(passwordFilename)
if err != nil {
log.L(ctx).Debugf("Failed to read '%s' (password file): %s", passwordFilename, err)
} else if w.conf.Filenames.PasswordTrimSpace {
password = []byte(strings.TrimSpace(string(password)))
}
}

Expand Down

0 comments on commit 8b6cfe4

Please sign in to comment.