|
|
@ -699,25 +699,43 @@ define([
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
common.ownUserDrive = function (Crypt, edPublic, cb) {
|
|
|
|
common.changeUserPassword = function (Crypt, edPublic, data, cb) {
|
|
|
|
var hash = LocalStore.getUserHash();
|
|
|
|
if (!edPublic) {
|
|
|
|
//var href = '/drive/#' + hash;
|
|
|
|
return void cb({
|
|
|
|
|
|
|
|
error: 'E_NOT_LOGGED_IN'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var accountName = LocalStore.getAccountName();
|
|
|
|
|
|
|
|
var hash = LocalStore.getUserHash(); // To load your old drive
|
|
|
|
|
|
|
|
var password = data.password; // To remove your old block
|
|
|
|
|
|
|
|
var newPassword = data.newPassword; // To create your new block
|
|
|
|
var secret = Hash.getSecrets('drive', hash);
|
|
|
|
var secret = Hash.getSecrets('drive', hash);
|
|
|
|
var newHash, newHref, newSecret;
|
|
|
|
var newHash, newHref, newSecret, newBlockSeed;
|
|
|
|
|
|
|
|
var oldIsOwned = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// XXX ansuz: check that the old password is correct
|
|
|
|
|
|
|
|
throw new Error("XXX");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var blockHash = LocalStore.getBlockHash();
|
|
|
|
|
|
|
|
var Cred, Block;
|
|
|
|
Nthen(function (waitFor) {
|
|
|
|
Nthen(function (waitFor) {
|
|
|
|
|
|
|
|
require([
|
|
|
|
|
|
|
|
'/customize/credential.js',
|
|
|
|
|
|
|
|
'/common/outer/login-block.js'
|
|
|
|
|
|
|
|
], waitFor(function (_Cred, _Block) {
|
|
|
|
|
|
|
|
Cred = _Cred;
|
|
|
|
|
|
|
|
Block = _Block;
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
// Check if our drive is already owned
|
|
|
|
// Check if our drive is already owned
|
|
|
|
common.anonRpcMsg('GET_METADATA', secret.channel, waitFor(function (err, obj) {
|
|
|
|
common.anonRpcMsg('GET_METADATA', secret.channel, waitFor(function (err, obj) {
|
|
|
|
if (err || obj.error) { return; }
|
|
|
|
if (err || obj.error) { return; }
|
|
|
|
if (obj.owners && Array.isArray(obj.owners) &&
|
|
|
|
if (obj.owners && Array.isArray(obj.owners) &&
|
|
|
|
obj.owners.indexOf(edPublic) !== -1) {
|
|
|
|
obj.owners.indexOf(edPublic) !== -1) {
|
|
|
|
waitFor.abort();
|
|
|
|
oldIsOwned = true;
|
|
|
|
cb({
|
|
|
|
|
|
|
|
error: 'ALREADY_OWNED'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
waitFor.abort(); // TODO remove this line
|
|
|
|
|
|
|
|
// Create a new user hash
|
|
|
|
// Create a new user hash
|
|
|
|
// Get the current content, store it in the new user file
|
|
|
|
// Get the current content, store it in the new user file
|
|
|
|
// and make sure the new user drive is owned
|
|
|
|
// and make sure the new user drive is owned
|
|
|
@ -742,26 +760,67 @@ define([
|
|
|
|
}), optsPut);
|
|
|
|
}), optsPut);
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
// Migration success
|
|
|
|
// Drive content copied: get the new block location
|
|
|
|
// TODO: Replace user hash in login block
|
|
|
|
Cred.deriveFromPassphrase(accountName, newPassword, 192, waitFor(function (bytes) {
|
|
|
|
|
|
|
|
newBlockSeed = null; // XXX
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
|
|
|
// Write the new login block
|
|
|
|
|
|
|
|
var keys = Block.genkeys(newBlockSeed);
|
|
|
|
|
|
|
|
var content = Block.serialize(JSON.stringify({
|
|
|
|
|
|
|
|
User_name: accountName,
|
|
|
|
|
|
|
|
User_hash: newHash
|
|
|
|
|
|
|
|
}), keys);
|
|
|
|
|
|
|
|
common.writeLoginBlock(content, waitFor(function (obj) {
|
|
|
|
|
|
|
|
var newBlockHash = Block.getBlockHash(keys);
|
|
|
|
|
|
|
|
LocalStore.setBlockHash(newBlockHash);
|
|
|
|
|
|
|
|
if (obj && obj.error) {
|
|
|
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
|
|
|
return void cb(obj);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}));
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
// New drive hash is in login block, unpin the old one and pin the new one
|
|
|
|
// New drive hash is in login block, unpin the old one and pin the new one
|
|
|
|
common.unpinPads([secret.channel], waitFor());
|
|
|
|
common.unpinPads([secret.channel], waitFor());
|
|
|
|
common.pinPads([newSecret.channel], waitFor());
|
|
|
|
common.pinPads([newSecret.channel], waitFor());
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
// Login block updated
|
|
|
|
// Remove block hash
|
|
|
|
// TODO: logout everywhere
|
|
|
|
if (blockHash) {
|
|
|
|
// * It should wipe localStorage.User_hash, ...
|
|
|
|
var removeData = Block.remove(keys);
|
|
|
|
// * login will get the new value from loginBlock and store it in localStorage
|
|
|
|
common.removeLoginBlock(removeData, waitFor(function (obj) {
|
|
|
|
// * SharedWorker will reconnect with the new value in other locations
|
|
|
|
if (obj && obj.error) { return void console.error(obj.error); }
|
|
|
|
// TODO: then DISCONNECT here
|
|
|
|
}));
|
|
|
|
common.logoutFromAll(waitFor(function () {
|
|
|
|
}
|
|
|
|
postMessage("DISCONNECT");
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
}));
|
|
|
|
if (oldIsOwned) {
|
|
|
|
|
|
|
|
common.removeOwnedChannel(secret.channel, waitFor(function (obj) {
|
|
|
|
|
|
|
|
if (obj && obj.error) {
|
|
|
|
|
|
|
|
// Deal with it as if it was not owned
|
|
|
|
|
|
|
|
oldIsOwned = false;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
common.logoutFromAll(waitFor(function () {
|
|
|
|
|
|
|
|
postMessage("DISCONNECT");
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
|
|
|
if (!oldIsOwned) {
|
|
|
|
|
|
|
|
postMessage("SET", {
|
|
|
|
|
|
|
|
key: [Constants.deprecatedKey],
|
|
|
|
|
|
|
|
value: true
|
|
|
|
|
|
|
|
}, waitFor(function (obj) {
|
|
|
|
|
|
|
|
if (obj && obj.error) {
|
|
|
|
|
|
|
|
console.error(obj.error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
common.logoutFromAll(waitFor(function () {
|
|
|
|
|
|
|
|
postMessage("DISCONNECT");
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
}
|
|
|
|
}).nThen(function () {
|
|
|
|
}).nThen(function () {
|
|
|
|
// We have the new drive, with the new login block
|
|
|
|
// We have the new drive, with the new login block
|
|
|
|
// TODO: maybe reload automatically?
|
|
|
|
window.location.reload();
|
|
|
|
cb({ state: true });
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|