Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
silkaj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
silkaj
Commits
03ad790a
Commit
03ad790a
authored
5 years ago
by
Moul
Committed by
matograine
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[mod] crypto: Import to-level 're' lib for clarity
- 're.' is not too long
parent
e52b7294
No related branches found
No related tags found
2 merge requests
!146
Merge dev into master branch to complete v0.8.0 development cycle
,
!128
[fix] #278: changing regex for PubSec authfile authentication
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
silkaj/auth.py
+6
-6
6 additions, 6 deletions
silkaj/auth.py
silkaj/crypto_tools.py
+5
-5
5 additions, 5 deletions
silkaj/crypto_tools.py
with
11 additions
and
11 deletions
silkaj/auth.py
+
6
−
6
View file @
03ad790a
...
...
@@ -15,11 +15,11 @@ You should have received a copy of the GNU Affero General Public License
along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
"""
import
re
from
silkaj.tools
import
message_exit
from
click
import
command
,
option
,
pass_context
,
confirm
from
getpass
import
getpass
from
pathlib
import
Path
from
re
import
compile
,
search
,
MULTILINE
from
duniterpy.key
import
SigningKey
from
duniterpy.key.scrypt_params
import
ScryptParams
...
...
@@ -72,16 +72,16 @@ def auth_by_auth_file(ctx):
message_exit
(
'
Error: the file
"'
+
file
+
'"
does not exist
'
)
filetxt
=
authfile
.
open
(
"
r
"
).
read
()
# regex for seed (hexadecimal)
regex_seed
=
compile
(
"
^[0-9a-fA-F]{64}$
"
)
regex_seed
=
re
.
compile
(
"
^[0-9a-fA-F]{64}$
"
)
# two regural expressions for the PubSec format
regex_pubkey
=
compile
(
"
pub: ([1-9A-HJ-NP-Za-km-z]{43,44})
"
,
MULTILINE
)
regex_signkey
=
compile
(
"
sec: ([1-9A-HJ-NP-Za-km-z]{87,90})
"
,
MULTILINE
)
regex_pubkey
=
re
.
compile
(
"
pub: ([1-9A-HJ-NP-Za-km-z]{43,44})
"
,
re
.
MULTILINE
)
regex_signkey
=
re
.
compile
(
"
sec: ([1-9A-HJ-NP-Za-km-z]{87,90})
"
,
re
.
MULTILINE
)
# Seed format
if
search
(
regex_seed
,
filetxt
):
if
re
.
search
(
regex_seed
,
filetxt
):
return
SigningKey
.
from_seedhex_file
(
file
)
# PubSec format
elif
search
(
regex_pubkey
,
filetxt
)
and
search
(
regex_signkey
,
filetxt
):
elif
re
.
search
(
regex_pubkey
,
filetxt
)
and
re
.
search
(
regex_signkey
,
filetxt
):
return
SigningKey
.
from_pubsec_file
(
file
)
else
:
message_exit
(
"
Error: the format of the file is invalid
"
)
...
...
This diff is collapsed.
Click to expand it.
silkaj/crypto_tools.py
+
5
−
5
View file @
03ad790a
...
...
@@ -15,8 +15,8 @@ You should have received a copy of the GNU Affero General Public License
along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
"""
import
re
from
nacl
import
encoding
,
hash
from
re
import
compile
,
search
def
check_public_key
(
pubkey
,
display_error
):
...
...
@@ -25,13 +25,13 @@ def check_public_key(pubkey, display_error):
Check pubkey checksum which could be append after the pubkey
If check pass: return pubkey
"""
regex
=
compile
(
"
^[1-9A-HJ-NP-Za-km-z]{43,44}$
"
)
regex_checksum
=
compile
(
regex
=
re
.
compile
(
"
^[1-9A-HJ-NP-Za-km-z]{43,44}$
"
)
regex_checksum
=
re
.
compile
(
"
^[1-9A-HJ-NP-Za-km-z]{43,44}
"
+
"
![1-9A-HJ-NP-Za-km-z]{3}$
"
)
if
search
(
regex
,
pubkey
):
if
re
.
search
(
regex
,
pubkey
):
return
pubkey
elif
search
(
regex_checksum
,
pubkey
):
elif
re
.
search
(
regex_checksum
,
pubkey
):
pubkey
,
checksum
=
pubkey
.
split
(
"
!
"
)
pubkey_byte
=
b58_decode
(
pubkey
)
checksum_calculed
=
b58_encode
(
...
...
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