diff --git a/www/auth/index.html b/www/auth/index.html deleted file mode 100644 index 685ca37c4..000000000 --- a/www/auth/index.html +++ /dev/null @@ -1,9 +0,0 @@ - - -
- - - - - - diff --git a/www/auth/main.js b/www/auth/main.js deleted file mode 100644 index fcbeaf3af..000000000 --- a/www/auth/main.js +++ /dev/null @@ -1,193 +0,0 @@ -define([ - 'jquery', - '/api/config', - '/common/cryptget.js', - '/common/pinpad.js', - '/common/common-constants.js', - '/common/common-hash.js', - '/common/outer/local-store.js', - '/common/outer/login-block.js', - '/common/outer/network-config.js', - '/customize/login.js', - '/common/test.js', - '/bower_components/nthen/index.js', - '/bower_components/netflux-websocket/netflux-client.js', - '/bower_components/tweetnacl/nacl-fast.min.js' -], function ($, ApiConfig, Crypt, Pinpad, Constants, Hash, LocalStore, Block, NetConfig, Login, Test, nThen, Netflux) { - var Nacl = window.nacl; - - var signMsg = function (msg, privKey) { - var signKey = Nacl.util.decodeBase64(privKey); - var buffer = Nacl.util.decodeUTF8(msg); - return Nacl.util.encodeBase64(Nacl.sign(buffer, signKey)); - }; - - // TODO: Allow authing for any domain as long as the user clicks an "accept" button - // inside of the iframe. - var AUTHORIZED_DOMAINS = [ - /\.cryptpad\.fr$/, - /^http(s)?:\/\/localhost\:/ - ]; - - // Safari is weird about localStorage in iframes but seems to let sessionStorage slide. - localStorage[Constants.userHashKey] = localStorage[Constants.userHashKey] || - sessionStorage[Constants.userHashKey]; - - var proxy; - var rpc; - var network; - var rpcError; - var contacts = {}; - - var loadProxy = function (hash) { - nThen(function (waitFor) { - var wsUrl = NetConfig.getWebsocketURL(); - var w = waitFor(); - Netflux.connect(wsUrl).then(function (_network) { - network = _network; - w(); - }, function (err) { - rpcError = err; - console.error(err); - }); - }).nThen(function (waitFor) { - Crypt.get(hash, waitFor(function (err, val) { - if (err) { - waitFor.abort(); - console.error(err); - return; - } - try { - var parsed = JSON.parse(val); - proxy = parsed; - } catch (e) { - console.log("Can't parse user drive", e); - } - }), { - network: network - }); - }).nThen(function () { - var origin = ApiConfig.fileHost || window.location.origin; - // Get contacts and extract their avatar channel and key - var getData = function (obj, href) { - var parsed = Hash.parsePadUrl(href); - if (!parsed || parsed.type !== "file") { return; } - var secret = Hash.getSecrets('file', parsed.hash); - if (!secret.keys || !secret.channel) { return; } - obj.avatarKey = Hash.encodeBase64(secret.keys && secret.keys.cryptKey); - obj.avatarSrc = origin + Hash.getBlobPathFromHex(secret.channel); - }; - contacts.teams = proxy.teams || {}; - contacts.friends = proxy.friends || {}; - Object.keys(contacts.friends).map(function (key) { - var friend = contacts.friends[key]; - if (!friend) { return; } - var ret = { - edPublic: friend.edPublic, - name: friend.displayName, - }; - getData(ret, friend.avatar); - contacts.friends[key] = ret; - }); - Object.keys(contacts.teams).map(function (key) { - var team = contacts.teams[key]; - if (!team) { return; } - var avatar = team.metadata && team.metadata.avatar; - var ret = { - edPublic: team.keys && team.keys.drive && team.keys.drive.edPublic, - name: team.metadata && team.metadata.name - }; - getData(ret, avatar); - contacts.teams[key] = ret; - }); - contacts.origin = window.location.origin; - }).nThen(function (waitFor) { - if (!network) { return void waitFor.abort(); } - Pinpad.create(network, proxy, waitFor(function (e, call) { - if (e) { - rpcError = e; - return void waitFor.abort(); - } - rpc = call; - })); - }).nThen(function () { - Test(function () { - // This is only here to maybe trigger an error. - window.drive = proxy['drive']; - Test.passed(); - }); - }); - }; - - var whenReady = function (cb) { - if (proxy && (rpc || rpcError)) { return void cb(); } - console.log('CryptPad not ready...'); - setTimeout(function () { - whenReady(cb); - }, 100); - }; - - $(window).on("message", function (jqe) { - var evt = jqe.originalEvent; - var data = JSON.parse(evt.data); - var domain = evt.origin; - var srcWindow = evt.source; - var ret = { txid: data.txid }; - console.log('CP receiving', data); - if (data.cmd === 'PING') { - ret.res = 'PONG'; - } else if (data.cmd === 'LOGIN') { - Login.loginOrRegister(data.data.name, data.data.password, false, false, function (err) { - if (err) { - ret.error = 'LOGIN_ERROR'; - srcWindow.postMessage(JSON.stringify(ret), domain); - return; - } - loadProxy(LocalStore.getUserHash()); - srcWindow.postMessage(JSON.stringify(ret), domain); - }); - return; - } else if (data.cmd === 'SIGN') { - if (!AUTHORIZED_DOMAINS.filter(function (x) { return x.test(domain); }).length) { - ret.error = "UNAUTH_DOMAIN"; - } else if (!LocalStore.isLoggedIn()) { - ret.error = "NOT_LOGGED_IN"; - } else { - return void whenReady(function () { - var sig = signMsg(data.data, proxy.edPrivate); - ret.res = { - uname: proxy.login_name, - edPublic: proxy.edPublic, - sig: sig - }; - ret.contacts = contacts; - srcWindow.postMessage(JSON.stringify(ret), domain); - }); - } - } else if (data.cmd === 'UPDATE_LIMIT') { - return void whenReady(function () { - if (rpcError) { - // Tell the user on accounts that there was an issue and they need to wait maximum 24h or contact an admin - ret.warning = true; - srcWindow.postMessage(JSON.stringify(ret), domain); - return; - } - rpc.updatePinLimits(function (e, limit, plan, note) { - if (e) { - ret.warning = true; - } - ret.res = [limit, plan, note]; - srcWindow.postMessage(JSON.stringify(ret), domain); - }); - }); - } else { - ret.error = "UNKNOWN_CMD"; - } - srcWindow.postMessage(JSON.stringify(ret), domain); - }); - - var userHash = LocalStore.getUserHash(); - if (userHash) { - loadProxy(userHash); - } -}); diff --git a/www/common/common-constants.js b/www/common/common-constants.js index 553665574..17db2302c 100644 --- a/www/common/common-constants.js +++ b/www/common/common-constants.js @@ -5,10 +5,6 @@ define(['/customize/application_config.js'], function (AppConfig) { userNameKey: 'User_name', blockHashKey: 'Block_hash', fileHashKey: 'FS_hash', - // sessionStorage - newPadPathKey: "newPadPath", - newPadTeamKey: "newPadTeam", - newPadFileData: "newPadFileData", // Store displayNameKey: 'cryptpad.username', oldStorageKey: 'CryptPad_RECENTPADS', diff --git a/www/common/onlyoffice/main.js b/www/common/onlyoffice/main.js index 83d887548..0560b95bd 100644 --- a/www/common/onlyoffice/main.js +++ b/www/common/onlyoffice/main.js @@ -55,7 +55,7 @@ define([ var addData = function (obj) { obj.ooType = window.location.pathname.replace(/^\//, '').replace(/\/$/, ''); obj.ooVersionHash = version; - obj.ooForceVersion = localStorage.CryptPad_ooVersion || sessionStorage.CryptPad_ooVersion || ""; + obj.ooForceVersion = localStorage.CryptPad_ooVersion || ""; }; var addRpc = function (sframeChan, Cryptpad, Utils) { sframeChan.on('Q_OO_SAVE', function (data, cb) { diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 653c4d1f5..62e078050 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -2730,7 +2730,6 @@ define([ * - userHash or anonHash * Todo in cb * - LocalStore.setFSHash if needed - * - sessionStorage.User_Hash * - stuff with tokenKey * Event to outer * - requestLogin diff --git a/www/common/outer/local-store.js b/www/common/outer/local-store.js index 774924148..d15c2e8c6 100644 --- a/www/common/outer/local-store.js +++ b/www/common/outer/local-store.js @@ -82,19 +82,6 @@ define([ localStorage.setItem(Constants.userNameKey, name); if (cb) { cb(); } }; - var eraseTempSessionValues = LocalStore.eraseTempSessionValues = function () { - // delete sessionStorage values that might have been left over - // from the main page's /user redirect - [ - 'login', - 'login_user', - 'login_pass', - 'login_rmb', - 'register' - ].forEach(function (k) { - delete sessionStorage[k]; - }); - }; var logoutHandlers = []; LocalStore.logout = function (cb, isDeletion) { [ @@ -104,10 +91,8 @@ define([ 'loginToken', 'plan', ].forEach(function (k) { - sessionStorage.removeItem(k); localStorage.removeItem(k); delete localStorage[k]; - delete sessionStorage[k]; }); try { Object.keys(localStorage || {}).forEach(function (k) { @@ -122,7 +107,6 @@ define([ if (!LocalStore.getFSHash()) { LocalStore.setFSHash(Hash.createRandomHash('drive')); } - eraseTempSessionValues(); if (!isDeletion) { logoutHandlers.forEach(function (h) { diff --git a/www/common/sframe-channel.js b/www/common/sframe-channel.js deleted file mode 100644 index a7edf0814..000000000 --- a/www/common/sframe-channel.js +++ /dev/null @@ -1,166 +0,0 @@ -// This file provides the API for the channel for talking to and from the sandbox iframe. -define([ - '/common/sframe-protocol.js', - '/common/common-util.js' -], function (SFrameProtocol, Util) { - - var mkTxid = function () { - return Math.random().toString(16).replace('0.', '') + Math.random().toString(16).replace('0.', ''); - }; - - var create = function (ow, cb, isSandbox, sendData) { - var otherWindow; - var evReady = Util.mkEvent(true); - var handlers = {}; - var queries = {}; - - // list of handlers which are registered from the other side... - var insideHandlers = []; - var callWhenRegistered = {}; - - var chan = {}; - - // Send a query. channel.query('Q_SOMETHING', { args: "whatever" }, function (reply) { ... }); - chan.query = function (q, content, cb, opts) { - if (!otherWindow) { throw new Error('not yet initialized'); } - if (!SFrameProtocol[q]) { - throw new Error('please only make queries are defined in sframe-protocol.js'); - } - opts = opts || {}; - var txid = mkTxid(); - var to = opts.timeout || 30000; - var timeout = setTimeout(function () { - delete queries[txid]; - console.log("Timeout making query " + q); - }, to); - queries[txid] = function (data, msg) { - clearTimeout(timeout); - delete queries[txid]; - cb(undefined, data.content, msg); - }; - evReady.reg(function () { - otherWindow.postMessage(JSON.stringify({ - txid: txid, - content: content, - q: q - }), '*'); - }); - }; - - // Fire an event. channel.event('EV_SOMETHING', { args: "whatever" }); - var event = chan.event = function (e, content) { - if (!SFrameProtocol[e]) { - throw new Error('please only fire events that are defined in sframe-protocol.js'); - } - if (e.indexOf('EV_') !== 0) { - throw new Error('please only use events (starting with EV_) for event messages'); - } - evReady.reg(function () { - otherWindow.postMessage(JSON.stringify({ content: content, q: e }), '*'); - }); - }; - - // Be notified on query or event. channel.on('EV_SOMETHING', function (args, reply) { ... }); - // If the type is a query, your handler will be invoked with a reply function that takes - // one argument (the content to reply with). - chan.on = function (queryType, handler, quiet) { - if (!SFrameProtocol[queryType]) { - throw new Error('please only register handlers which are defined in sframe-protocol.js'); - } - (handlers[queryType] = handlers[queryType] || []).push(function (data, msg) { - handler(data.content, function (replyContent) { - if (queryType.indexOf('Q_') !== 0) { throw new Error("replies to events are invalid"); } - msg.source.postMessage(JSON.stringify({ - txid: data.txid, - content: replyContent - }), '*'); - }, msg); - }); - if (!quiet) { - event('EV_REGISTER_HANDLER', queryType); - } - }; - - // If a particular handler is registered, call the callback immediately, otherwise it will be called - // when that handler is first registered. - // channel.whenReg('Q_SOMETHING', function () { ...query Q_SOMETHING?... }); - chan.whenReg = function (queryType, cb, always) { - if (!SFrameProtocol[queryType]) { - throw new Error('please only register handlers which are defined in sframe-protocol.js'); - } - var reg = always; - if (insideHandlers.indexOf(queryType) > -1) { - cb(); - } else { - reg = true; - } - if (reg) { - (callWhenRegistered[queryType] = callWhenRegistered[queryType] || []).push(cb); - } - }; - - // Same as whenReg except it will invoke every time there is another registration, not just once. - chan.onReg = function (queryType, cb) { chan.whenReg(queryType, cb, true); }; - - chan.on('EV_REGISTER_HANDLER', function (content) { - if (callWhenRegistered[content]) { - callWhenRegistered[content].forEach(function (f) { f(); }); - delete callWhenRegistered[content]; - } - insideHandlers.push(content); - }); - chan.whenReg('EV_REGISTER_HANDLER', evReady.fire); - - // Make sure both iframes are ready - var isReady =false; - chan.onReady = function (h) { - if (isReady) { - return void h(); - } - if (typeof(h) !== "function") { return; } - chan.on('EV_RPC_READY', function () { isReady = true; h(); }); - }; - chan.ready = function () { - chan.whenReg('EV_RPC_READY', function () { - chan.event('EV_RPC_READY'); - }); - }; - - var txid; - window.addEventListener('message', function (msg) { - var data = JSON.parse(msg.data); - if (ow !== msg.source) { - return; - //console.log("DROP Message from unexpected source"); - //console.log(msg); - } else if (!otherWindow) { - otherWindow = ow; - sendData = sendData || {}; - sendData.txid = data.txid; - ow.postMessage(JSON.stringify(sendData), '*'); - cb(chan); - } else if (typeof(data.q) === 'string' && handlers[data.q]) { - handlers[data.q].forEach(function (f) { - f(data || JSON.parse(msg.data), msg); - data = undefined; - }); - } else if (typeof(data.q) === 'undefined' && queries[data.txid]) { - queries[data.txid](data, msg); - } else if (data.txid === txid) { - // stray message from init - return; - } else { - console.log("DROP Unhandled message"); - console.log(msg); - } - }); - if (isSandbox) { - // we're in the sandbox - otherWindow = ow; - evReady.fire(); - cb(chan); - } - }; - - return { create: create }; -}); diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index d476d02d4..f1fd0ac8d 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -1181,15 +1181,6 @@ define([ }); }); - sframeChan.on('Q_SESSIONSTORAGE_PUT', function (data, cb) { - if (typeof (data.value) === "undefined") { - delete sessionStorage[data.key]; - } else { - sessionStorage[data.key] = data.value; - } - cb(); - }); - sframeChan.on('Q_IS_ONLY_IN_SHARED_FOLDER', function (data, cb) { Cryptpad.isOnlyInSharedFolder(secret.channel, function (err, t) { if (err) { return void cb({error: err}); } diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index ffff122b5..3eb86ff93 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -462,15 +462,6 @@ define([ }); }; - funcs.sessionStorage = { - put: function (key, value, cb) { - ctx.sframeChan.query('Q_SESSIONSTORAGE_PUT', { - key: key, - value: value - }, cb); - } - }; - funcs.setDisplayName = function (name, cb) { cb = cb || $.noop; ctx.sframeChan.query('Q_SETTINGS_SET_DISPLAY_NAME', name, cb); diff --git a/www/common/sframe-protocol.js b/www/common/sframe-protocol.js deleted file mode 100644 index 5eb9d829e..000000000 --- a/www/common/sframe-protocol.js +++ /dev/null @@ -1,271 +0,0 @@ -// This file defines all of the RPC calls which are used between the inner and outer iframe. -// Define *querys* (which expect a response) using Q_