##// END OF EJS Templates
Merge pull request #6076 from minrk/cookie-secret...
Thomas Kluyver -
r17145:6b5103a3 merge
parent child Browse files
Show More
@@ -6,6 +6,7 b''
6
6
7 from __future__ import print_function
7 from __future__ import print_function
8
8
9 import base64
9 import errno
10 import errno
10 import io
11 import io
11 import json
12 import json
@@ -357,6 +358,14 b' class NotebookApp(BaseIPythonApplication):'
357 help="""The full path to a private key file for usage with SSL/TLS."""
358 help="""The full path to a private key file for usage with SSL/TLS."""
358 )
359 )
359
360
361 cookie_secret_file = Unicode(config=True,
362 help="""The file where the cookie secret is stored."""
363 )
364 def _cookie_secret_file_default(self):
365 if self.profile_dir is None:
366 return ''
367 return os.path.join(self.profile_dir.security_dir, 'notebook_cookie_secret')
368
360 cookie_secret = Bytes(b'', config=True,
369 cookie_secret = Bytes(b'', config=True,
361 help="""The random bytes used to secure cookies.
370 help="""The random bytes used to secure cookies.
362 By default this is a new random number every time you start the Notebook.
371 By default this is a new random number every time you start the Notebook.
@@ -367,7 +376,26 b' class NotebookApp(BaseIPythonApplication):'
367 """
376 """
368 )
377 )
369 def _cookie_secret_default(self):
378 def _cookie_secret_default(self):
370 return os.urandom(1024)
379 if os.path.exists(self.cookie_secret_file):
380 with io.open(self.cookie_secret_file, 'rb') as f:
381 return f.read()
382 else:
383 secret = base64.encodestring(os.urandom(1024))
384 self._write_cookie_secret_file(secret)
385 return secret
386
387 def _write_cookie_secret_file(self, secret):
388 """write my secret to my secret_file"""
389 self.log.info("Writing notebook server cookie secret to %s", self.cookie_secret_file)
390 with io.open(self.cookie_secret_file, 'wb') as f:
391 f.write(secret)
392 try:
393 os.chmod(self.cookie_secret_file, 0o600)
394 except OSError:
395 self.log.warn(
396 "Could not set permissions on %s",
397 self.cookie_secret_file
398 )
371
399
372 password = Unicode(u'', config=True,
400 password = Unicode(u'', config=True,
373 help="""Hashed password to use for web authentication.
401 help="""Hashed password to use for web authentication.
General Comments 0
You need to be logged in to leave comments. Login now