diff --git a/frontend/src/upload.js b/frontend/src/upload.js index 60ebe96c..e9f0811a 100644 --- a/frontend/src/upload.js +++ b/frontend/src/upload.js @@ -1,10 +1,18 @@ const FileSender = require('./fileSender'); -const { notify } = require('./utils'); +const { notify, gcmCompliant } = require('./utils'); const $ = require('jquery'); const Raven = window.Raven; $(document).ready(function() { + + // added as a print statement for now, eventually move init stuff + // into here and display an error page if it's not compliant + gcmCompliant().catch(err => { + $('#page-one').hide(); + $('#compliance-error').show(); + }) + // reset copy button const $copyBtn = $('#copy-btn'); $copyBtn.attr('disabled', false); @@ -15,6 +23,7 @@ $(document).ready(function() { $('#upload-progress').hide(); $('#share-link').hide(); $('#upload-error').hide(); + $('#compliance-error').hide(); if (localStorage.length === 0) { toggleHeader(); diff --git a/frontend/src/utils.js b/frontend/src/utils.js index 2e6400ce..419f7b88 100644 --- a/frontend/src/utils.js +++ b/frontend/src/utils.js @@ -32,8 +32,42 @@ function notify(str) { } } +function gcmCompliant() { + try { + return window.crypto.subtle.generateKey( + { + name: 'AES-GCM', + length: 128 + }, + true, + ['encrypt', 'decrypt'] + ).then(key => { + return window.crypto.subtle.encrypt( + { + name: 'AES-GCM', + iv: window.crypto.getRandomValues(new Uint8Array(12)), + additionalData: window.crypto.getRandomValues(new Uint8Array(6)) + }, + key, + new ArrayBuffer(8) + ) + .then(() => { + return Promise.resolve() + }) + .catch(err => { + return Promise.reject() + }) + }).catch(err => { + return Promise.reject(); + }) + } catch(err) { + return Promise.reject(); + } +} + module.exports = { arrayToHex, hexToArray, - notify + notify, + gcmCompliant }; diff --git a/views/index.handlebars b/views/index.handlebars index dd2942d7..6d6b89db 100644 --- a/views/index.handlebars +++ b/views/index.handlebars @@ -100,6 +100,16 @@ +
+
+ Encryption error
+ Your browser does not support gcm encryption. +
+
+ Send another file +
+
+