##// END OF EJS Templates
Merge pull request #6114 from ivanov/update-digest-api...
Paul Ivanov -
r17360:71fce017 merge
parent child Browse files
Show More
@@ -27,12 +27,20 b' except:'
27 cPickle = None
27 cPickle = None
28 import pickle
28 import pickle
29
29
30 try:
31 # We are using compare_digest to limit the surface of timing attacks
32 from hmac import compare_digest
33 except ImportError:
34 # Python < 2.7.7: When digests don't match no feedback is provided,
35 # limiting the surface of attack
36 def compare_digest(a,b): return a == b
37
30 import zmq
38 import zmq
31 from zmq.utils import jsonapi
39 from zmq.utils import jsonapi
32 from zmq.eventloop.ioloop import IOLoop
40 from zmq.eventloop.ioloop import IOLoop
33 from zmq.eventloop.zmqstream import ZMQStream
41 from zmq.eventloop.zmqstream import ZMQStream
34
42
35 from IPython.core.release import kernel_protocol_version, kernel_protocol_version_info
43 from IPython.core.release import kernel_protocol_version
36 from IPython.config.configurable import Configurable, LoggingConfigurable
44 from IPython.config.configurable import Configurable, LoggingConfigurable
37 from IPython.utils import io
45 from IPython.utils import io
38 from IPython.utils.importstring import import_item
46 from IPython.utils.importstring import import_item
@@ -216,7 +224,7 b' class Session(Configurable):'
216 dict-based IPython message spec. The Session will handle
224 dict-based IPython message spec. The Session will handle
217 serialization/deserialization, security, and metadata.
225 serialization/deserialization, security, and metadata.
218
226
219 Sessions support configurable serialiization via packer/unpacker traits,
227 Sessions support configurable serialization via packer/unpacker traits,
220 and signing with HMAC digests via the key/keyfile traits.
228 and signing with HMAC digests via the key/keyfile traits.
221
229
222 Parameters
230 Parameters
@@ -524,7 +532,7 b' class Session(Configurable):'
524 Parameters
532 Parameters
525 ----------
533 ----------
526 msg : dict or Message
534 msg : dict or Message
527 The nexted message dict as returned by the self.msg method.
535 The next message dict as returned by the self.msg method.
528
536
529 Returns
537 Returns
530 -------
538 -------
@@ -818,7 +826,7 b' class Session(Configurable):'
818 raise ValueError("Duplicate Signature: %r" % signature)
826 raise ValueError("Duplicate Signature: %r" % signature)
819 self._add_digest(signature)
827 self._add_digest(signature)
820 check = self.sign(msg_list[1:5])
828 check = self.sign(msg_list[1:5])
821 if not signature == check:
829 if not compare_digest(signature, check):
822 raise ValueError("Invalid Signature: %r" % signature)
830 raise ValueError("Invalid Signature: %r" % signature)
823 if not len(msg_list) >= minlen:
831 if not len(msg_list) >= minlen:
824 raise TypeError("malformed message, must have at least %i elements"%minlen)
832 raise TypeError("malformed message, must have at least %i elements"%minlen)
General Comments 0
You need to be logged in to leave comments. Login now