summaryrefslogtreecommitdiffstats
path: root/accounts/utils/sessions.py
diff options
context:
space:
mode:
Diffstat (limited to 'accounts/utils/sessions.py')
-rw-r--r--accounts/utils/sessions.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/accounts/utils/sessions.py b/accounts/utils/sessions.py
index cd12030..dd4e4bb 100644
--- a/accounts/utils/sessions.py
+++ b/accounts/utils/sessions.py
@@ -24,17 +24,15 @@ class EncryptedSerializer(TaggedJSONSerializer):
self.block_size = AES.block_size
def _cipher(self, iv):
- return AES.new(
- current_app.config['SESSION_ENCRYPTION_KEY'],
- AES.MODE_CBC, iv)
+ key = current_app.config['SESSION_ENCRYPTION_KEY']
+ assert len(key) == 32
+ return AES.new(key, AES.MODE_CBC, iv)
def dumps(self, value):
"""
Encrypt the serialized values with `config.SESSION_ENCRYPTION_KEY`.
The key must be 32 bytes long.
"""
- assert len(current_app.config['SESSION_ENCRYPTION_KEY']) == 32
-
serialized_value = super(EncryptedSerializer, self).dumps(value)
raw = _pad(serialized_value, self.block_size)
@@ -54,9 +52,18 @@ class EncryptedSerializer(TaggedJSONSerializer):
class EncryptedSessionInterface(SecureCookieSessionInterface):
serializer = EncryptedSerializer()
- def open_session(self, *args, **kwargs):
+ def open_session(self, app, request):
+ session = None
try:
parent = super(EncryptedSessionInterface, self)
- return parent.open_session(*args, **kwargs)
+ session = parent.open_session(app, request)
except BadPayload:
- return self.session_class()
+ session = self.session_class()
+
+ if session is not None:
+ if app.config.get('PERMANENT_SESSION_LIFETIME') is not None:
+ session.permanent = True
+ else:
+ session.permanent = False
+
+ return session