From cb5fa72dbad2b4420a80c301e1b7bda4705f283d Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 19 Jun 2018 17:17:56 +0200 Subject: [PATCH] implement removeLoginBlock rpc --- rpc.js | 9 ++++++--- www/common/cryptpad-common.js | 6 ++++++ www/common/outer/async-store.js | 11 ++++++++++- www/common/outer/login-block.js | 11 +++++++++++ www/common/outer/store-rpc.js | 1 + www/common/pinpad.js | 15 +++++++++++++++ www/common/sframe-common-outer.js | 4 ++++ www/common/sframe-protocol.js | 3 +++ 8 files changed, 56 insertions(+), 4 deletions(-) diff --git a/rpc.js b/rpc.js index f07af7c4c..d10fe6149 100644 --- a/rpc.js +++ b/rpc.js @@ -1859,9 +1859,12 @@ RPC.create = function ( Respond(e); }); case 'REMOVE_LOGIN_BLOCK': - return void removeLoginBlock(Env, msg, function (e) { - // TODO handle response - e = e; + return void removeLoginBlock(Env, msg[1], function (e) { + if (e) { + WARN(e, 'REMOVE_LOGIN_BLOCK'); + return void Respond(e); + } + Respond(e); }); default: return void Respond('UNSUPPORTED_RPC_CALL', msg); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index b3f3edb63..d095d2b3c 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -240,6 +240,12 @@ define([ }); }; + common.removeLoginBlock = function (data, cb) { + postMessage('REMOVE_LOGIN_BLOCK', data, function (obj) { + cb(obj); + }); + }; + // ANON RPC // SFRAME: talk to anon_rpc from the iframe diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index e703b6a5b..e22e2d574 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -13,7 +13,7 @@ define([ '/common/outer/network-config.js', '/customize/application_config.js', - '/bower_components/chainpad-crypto/crypto.js?v=0.1.5', + '/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad/chainpad.dist.js', '/bower_components/chainpad-listmap/chainpad-listmap.js', '/bower_components/nthen/index.js', @@ -285,6 +285,15 @@ define([ }); }; + Store.removeLoginBlock = function (clientId, data, cb) { + store.rpc.removeLoginBlock(data, function (e, res) { + cb({ + error: e, + data: res + }); + }); + }; + Store.initRpc = function (clientId, data, cb) { if (store.rpc) { return void cb(account); } require(['/common/pinpad.js'], function (Pinpad) { diff --git a/www/common/outer/login-block.js b/www/common/outer/login-block.js index bac63f2f8..026fa289f 100644 --- a/www/common/outer/login-block.js +++ b/www/common/outer/login-block.js @@ -75,5 +75,16 @@ define([ }; }; + Block.remove = function (keys) { + // sign the hash of the text 'DELETE_BLOCK' + var sig = Nacl.sign.detached(Nacl.hash( + Nacl.util.decodeUTF8('DELETE_BLOCK')), keys.sign.secretKey); + + return { + publicKey: Nacl.util.encodeBase64(keys.sign.publicKey), + signature: Nacl.util.encodeBase64(sig), + }; + }; + return Block; }); diff --git a/www/common/outer/store-rpc.js b/www/common/outer/store-rpc.js index a2b7d2404..e1a941040 100644 --- a/www/common/outer/store-rpc.js +++ b/www/common/outer/store-rpc.js @@ -24,6 +24,7 @@ define([ UPLOAD_STATUS: Store.uploadStatus, UPLOAD_CANCEL: Store.uploadCancel, WRITE_LOGIN_BLOCK: Store.writeLoginBlock, + REMOVE_LOGIN_BLOCK: Store.removeLoginBlock, PIN_PADS: Store.pinPads, UNPIN_PADS: Store.unpinPads, GET_DELETED_PADS: Store.getDeletedPads, diff --git a/www/common/pinpad.js b/www/common/pinpad.js index da1e51d28..721f8a94b 100644 --- a/www/common/pinpad.js +++ b/www/common/pinpad.js @@ -237,6 +237,21 @@ define([ }); }; + exp.removeLoginBlock = function (data, cb) { + if (!data) { return void cb('NO_DATA'); } + if (!data.publicKey || !data.signature) { + console.log(data); + return void cb("MISSING_PARAMETERS"); + } + + rpc.send('REMOVE_LOGIN_BLOCK', [ + data.publicKey, // publicKey + data.signature, // signature + ], function (e) { + cb(e); + }); + }; + cb(e, exp); }); }; diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 79f9c45a7..c40bff5e3 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -647,6 +647,10 @@ define([ Cryptpad.writeLoginBlock(data, cb); }); + sframeChan.on('Q_REMOVE_LOGIN_BLOCK', function (data, cb) { + Cryptpad.removeLoginBlock(data, cb); + }); + if (cfg.addRpc) { cfg.addRpc(sframeChan, Cryptpad, Utils); } diff --git a/www/common/sframe-protocol.js b/www/common/sframe-protocol.js index a75936af5..8bb68aeef 100644 --- a/www/common/sframe-protocol.js +++ b/www/common/sframe-protocol.js @@ -77,6 +77,9 @@ define({ // Write/update the login block when the account password is changed 'Q_WRITE_LOGIN_BLOCK': true, + // Remove login blocks + 'Q_REMOVE_LOGIN_BLOCK': true, + // Check the pin limit to determine if we can store the pad in the drive or if we should. // display a warning 'Q_GET_PIN_LIMIT_STATUS': true,