diff --git a/customize.dist/login.js b/customize.dist/login.js index 69afa731d..d35dbfd35 100644 --- a/customize.dist/login.js +++ b/customize.dist/login.js @@ -72,6 +72,7 @@ define([ opt.channel64 = Util.hexToBase64(channelHex); + // XXX why don't we generate a v2 ? opt.userHash = '/1/edit/' + [opt.channel64, opt.keys.editKeyStr].join('/') + '/'; return opt; @@ -90,6 +91,7 @@ define([ }; var loadUserObject = function (opt, cb) { + console.log(opt); var config = { websocketURL: NetConfig.getWebsocketURL(), channel: opt.channelHex, @@ -102,6 +104,8 @@ define([ owners: [opt.edPublic] }; + console.log(config); + var rt = opt.rt = Listmap.create(config); rt.proxy .on('ready', function () { @@ -178,6 +182,8 @@ define([ console.error("Found a login block but failed to decrypt"); return; } + + console.error(decryptedBlock); res.blockInfo = decryptedBlock; })); }).nThen(function (waitFor) { @@ -253,11 +259,12 @@ define([ }); }); })); - }).nThen(function (waitFor) { // MODERN REGISTRATION + }).nThen(function (waitFor) { // MODERN REGISTRATION / LOGIN var opt; if (res.blockInfo) { opt = loginOptionsFromBlock(res.blockInfo); userHash = res.blockInfo.User_hash; + console.error(opt, userHash); } else { console.log("allocating random bytes for a new user object"); opt = allocateBytes(Nacl.randomBytes(Exports.requiredBytes)); @@ -271,6 +278,8 @@ define([ return void cb('MODERN_REGISTRATION_INIT'); } + console.error(JSON.stringify(rt.proxy)); + // export the realtime object you checked RT = rt; diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 5238385f3..2af8e919d 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -724,6 +724,7 @@ define([ var Cred, Block, Login; Nthen(function (waitFor) { + console.log("loading necessary modules"); require([ '/customize/credential.js', '/common/outer/login-block.js', @@ -735,11 +736,13 @@ define([ })); }).nThen(function (waitFor) { // confirm that the provided password is correct + console.log("checking whether the password you entered was correct"); Cred.deriveFromPassphrase(accountName, password, Login.requiredBytes, waitFor(function (bytes) { var allocated = Login.allocateBytes(bytes); oldBlockKeys = allocated.blockKeys; if (blockHash) { if (blockHash !== allocated.blockHash) { + console.log("password did not yield the correct blockHash ?"); // incorrect password probably waitFor.abort(); return void cb({ @@ -750,6 +753,7 @@ define([ } else { // otherwise they're a legacy user, and we should check against the User_hash if (hash !== allocated.userHash) { + console.log("password did not yield the correct userHash"); waitFor.abort(); return void cb({ error: 'INVALID_PASSWORD', @@ -759,6 +763,7 @@ define([ })); }).nThen(function (waitFor) { // Check if our drive is already owned + console.log("checking if old drive is owned"); common.anonRpcMsg('GET_METADATA', secret.channel, waitFor(function (err, obj) { if (err || obj.error) { return; } if (obj.owners && Array.isArray(obj.owners) && @@ -778,21 +783,38 @@ define([ owners: [edPublic] }; + console.log("copying contents of old drive to new location"); Crypt.get(hash, waitFor(function (err, val) { if (err) { waitFor.abort(); return void cb({ error: err }); } + console.log(val); + console.log("%s => %s", hash, newHash); Crypt.put(newHash, val, waitFor(function (err) { if (err) { waitFor.abort(); + console.error(err); return void cb({ error: err }); } + + + console.error('checking content at newHash: %s', newHash); + + Crypt.get(newHash, function (err, val) { + if (err) { + waitFor.abort(); + console.log(err); + return void cb({ error: err }); + } + console.error(val); + }); }), optsPut); })); }).nThen(function (waitFor) { // Drive content copied: get the new block location + console.log("deriving new credentials from passphrase"); Cred.deriveFromPassphrase(accountName, newPassword, Login.requiredBytes, waitFor(function (bytes) { var allocated = Login.allocateBytes(bytes); newBlockSeed = allocated.blockSeed; @@ -800,14 +822,19 @@ define([ }).nThen(function (waitFor) { // Write the new login block var keys = Block.genkeys(newBlockSeed); - var content = Block.serialize(JSON.stringify({ + + var temp = { User_name: accountName, User_hash: newHash, edPublic: edPublic, // edPrivate XXX - }), keys); + }; + + var content = Block.serialize(JSON.stringify(temp), keys); + console.log("writing new login block"); common.writeLoginBlock(content, waitFor(function (obj) { + console.log("new login block written"); var newBlockHash = Block.getBlockHash(keys); LocalStore.setBlockHash(newBlockHash); if (obj && obj.error) { @@ -817,11 +844,13 @@ define([ })); }).nThen(function (waitFor) { // New drive hash is in login block, unpin the old one and pin the new one + console.log("unpinning old drive and pinning new one"); common.unpinPads([secret.channel], waitFor()); common.pinPads([newSecret.channel], waitFor()); }).nThen(function (waitFor) { // Remove block hash if (blockHash) { + console.log('removing old login block'); var removeData = Block.remove(oldBlockKeys); common.removeLoginBlock(removeData, waitFor(function (obj) { if (obj && obj.error) { return void console.error(obj.error); } @@ -829,6 +858,7 @@ define([ } }).nThen(function (waitFor) { if (oldIsOwned) { + console.log('removing old drive'); common.removeOwnedChannel(secret.channel, waitFor(function (obj) { if (obj && obj.error) { // Deal with it as if it was not owned @@ -842,6 +872,7 @@ define([ } }).nThen(function (waitFor) { if (!oldIsOwned) { + console.error('deprecating old drive.'); postMessage("SET", { key: [Constants.deprecatedKey], value: true @@ -855,6 +886,8 @@ define([ })); } }).nThen(function () { + console.error('done ?'); + return; // We have the new drive, with the new login block window.location.reload(); });