mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
sso: Fixes for regressions after adding captcha and axes
- Change sso refresh url to refresh-pubtkt since refresh was conflicting with captcha's image refresh url. - Fix datetime.timedelta calculation for refresh interval. Now validity of ticket is 30 seconds as it was intended to be. It was wrongly set to 30 days earlier. Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
1fe9bb317a
commit
111f8f9145
5 files changed
+41
-25
No files matched your search
+25
-15
@@ -89,18 +89,21 @@ def subcommand_create_key_pair(_):
|
||||
os.chmod(fil, 0o440)
|
||||
|
||||
|
||||
def create_ticket(pkey, uid, validuntil, ip=None, tokens=None,
|
||||
udata=None, graceperiod=None, extra_fields=None):
|
||||
def create_ticket(pkey,
|
||||
uid,
|
||||
validuntil,
|
||||
ip=None,
|
||||
tokens=None,
|
||||
udata=None,
|
||||
graceperiod=None,
|
||||
extra_fields=None):
|
||||
"""Create and return a signed mod_auth_pubtkt ticket."""
|
||||
fields = [
|
||||
'uid={}'.format(uid),
|
||||
'validuntil={}'.format(validuntil, type='d'),
|
||||
ip and 'cip={}'.format(ip),
|
||||
tokens and 'tokens={}'.format(tokens),
|
||||
graceperiod and 'graceperiod={}'.format(graceperiod, type='d'),
|
||||
udata and 'udata={}'.format(udata),
|
||||
extra_fields and ';'.join(
|
||||
['{}={}'.format(k, v) for k, v in extra_fields])
|
||||
'uid={}'.format(uid), 'validuntil={}'.format(validuntil, type='d'), ip
|
||||
and 'cip={}'.format(ip), tokens and 'tokens={}'.format(tokens),
|
||||
graceperiod and 'graceperiod={}'.format(graceperiod, type='d'), udata
|
||||
and 'udata={}'.format(udata), extra_fields
|
||||
and ';'.join(['{}={}'.format(k, v) for k, v in extra_fields])
|
||||
]
|
||||
data = ';'.join(filter(None, fields))
|
||||
signature = 'sig={}'.format(sign(pkey, data))
|
||||
@@ -120,15 +123,22 @@ def subcommand_generate_ticket(arguments):
|
||||
tokens = arguments.tokens
|
||||
with open(private_key_file, 'r') as fil:
|
||||
pkey = crypto.load_privatekey(crypto.FILETYPE_PEM, fil.read().encode())
|
||||
valid_until = minutes_from_now(30)
|
||||
grace_period = minutes_from_now(25)
|
||||
valid_until = seconds_from_now(30)
|
||||
grace_period = seconds_from_now(25)
|
||||
print(create_ticket(
|
||||
pkey, uid, valid_until, tokens=tokens, graceperiod=grace_period))
|
||||
|
||||
|
||||
def minutes_from_now(minutes):
|
||||
"""Return a timestamp at the given number of minutes from now."""
|
||||
return (datetime.datetime.now() + datetime.timedelta(minutes)).timestamp()
|
||||
# def minutes_from_now(minutes):
|
||||
# """Return a timestamp at the given number of minutes from now."""
|
||||
# return (datetime.datetime.now() + datetime.timedelta(
|
||||
# 0, minutes * 60)).timestamp()
|
||||
|
||||
|
||||
def seconds_from_now(seconds):
|
||||
"""Return a timestamp at the given number of seconds from now."""
|
||||
return (
|
||||
datetime.datetime.now() + datetime.timedelta(0, seconds)).timestamp()
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in new issue
Block a user