Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odevzdávací Systém MO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Mareš
Odevzdávací Systém MO
Merge requests
!86
Registrace
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
Registrace
mj/registrace
into
devel
Overview
49
Commits
38
Changes
1
Merged
Martin Mareš
requested to merge
mj/registrace
into
devel
4 years ago
Overview
38
Commits
38
Changes
1
Implementace registrace podle
#220 (closed)
.
Edited
3 years ago
by
Martin Mareš
0
0
Merge request reports
Viewing commit
fc7fa83b
Prev
Next
Show latest version
1 file
+
17
−
3
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
fc7fa83b
mo.tokens: Obecný parametrizovaný podpis a hash
· fc7fa83b
Martin Mareš
authored
4 years ago
mo/tokens.py
+
17
−
3
View file @ fc7fa83b
Edit in single-file editor
Open in Web IDE
Show full file
# Podepsané tokeny
import
hashlib
import
hmac
import
urllib.parse
from
typing
import
Optional
,
List
@@ -8,9 +9,7 @@ import mo.config as config
def
_sign_token
(
token
:
str
,
use
:
str
)
->
str
:
key
=
'
-
'
.
join
((
'
sign-token
'
,
use
,
config
.
SECRET_KEY
))
mac
=
hmac
.
HMAC
(
key
.
encode
(
'
us-ascii
'
),
token
.
encode
(
'
us-ascii
'
),
'
sha256
'
)
return
mac
.
hexdigest
()[:
16
]
return
sign
(
token
,
'
token-
'
+
use
)
def
sign_token
(
fields
:
List
[
str
],
use
:
str
)
->
str
:
@@ -27,3 +26,18 @@ def verify_token(token: str, use: str) -> Optional[List[str]]:
if
_sign_token
(
'
:
'
.
join
(
enc_fields
),
use
)
!=
sign
:
return
None
return
[
urllib
.
parse
.
unquote
(
f
)
for
f
in
enc_fields
]
def
sign
(
msg
:
str
,
use
:
str
)
->
str
:
"""
Podpis parametrizovaný tajným klíčem a účelem.
"""
key
=
use
+
'
#
'
+
config
.
SECRET_KEY
mac
=
hmac
.
HMAC
(
key
.
encode
(
'
us-ascii
'
),
msg
.
encode
(
'
us-ascii
'
),
'
sha256
'
)
return
mac
.
hexdigest
()[:
16
]
def
hash
(
msg
:
str
,
use
:
str
)
->
str
:
"""
Hešovací funkce parametrizovaná tajným klíčem a účelem.
"""
m
=
'
#
'
.
join
((
use
,
config
.
SECRET_KEY
,
msg
)).
encode
(
'
us-ascii
'
)
return
hashlib
.
sha256
(
m
).
hexdigest
()
Loading