diff src/browser/sat_browser/otrjs_wrapper.py @ 549:cd56f2b0e85b

browser_side: disable OTR if the browser is too old to offer crypto.getRandomValues (CSPRNG)
author souliane <souliane@mailoo.org>
date Wed, 17 Sep 2014 17:15:03 +0200
parents cd492c18b366
children 9877607c719a
line wrap: on
line diff
--- a/src/browser/sat_browser/otrjs_wrapper.py	Thu Sep 11 12:59:13 2014 +0200
+++ b/src/browser/sat_browser/otrjs_wrapper.py	Wed Sep 17 17:15:03 2014 +0200
@@ -43,6 +43,16 @@
 import otr.min.js
 
 
+def isSupported():
+    JS("""return (typeof OTR !== 'undefined');""")
+
+
+if not isSupported():
+    # see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues#Browser_Compatibility
+    log.error('Your browser is not implementing CSPRNG: OTR has been disabled.')
+    raise ImportError('CSPRNG is not supported by your browser')
+
+
 class context(object):
 
     # Pre-declare these attributes to avoid the pylint "undefined variable" errors