diff --git a/crypto/keyring/keyring.go b/crypto/keyring/keyring.go index 05dac4822fcf..19ae87211353 100644 --- a/crypto/keyring/keyring.go +++ b/crypto/keyring/keyring.go @@ -176,7 +176,7 @@ func NewInMemoryWithKeyring(kr keyring.Keyring, cdc codec.Codec, opts ...Option) // New creates a new instance of a keyring. // Keyring options can be applied when generating the new instance. // Available backends are "os", "file", "kwallet", "memory", "pass", "test". -func New( +func newKeyringGeneric( appName, backend, rootDir string, userInput io.Reader, cdc codec.Codec, opts ...Option, ) (Keyring, error) { var ( diff --git a/crypto/keyring/keyring_linux.go b/crypto/keyring/keyring_linux.go new file mode 100644 index 000000000000..90cd06014c65 --- /dev/null +++ b/crypto/keyring/keyring_linux.go @@ -0,0 +1,41 @@ +//go:build linux +// +build linux + +package keyring + +import ( + "io" + + "github.com/99designs/keyring" + "github.com/cosmos/cosmos-sdk/codec" +) + +const BackendKeyctl = "keyctl" + +func newKeyctlBackendConfig(appName, _ string, inpt io.Reader) keyring.Config { + return keyring.Config{ + AllowedBackends: []keyring.BackendType{keyring.KeyCtlBackend}, + ServiceName: appName, + KeyCtlScope: "user", + KeyCtlPerm: 0x3f3f0000, + } +} + +// New creates a new instance of a keyring. +// Keyring options can be applied when generating the new instance. +// Available backends are "os", "file", "kwallet", "memory", "pass", "test". +func New( + appName, backend, rootDir string, userInput io.Reader, cdc codec.Codec, opts ...Option, +) (Keyring, error) { + + if backend != BackendKeyctl { + return newKeyringGeneric(appName, backend, rootDir, userInput, cdc, opts...) + } + + db, err := keyring.Open(newKeyctlBackendConfig(appName, "", userInput)) + if err != nil { + return nil, err + } + + return newKeystore(db, cdc, backend, opts...), nil +} diff --git a/crypto/keyring/keyring_other.go b/crypto/keyring/keyring_other.go new file mode 100644 index 000000000000..48b90fe5dd1e --- /dev/null +++ b/crypto/keyring/keyring_other.go @@ -0,0 +1,16 @@ +//go:build !linux +// +build !linux + +package keyring + +import ( + "io" + + "github.com/cosmos/cosmos-sdk/codec" +) + +func New( + appName, backend, rootDir string, userInput io.Reader, cdc codec.Codec, opts ...Option, +) (Keyring, error) { + return newKeyringGeneric(appName, backend, rootDir, userInput, cdc, opts...) +}