diff --git a/IPython/kernel/zmq/session.py b/IPython/kernel/zmq/session.py index b69e5e0..bedeaf5 100644 --- a/IPython/kernel/zmq/session.py +++ b/IPython/kernel/zmq/session.py @@ -307,11 +307,8 @@ class Session(Configurable): key = CBytes(b'', config=True, help="""execution key, for extra authentication.""") - def _key_changed(self, name, old, new): - if new: - self.auth = hmac.HMAC(new, digestmod=self.digest_mod) - else: - self.auth = None + def _key_changed(self): + self._new_auth() signature_scheme = Unicode('hmac-sha256', config=True, help="""The digest scheme used to construct the message signatures. @@ -324,6 +321,7 @@ class Session(Configurable): self.digest_mod = getattr(hashlib, hash_name) except AttributeError: raise TraitError("hashlib has no such attribute: %s" % hash_name) + self._new_auth() digest_mod = Any() def _digest_mod_default(self): @@ -331,6 +329,12 @@ class Session(Configurable): auth = Instance(hmac.HMAC) + def _new_auth(self): + if self.key: + self.auth = hmac.HMAC(self.key, digestmod=self.digest_mod) + else: + self.auth = None + digest_history = Set() digest_history_size = Integer(2**16, config=True, help="""The maximum number of digests to remember.