Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
9ee0b1cb
Commit
9ee0b1cb
authored
3 years ago
by
Bastian Köcher
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Keystore: Store files with permission 600 on unix (#10263)
parent
4920ce5a
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/client/keystore/src/local.rs
+36
-8
36 additions, 8 deletions
substrate/client/keystore/src/local.rs
with
36 additions
and
8 deletions
substrate/client/keystore/src/local.rs
+
36
−
8
View file @
9ee0b1cb
...
...
@@ -364,8 +364,7 @@ impl KeystoreInner {
let
path
=
path
.into
();
fs
::
create_dir_all
(
&
path
)
?
;
let
instance
=
Self
{
path
:
Some
(
path
),
additional
:
HashMap
::
new
(),
password
};
Ok
(
instance
)
Ok
(
Self
{
path
:
Some
(
path
),
additional
:
HashMap
::
new
(),
password
})
}
/// Get the password for this store.
...
...
@@ -397,10 +396,9 @@ impl KeystoreInner {
/// Places it into the file system store, if a path is configured.
fn
insert_unknown
(
&
self
,
key_type
:
KeyTypeId
,
suri
:
&
str
,
public
:
&
[
u8
])
->
Result
<
()
>
{
if
let
Some
(
path
)
=
self
.key_file_path
(
public
,
key_type
)
{
let
mut
file
=
File
::
create
(
path
)
.map_err
(
Error
::
Io
)
?
;
serde_json
::
to_writer
(
&
file
,
&
suri
)
.map_err
(
Error
::
Json
)
?
;
file
.flush
()
.map_err
(
Error
::
Io
)
?
;
Self
::
write_to_file
(
path
,
suri
)
?
;
}
Ok
(())
}
...
...
@@ -411,15 +409,29 @@ impl KeystoreInner {
fn
generate_by_type
<
Pair
:
PairT
>
(
&
mut
self
,
key_type
:
KeyTypeId
)
->
Result
<
Pair
>
{
let
(
pair
,
phrase
,
_
)
=
Pair
::
generate_with_phrase
(
self
.password
());
if
let
Some
(
path
)
=
self
.key_file_path
(
pair
.public
()
.as_slice
(),
key_type
)
{
let
mut
file
=
File
::
create
(
path
)
?
;
serde_json
::
to_writer
(
&
file
,
&
phrase
)
?
;
file
.flush
()
?
;
Self
::
write_to_file
(
path
,
&
phrase
)
?
;
}
else
{
self
.insert_ephemeral_pair
(
&
pair
,
&
phrase
,
key_type
);
}
Ok
(
pair
)
}
/// Write the given `data` to `file`.
fn
write_to_file
(
file
:
PathBuf
,
data
:
&
str
)
->
Result
<
()
>
{
let
mut
file
=
File
::
create
(
file
)
?
;
serde_json
::
to_writer
(
&
file
,
data
)
?
;
file
.flush
()
?
;
#[cfg(target_family
=
"unix"
)]
{
use
std
::
os
::
unix
::
fs
::
PermissionsExt
;
file
.set_permissions
(
fs
::
Permissions
::
from_mode
(
0o600
))
?
;
}
Ok
(())
}
/// Create a new key from seed.
///
/// Does not place it into the file system store.
...
...
@@ -735,4 +747,20 @@ mod tests {
SyncCryptoStore
::
sr25519_generate_new
(
&
store
,
TEST_KEY_TYPE
,
None
)
.unwrap
();
assert_eq!
(
SyncCryptoStore
::
sr25519_public_keys
(
&
store
,
TEST_KEY_TYPE
)
.len
(),
2
);
}
#[test]
#[cfg(target_family
=
"unix"
)]
fn
uses_correct_file_permissions_on_unix
()
{
use
std
::
os
::
unix
::
fs
::
PermissionsExt
;
let
temp_dir
=
TempDir
::
new
()
.unwrap
();
let
store
=
LocalKeystore
::
open
(
temp_dir
.path
(),
None
)
.unwrap
();
let
public
=
SyncCryptoStore
::
sr25519_generate_new
(
&
store
,
TEST_KEY_TYPE
,
None
)
.unwrap
();
let
path
=
store
.0
.read
()
.key_file_path
(
public
.as_ref
(),
TEST_KEY_TYPE
)
.unwrap
();
let
permissions
=
File
::
open
(
path
)
.unwrap
()
.metadata
()
.unwrap
()
.permissions
();
assert_eq!
(
0o100600
,
permissions
.mode
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment