Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
clients
python
DuniterPy
Commits
41b60ea4
Commit
41b60ea4
authored
1 year ago
by
Moul
Browse files
Options
Downloads
Patches
Plain Diff
Store authentication file with 600 permissions (
#203
)
parent
0050c779
No related branches found
No related tags found
1 merge request
!185
SigningKey: Allow to pass Path and store auth file with 600 permissions #203
Pipeline
#32550
waiting for manual action
Stage: checks
Stage: tests
Stage: release
Stage: publish_doc
Changes
2
Pipelines
5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
duniterpy/key/signing_key.py
+11
-6
11 additions, 6 deletions
duniterpy/key/signing_key.py
tests/key/test_signing_key.py
+7
-0
7 additions, 0 deletions
tests/key/test_signing_key.py
with
18 additions
and
6 deletions
duniterpy/key/signing_key.py
+
11
−
6
View file @
41b60ea4
...
...
@@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
base64
import
os
import
re
from
hashlib
import
scrypt
,
sha256
from
pathlib
import
Path
...
...
@@ -36,6 +37,10 @@ from .scrypt_params import ScryptParams
SigningKeyType
=
TypeVar
(
"
SigningKeyType
"
,
bound
=
"
SigningKey
"
)
def
opener_user_rw
(
path
,
flags
):
return
os
.
open
(
path
,
flags
,
0o600
)
class
SigningKey
(
libnacl
.
sign
.
Signer
):
def
__init__
(
self
,
seed
:
bytes
)
->
None
:
"""
...
...
@@ -92,7 +97,7 @@ class SigningKey(libnacl.sign.Signer):
:return:
"""
# capture credentials from file
with
open
(
path
,
encoding
=
"
utf-8
"
)
as
fh
:
with
open
(
path
,
encoding
=
"
utf-8
"
,
opener
=
opener_user_rw
)
as
fh
:
lines
=
fh
.
readlines
()
assert
len
(
lines
)
>
1
salt
=
lines
[
0
].
strip
()
...
...
@@ -107,7 +112,7 @@ class SigningKey(libnacl.sign.Signer):
:param path: Authentication file path
"""
seedhex
=
convert_seed_to_seedhex
(
self
.
seed
)
with
open
(
path
,
"
w
"
,
encoding
=
"
utf-8
"
)
as
fh
:
with
open
(
path
,
"
w
"
,
encoding
=
"
utf-8
"
,
opener
=
opener_user_rw
)
as
fh
:
fh
.
write
(
seedhex
)
@staticmethod
...
...
@@ -179,7 +184,7 @@ class SigningKey(libnacl.sign.Signer):
:param path: Path to WIF file
"""
with
open
(
path
,
encoding
=
"
utf-8
"
)
as
fh
:
with
open
(
path
,
encoding
=
"
utf-8
"
,
opener
=
opener_user_rw
)
as
fh
:
pubsec_content
=
fh
.
read
()
# line patterns
...
...
@@ -221,7 +226,7 @@ class SigningKey(libnacl.sign.Signer):
Version:
{
version
}
\n\
pub:
{
self
.
pubkey
}
\n\
sec:
{
base58_signing_key
}
"
with
open
(
path
,
"
w
"
,
encoding
=
"
utf-8
"
)
as
fh
:
with
open
(
path
,
"
w
"
,
encoding
=
"
utf-8
"
,
opener
=
opener_user_rw
)
as
fh
:
fh
.
write
(
content
)
@staticmethod
...
...
@@ -341,7 +346,7 @@ sec: {base58_signing_key}"
content
=
f
"
Type: WIF
\n\
Version:
{
version
}
\n\
Data:
{
wif_key
}
"
with
open
(
path
,
"
w
"
,
encoding
=
"
utf-8
"
)
as
fh
:
with
open
(
path
,
"
w
"
,
encoding
=
"
utf-8
"
,
opener
=
opener_user_rw
)
as
fh
:
fh
.
write
(
content
)
@staticmethod
...
...
@@ -471,7 +476,7 @@ Data: {wif_key}"
content
=
f
"
Type: EWIF
\n\
Version:
{
version
}
\n\
Data:
{
ewif_key
}
"
with
open
(
path
,
"
w
"
,
encoding
=
"
utf-8
"
)
as
fh
:
with
open
(
path
,
"
w
"
,
encoding
=
"
utf-8
"
,
opener
=
opener_user_rw
)
as
fh
:
fh
.
write
(
content
)
@classmethod
...
...
This diff is collapsed.
Click to expand it.
tests/key/test_signing_key.py
+
7
−
0
View file @
41b60ea4
...
...
@@ -52,6 +52,13 @@ class TestSigningKey(unittest.TestCase):
sign_key_load
=
SigningKey
.
from_seedhex_file
(
TEST_FILE_PATH
)
self
.
assertEqual
(
sign_key_save
.
sk
,
sign_key_load
.
sk
)
def
test_permissions_save_seedhex_file
(
self
):
sign_key_save
=
SigningKey
.
from_credentials
(
"
alice
"
,
"
password
"
,
ScryptParams
())
sign_key_save
.
save_seedhex_file
(
TEST_FILE_PATH
)
# https://www.geeksforgeeks.org/how-to-get-the-permission-mask-of-a-file-in-python/
assert
oct
(
os
.
stat
(
TEST_FILE_PATH
).
st_mode
)[
-
3
:]
==
"
600
"
def
test_save_and_load_from_pubsec_file
(
self
):
sign_key_save
=
SigningKey
.
from_credentials
(
"
alice
"
,
"
password
"
,
ScryptParams
())
sign_key_save
.
save_pubsec_file
(
TEST_FILE_PATH
)
...
...
This diff is collapsed.
Click to expand it.
Vincent Texier
@vtexier
mentioned in issue
#93 (closed)
·
1 year ago
mentioned in issue
#93 (closed)
mentioned in issue #93
Toggle commit list
Preview
0%
Loading
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