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

feat(crypto/keyring): add Linux's keyctl support #17607

Closed
wants to merge 13 commits into from
2 changes: 1 addition & 1 deletion crypto/keyring/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,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 (
Expand Down
52 changes: 52 additions & 0 deletions crypto/keyring/keyring_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//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,
}
alessio marked this conversation as resolved.
Show resolved Hide resolved
}

func New(
appName, backend, rootDir string, userInput io.Reader, cdc codec.Codec, opts ...Option,
) (Keyring, error) {
return newSupportedKeyring(appName, backend, rootDir, userInput, cdc, opts...)
}

// 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 newSupportedKeyring(
appName, backend, rootDir string, userInput io.Reader, cdc codec.Codec, opts ...Option,
) (Keyring, error) {
var (
db keyring.Keyring
err error
)
alessio marked this conversation as resolved.
Show resolved Hide resolved

if backend != BackendKeyctl {
return newKeyringGeneric(appName, backend, rootDir, userInput, cdc, opts...)
}

db, err = keyring.Open(newKeyctlBackendConfig(appName, "", userInput))

alessio marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}
alessio marked this conversation as resolved.
Show resolved Hide resolved

return newKeystore(db, cdc, backend, opts...), nil
}
16 changes: 16 additions & 0 deletions crypto/keyring/keyring_other.go
Original file line number Diff line number Diff line change
@@ -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...)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
cosmossdk.io/math v1.1.2
cosmossdk.io/store v1.0.0-rc.0
cosmossdk.io/x/tx v0.9.1
github.com/99designs/keyring v1.2.1
github.com/99designs/keyring v1.2.2
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816
github.com/bits-and-blooms/bitset v1.8.0
github.com/chzyer/readline v1.5.1
Expand Down
Loading