Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
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
Container Registry
Model registry
Monitor
Service Desk
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
Maunium
synapse
Commits
248cfd5e
Commit
248cfd5e
authored
9 years ago
by
Daniel Wagner-Hall
Browse files
Options
Downloads
Patches
Plain Diff
Take a boolean not a list of lambdas
parent
57a76c9a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/api/auth.py
+17
-8
17 additions, 8 deletions
synapse/api/auth.py
synapse/handlers/auth.py
+1
-1
1 addition, 1 deletion
synapse/handlers/auth.py
with
18 additions
and
9 deletions
synapse/api/auth.py
+
17
−
8
View file @
248cfd5e
...
...
@@ -587,10 +587,7 @@ class Auth(object):
def
_get_user_from_macaroon
(
self
,
macaroon_str
):
try
:
macaroon
=
pymacaroons
.
Macaroon
.
deserialize
(
macaroon_str
)
self
.
validate_macaroon
(
macaroon
,
"
access
"
,
[
lambda
c
:
c
.
startswith
(
"
time <
"
)]
)
self
.
validate_macaroon
(
macaroon
,
"
access
"
,
False
)
user_prefix
=
"
user_id =
"
user
=
None
...
...
@@ -638,22 +635,34 @@ class Auth(object):
errcode
=
Codes
.
UNKNOWN_TOKEN
)
def
validate_macaroon
(
self
,
macaroon
,
type_string
,
additional_validation_functions
):
def
validate_macaroon
(
self
,
macaroon
,
type_string
,
verify_expiry
):
"""
validate that a Macaroon is understood by and was signed by this server.
Args:
macaroon(pymacaroons.Macaroon): The macaroon to validate
type_string(str): The kind of token this is (e.g.
"
access
"
,
"
refresh
"
)
verify_expiry(bool): Whether to verify whether the macaroon has expired.
This should really always be True, but no clients currently implement
token refresh, so we can
'
t enforce expiry yet.
"""
v
=
pymacaroons
.
Verifier
()
v
.
satisfy_exact
(
"
gen = 1
"
)
v
.
satisfy_exact
(
"
type =
"
+
type_string
)
v
.
satisfy_general
(
lambda
c
:
c
.
startswith
(
"
user_id =
"
))
v
.
satisfy_exact
(
"
guest = true
"
)
if
verify_expiry
:
v
.
satisfy_general
(
self
.
_verify_expiry
)
else
:
v
.
satisfy_general
(
lambda
c
:
c
.
startswith
(
"
time <
"
))
for
validation_function
in
additional_validation_functions
:
v
.
satisfy_general
(
validation_function
)
v
.
verify
(
macaroon
,
self
.
hs
.
config
.
macaroon_secret_key
)
v
=
pymacaroons
.
Verifier
()
v
.
satisfy_general
(
self
.
_verify_recognizes_caveats
)
v
.
verify
(
macaroon
,
self
.
hs
.
config
.
macaroon_secret_key
)
def
verify_expiry
(
self
,
caveat
):
def
_
verify_expiry
(
self
,
caveat
):
prefix
=
"
time <
"
if
not
caveat
.
startswith
(
prefix
):
return
False
...
...
This diff is collapsed.
Click to expand it.
synapse/handlers/auth.py
+
1
−
1
View file @
248cfd5e
...
...
@@ -407,7 +407,7 @@ class AuthHandler(BaseHandler):
try
:
macaroon
=
pymacaroons
.
Macaroon
.
deserialize
(
login_token
)
auth_api
=
self
.
hs
.
get_auth
()
auth_api
.
validate_macaroon
(
macaroon
,
"
login
"
,
[
auth_api
.
verify_expiry
]
)
auth_api
.
validate_macaroon
(
macaroon
,
"
login
"
,
True
)
return
self
.
_get_user_from_macaroon
(
macaroon
)
except
(
pymacaroons
.
exceptions
.
MacaroonException
,
TypeError
,
ValueError
):
raise
AuthError
(
401
,
"
Invalid token
"
,
errcode
=
Codes
.
UNKNOWN_TOKEN
)
...
...
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