|
|
@ -232,17 +232,6 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
postMessage("MIGRATE_ANON_DRIVE", data, cb);
|
|
|
|
postMessage("MIGRATE_ANON_DRIVE", data, cb);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
// Settings
|
|
|
|
|
|
|
|
common.deleteAccount = function (cb) {
|
|
|
|
|
|
|
|
postMessage("DELETE_ACCOUNT", null, function (obj) {
|
|
|
|
|
|
|
|
if (obj.state) {
|
|
|
|
|
|
|
|
Feedback.send('DELETE_ACCOUNT_AUTOMATIC');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Feedback.send('DELETE_ACCOUNT_MANUAL');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cb(obj);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Drive
|
|
|
|
// Drive
|
|
|
|
common.userObjectCommand = function (data, cb) {
|
|
|
|
common.userObjectCommand = function (data, cb) {
|
|
|
|
postMessage("DRIVE_USEROBJECT", data, cb);
|
|
|
|
postMessage("DRIVE_USEROBJECT", data, cb);
|
|
|
@ -1674,30 +1663,16 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
common.changeUserPassword = function (Crypt, edPublic, data, cb) {
|
|
|
|
var getBlockKeys = function (data, cb) {
|
|
|
|
if (!edPublic) {
|
|
|
|
|
|
|
|
return void cb({
|
|
|
|
|
|
|
|
error: 'E_NOT_LOGGED_IN'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var accountName = LocalStore.getAccountName();
|
|
|
|
var accountName = LocalStore.getAccountName();
|
|
|
|
var hash = LocalStore.getUserHash();
|
|
|
|
var password = data.password;
|
|
|
|
if (!hash) {
|
|
|
|
var Cred, Block, Login;
|
|
|
|
return void cb({
|
|
|
|
var blockKeys;
|
|
|
|
error: 'E_NOT_LOGGED_IN'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 newHash, newHref, newSecret, blockKeys;
|
|
|
|
|
|
|
|
var oldIsOwned = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var hash = LocalStore.getUserHash();
|
|
|
|
|
|
|
|
if (!hash) { return void cb({ error: 'E_NOT_LOGGED_IN' }); }
|
|
|
|
var blockHash = LocalStore.getBlockHash();
|
|
|
|
var blockHash = LocalStore.getBlockHash();
|
|
|
|
var oldBlockKeys;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var Cred, Block, Login;
|
|
|
|
|
|
|
|
Nthen(function (waitFor) {
|
|
|
|
Nthen(function (waitFor) {
|
|
|
|
require([
|
|
|
|
require([
|
|
|
|
'/common/common-credential.js',
|
|
|
|
'/common/common-credential.js',
|
|
|
@ -1710,30 +1685,92 @@ define([
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
// confirm that the provided password is correct
|
|
|
|
// confirm that the provided password is correct
|
|
|
|
Cred.deriveFromPassphrase(accountName, password, Login.requiredBytes, waitFor(function (bytes) {
|
|
|
|
Cred.deriveFromPassphrase(accountName, password, Login.requiredBytes,
|
|
|
|
|
|
|
|
waitFor(function (bytes) {
|
|
|
|
var allocated = Login.allocateBytes(bytes);
|
|
|
|
var allocated = Login.allocateBytes(bytes);
|
|
|
|
oldBlockKeys = allocated.blockKeys;
|
|
|
|
blockKeys = allocated.blockKeys;
|
|
|
|
if (blockHash) {
|
|
|
|
if (blockHash) {
|
|
|
|
if (blockHash !== allocated.blockHash) {
|
|
|
|
if (blockHash !== allocated.blockHash) {
|
|
|
|
|
|
|
|
// incorrect password
|
|
|
|
console.log("provided password did not yield the correct blockHash");
|
|
|
|
console.log("provided password did not yield the correct blockHash");
|
|
|
|
// incorrect password probably
|
|
|
|
|
|
|
|
waitFor.abort();
|
|
|
|
waitFor.abort();
|
|
|
|
return void cb({
|
|
|
|
return void cb({ error: 'INVALID_PASSWORD', });
|
|
|
|
error: 'INVALID_PASSWORD',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// the user has already created a block, so you should compare against that
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// otherwise they're a legacy user, and we should check against the User_hash
|
|
|
|
// otherwise they're a legacy user, and we should check against the User_hash
|
|
|
|
if (hash !== allocated.userHash) {
|
|
|
|
if (hash !== allocated.userHash) {
|
|
|
|
|
|
|
|
// incorrect password
|
|
|
|
console.log("provided password did not yield the correct userHash");
|
|
|
|
console.log("provided password did not yield the correct userHash");
|
|
|
|
waitFor.abort();
|
|
|
|
waitFor.abort();
|
|
|
|
return void cb({
|
|
|
|
return void cb({ error: 'INVALID_PASSWORD', });
|
|
|
|
error: 'INVALID_PASSWORD',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
|
|
|
cb({
|
|
|
|
|
|
|
|
Cred: Cred,
|
|
|
|
|
|
|
|
Block: Block,
|
|
|
|
|
|
|
|
Login: Login,
|
|
|
|
|
|
|
|
blockKeys: blockKeys
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
common.deleteAccount = function (data, cb) {
|
|
|
|
|
|
|
|
data = data || {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Confirm that the provided password is corrct and get the block keys
|
|
|
|
|
|
|
|
getBlockKeys(data, function (obj) {
|
|
|
|
|
|
|
|
if (obj && obj.error) { return void cb(obj); }
|
|
|
|
|
|
|
|
var blockKeys = obj.blockKeys;
|
|
|
|
|
|
|
|
var removeData = obj.Block.remove(blockKeys);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
postMessage("DELETE_ACCOUNT", {
|
|
|
|
|
|
|
|
removeData: removeData
|
|
|
|
|
|
|
|
}, function (obj) {
|
|
|
|
|
|
|
|
if (obj.state) {
|
|
|
|
|
|
|
|
Feedback.send('DELETE_ACCOUNT_AUTOMATIC');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Feedback.send('DELETE_ACCOUNT_MANUAL');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cb(obj);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
common.changeUserPassword = function (Crypt, edPublic, data, cb) {
|
|
|
|
|
|
|
|
if (!edPublic) {
|
|
|
|
|
|
|
|
return void cb({
|
|
|
|
|
|
|
|
error: 'E_NOT_LOGGED_IN'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var accountName = LocalStore.getAccountName();
|
|
|
|
|
|
|
|
var hash = LocalStore.getUserHash();
|
|
|
|
|
|
|
|
if (!hash) {
|
|
|
|
|
|
|
|
return void cb({
|
|
|
|
|
|
|
|
error: 'E_NOT_LOGGED_IN'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 newHash, newHref, newSecret, blockKeys;
|
|
|
|
|
|
|
|
var oldIsOwned = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var blockHash = LocalStore.getBlockHash();
|
|
|
|
|
|
|
|
var oldBlockKeys;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var Cred, Block, Login;
|
|
|
|
|
|
|
|
Nthen(function (waitFor) {
|
|
|
|
|
|
|
|
getBlockKeys(data, waitFor(function (obj) {
|
|
|
|
|
|
|
|
if (obj && obj.error) {
|
|
|
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
|
|
|
return void cb(obj);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
oldBlockKeys = obj.blockKeys;
|
|
|
|
|
|
|
|
Cred = obj.Cred;
|
|
|
|
|
|
|
|
Login = obj.Login;
|
|
|
|
|
|
|
|
Block = obj.Block;
|
|
|
|
|
|
|
|
}));
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
// Check if our drive is already owned
|
|
|
|
// Check if our drive is already owned
|
|
|
|
console.log("checking if old drive is owned");
|
|
|
|
console.log("checking if old drive is owned");
|
|
|
|