##// END OF EJS Templates
move signature checking to base NotebookManager...
MinRK -
Show More
@@ -26,7 +26,7 import shutil
26 from tornado import web
26 from tornado import web
27
27
28 from .nbmanager import NotebookManager
28 from .nbmanager import NotebookManager
29 from IPython.nbformat import current, sign
29 from IPython.nbformat import current
30 from IPython.utils.traitlets import Unicode, Dict, Bool, TraitError
30 from IPython.utils.traitlets import Unicode, Dict, Bool, TraitError
31 from IPython.utils import tz
31 from IPython.utils import tz
32
32
@@ -213,11 +213,8 class FileNotebookManager(NotebookManager):
213 nb = current.read(f, u'json')
213 nb = current.read(f, u'json')
214 except Exception as e:
214 except Exception as e:
215 raise web.HTTPError(400, u"Unreadable Notebook: %s %s" % (os_path, e))
215 raise web.HTTPError(400, u"Unreadable Notebook: %s %s" % (os_path, e))
216 self.mark_trusted_cells(nb, path, name)
216 model['content'] = nb
217 model['content'] = nb
217 trusted = self.notary.check_signature(nb)
218 if not trusted:
219 self.log.warn("Notebook %s/%s is not trusted", model['path'], model['name'])
220 self.notary.mark_cells(nb, trusted)
221 return model
218 return model
222
219
223 def save_notebook_model(self, model, name='', path=''):
220 def save_notebook_model(self, model, name='', path=''):
@@ -241,11 +238,7 class FileNotebookManager(NotebookManager):
241 os_path = self.get_os_path(new_name, new_path)
238 os_path = self.get_os_path(new_name, new_path)
242 nb = current.to_notebook_json(model['content'])
239 nb = current.to_notebook_json(model['content'])
243
240
244 if self.notary.check_cells(nb):
241 self.check_and_sign(nb, new_path, new_name)
245 self.notary.sign(nb)
246 else:
247 self.log.warn("Saving untrusted notebook %s/%s", new_path, new_name)
248
249
242
250 if 'name' in nb['metadata']:
243 if 'name' in nb['metadata']:
251 nb['metadata']['name'] = u''
244 nb['metadata']['name'] = u''
@@ -46,6 +46,26 class NotebookManager(LoggingConfigurable):
46 def _notary_default(self):
46 def _notary_default(self):
47 return sign.NotebookNotary(parent=self)
47 return sign.NotebookNotary(parent=self)
48
48
49 def check_and_sign(self, nb, path, name):
50 """Check for trusted cells, and sign the notebook.
51
52 Called as a part of saving notebooks.
53 """
54 if self.notary.check_cells(nb):
55 self.notary.sign(nb)
56 else:
57 self.log.warn("Saving untrusted notebook %s/%s", path, name)
58
59 def mark_trusted_cells(self, nb, path, name):
60 """Mark cells as trusted if the notebook signature matches.
61
62 Called as a part of loading notebooks.
63 """
64 trusted = self.notary.check_signature(nb)
65 if not trusted:
66 self.log.warn("Notebook %s/%s is not trusted", path, name)
67 self.notary.mark_cells(nb, trusted)
68
49 def path_exists(self, path):
69 def path_exists(self, path):
50 """Does the API-style path (directory) actually exist?
70 """Does the API-style path (directory) actually exist?
51
71
General Comments 0
You need to be logged in to leave comments. Login now