Skip to content

Commit 99206ed

Browse files
Alessio Tregliaalessio
authored andcommitted
keyring: new keyctl backend
keyctl is a Linux kernel's interface to help protect cryptohtaphic data from a whole class of potential security vulnerabilities. The Keyctl backend leverages such Linux's kernel feature to store keys in memory securely. For more information, please see: https://docs.kernel.org/security/keys/core.html The keyctl backend is available on Linux platforms only.
1 parent 4fe934e commit 99206ed

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
4444

4545
* (baseapp) [#20291](https://github.com/cosmos/cosmos-sdk/pull/20291) Simulate nested messages.
4646
* (cli) [#21372](https://github.com/cosmos/cosmos-sdk/pull/21372) Add a `bulk-add-genesis-account` genesis command to add many genesis accounts at once.
47+
* (crypto/keyring) [#21653](https://github.com/cosmos/cosmos-sdk/pull/21653) New Linux-only backend that adds Linux kernel's `keyctl` support.
4748

4849
### Improvements
4950

crypto/keyring/keyring.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func NewInMemoryWithKeyring(kr keyring.Keyring, cdc codec.Codec, opts ...Option)
180180
// New creates a new instance of a keyring.
181181
// Keyring options can be applied when generating the new instance.
182182
// Available backends are "os", "file", "kwallet", "memory", "pass", "test".
183-
func New(
183+
func newKeyringGeneric(
184184
appName, backend, rootDir string, userInput io.Reader, cdc codec.Codec, opts ...Option,
185185
) (Keyring, error) {
186186
var (

crypto/keyring/keyring_linux.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//go:build linux
2+
// +build linux
3+
4+
package keyring
5+
6+
import (
7+
"fmt"
8+
"io"
9+
10+
"github.com/99designs/keyring"
11+
"github.com/cosmos/cosmos-sdk/codec"
12+
)
13+
14+
const BackendKeyctl = "keyctl"
15+
16+
func newKeyctlBackendConfig(appName, _ string, _ io.Reader) keyring.Config {
17+
return keyring.Config{
18+
AllowedBackends: []keyring.BackendType{keyring.KeyCtlBackend},
19+
ServiceName: appName,
20+
KeyCtlScope: "user",
21+
KeyCtlPerm: 0x3f3f0000,
22+
}
23+
}
24+
25+
// New creates a new instance of a keyring.
26+
// Keyring options can be applied when generating the new instance.
27+
// Available backends are "os", "file", "kwallet", "memory", "pass", "test".
28+
func New(
29+
appName, backend, rootDir string, userInput io.Reader, cdc codec.Codec, opts ...Option,
30+
) (Keyring, error) {
31+
32+
if backend != BackendKeyctl {
33+
return newKeyringGeneric(appName, backend, rootDir, userInput, cdc, opts...)
34+
}
35+
36+
db, err := keyring.Open(newKeyctlBackendConfig(appName, "", userInput))
37+
if err != nil {
38+
return nil, fmt.Errorf("couldn't open keyring for %q: %w", appName, err)
39+
}
40+
41+
return newKeystore(db, cdc, backend, opts...), nil
42+
}

crypto/keyring/keyring_other.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//go:build !linux
2+
// +build !linux
3+
4+
package keyring
5+
6+
import (
7+
"io"
8+
9+
"github.com/cosmos/cosmos-sdk/codec"
10+
)
11+
12+
func New(
13+
appName, backend, rootDir string, userInput io.Reader, cdc codec.Codec, opts ...Option,
14+
) (Keyring, error) {
15+
return newKeyringGeneric(appName, backend, rootDir, userInput, cdc, opts...)
16+
}

0 commit comments

Comments
 (0)