Skip to content

Commit

Permalink
Merge pull request #3399 from minrk/hmac-deprecated
Browse files Browse the repository at this point in the history
add missing digestmod arg to HMAC
  • Loading branch information
takluyver authored Mar 7, 2018
2 parents ae1f167 + f16b073 commit 290e574
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions notebook/notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import datetime
import errno
import gettext
import hashlib
import hmac
import importlib
import io
import json
Expand All @@ -27,7 +29,6 @@
import time
import warnings
import webbrowser
import hmac

try: #PY3
from base64 import encodebytes
Expand Down Expand Up @@ -687,27 +688,26 @@ def _valdate_ip(self, proposal):
@default('cookie_secret_file')
def _default_cookie_secret_file(self):
return os.path.join(self.runtime_dir, 'notebook_cookie_secret')

cookie_secret = Bytes(b'', config=True,
help="""The random bytes used to secure cookies.
By default this is a new random number every time you start the Notebook.
Set it to a value in a config file to enable logins to persist across server sessions.
Note: Cookie secrets should be kept private, do not share config files with
cookie_secret stored in plaintext (you can read the value from a file).
"""
)

@default('cookie_secret')
def _default_cookie_secret(self):
if os.path.exists(self.cookie_secret_file):
with io.open(self.cookie_secret_file, 'rb') as f:
key = f.read()
else:
key = encodebytes(os.urandom(1024))
key = encodebytes(os.urandom(32))
self._write_cookie_secret_file(key)
h = hmac.HMAC(key)
h.digest_size = len(key)
h = hmac.new(key, digestmod=hashlib.sha256)
h.update(self.password.encode())
return h.digest()

Expand Down

0 comments on commit 290e574

Please sign in to comment.