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
c2c936c5
Commit
c2c936c5
authored
5 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#123
add authentication from Scuttlebutt .ssb/secret file
add test and example
parent
a29a2011
No related branches found
No related tags found
1 merge request
!101
Release 0.57.0
Pipeline
#8584
passed
5 years ago
Stage: format
Stage: test
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
duniterpy/key/signing_key.py
+28
-0
28 additions, 0 deletions
duniterpy/key/signing_key.py
examples/load_scuttlebutt_file.py
+24
-0
24 additions, 0 deletions
examples/load_scuttlebutt_file.py
tests/key/test_signing_key.py
+34
-0
34 additions, 0 deletions
tests/key/test_signing_key.py
with
86 additions
and
0 deletions
duniterpy/key/signing_key.py
+
28
−
0
View file @
c2c936c5
...
...
@@ -3,6 +3,7 @@ duniter public and private keys
@author: inso, vtexier, Moul
"""
import
base64
import
re
from
typing
import
Optional
,
Union
,
TypeVar
,
Type
...
...
@@ -469,3 +470,30 @@ Data: {data}""".format(
version
=
version
,
data
=
ewif_key
)
)
@classmethod
def
from_ssb_file
(
cls
:
Type
[
SigningKeyType
],
path
:
str
)
->
SigningKeyType
:
"""
Return SigningKey instance from ScuttleButt .ssb/secret file
:param path: Path to Scuttlebutt secret file
"""
with
open
(
path
,
"
r
"
)
as
fh
:
ssb_content
=
fh
.
read
()
# check data field
regex
=
re
.
compile
(
'
{
\\
s*
"
curve
"
:
"
ed25519
"
,
\\
s*
"
public
"
:
"
(.+)
\\
.ed25519
"
,
\\
s*
"
private
"
:
\\
s*
"
(.+)
\\
.ed25519
"
,
\\
s*
"
id
"
:
\\
s*
"
@
\\
1.ed25519
"
\\
s*}
'
,
re
.
MULTILINE
,
)
match
=
re
.
search
(
regex
,
ssb_content
)
if
not
match
:
raise
Exception
(
"
Error: Bad scuttlebutt secret file
"
)
# capture ssb secret key
secret
=
match
.
groups
()[
1
]
# extract seed from secret
seed
=
bytes
(
base64
.
b64decode
(
secret
)[
0
:
32
])
return
cls
(
seed
)
This diff is collapsed.
Click to expand it.
examples/load_scuttlebutt_file.py
0 → 100644
+
24
−
0
View file @
c2c936c5
import
sys
from
duniterpy.key
import
SigningKey
if
__name__
==
"
__main__
"
:
if
len
(
sys
.
argv
)
<
2
:
print
(
"""
Usage:
python load_scuttlebutt_file.py FILEPATH
"""
)
# capture filepath argument
scuttlebutt_filepath
=
sys
.
argv
[
1
]
# create SigningKey instance from file
signing_key_instance
=
SigningKey
.
from_ssb_file
(
scuttlebutt_filepath
)
# type: SigningKey
# print pubkey
print
(
"
Public key from scuttlebutt file: {}
"
.
format
(
signing_key_instance
.
pubkey
))
This diff is collapsed.
Click to expand it.
tests/key/test_signing_key.py
+
34
−
0
View file @
c2c936c5
...
...
@@ -93,3 +93,37 @@ class TestSigningKey(unittest.TestCase):
self
.
assertEqual
(
sign_key_test
.
sk
,
sign_key_load
.
sk
)
self
.
assertEqual
(
sign_key_test
.
pubkey
,
sign_key_load
.
pubkey
)
self
.
assertEqual
(
sign_key_test
.
vk
,
sign_key_load
.
vk
)
def
test_load_ssb_file
(
self
):
dummy_content
=
"""
# comments
#
#
{
"
curve
"
:
"
ed25519
"
,
"
public
"
:
"
dGVzdHRlc3R0ZXN0dGV0c3RldHN0dGV0c3RldGV0ZXRldHN0ZXR0c3RldHN0dGV0c3Q=.ed25519
"
,
"
private
"
:
"
dGVzdHRlc3R0ZXN0dGV0c3RldHN0dGV0c3RldGV0ZXRldHN0ZXR0c3RldHN0dGV0c3Q==.ed25519
"
,
"
id
"
:
"
@qJ8qVfXU2mIWG9WfKIRsd6GDscQlErzPHsxzHcyQMWQ=.ed25519
"
}
#
# comments
"""
# create dummy .ssb/secret file
with
open
(
TEST_FILE_PATH
,
"
w
"
)
as
fh
:
fh
.
write
(
dummy_content
)
# test load file
sign_key_load
=
SigningKey
.
from_credentials_file
(
TEST_FILE_PATH
)
self
.
assertEqual
(
sign_key_load
.
pubkey
,
"
FAhCeyWq2Ni2xZS3hmYk5w95f8ELxNhUVvU5VB2LXy49
"
)
self
.
assertEqual
(
sign_key_load
.
sk
.
hex
(),
"
f2f7ae68635dba3455390a74ca0811e4c06142229bb58556aaa37d5598548c9ed27f4cb2bfadbaf45b61714b896d4639ab90db035aee746611cdd342bdaa8996
"
,
)
self
.
assertEqual
(
sign_key_load
.
vk
.
hex
(),
"
d27f4cb2bfadbaf45b61714b896d4639ab90db035aee746611cdd342bdaa8996
"
,
)
This diff is collapsed.
Click to expand it.
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