|
|
|
@ -779,7 +779,7 @@ define([
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
common.changePadPassword = function (Crypt, href, newPassword, edPublic, cb) {
|
|
|
|
|
common.changePadPassword = function (Crypt, Crypto, href, newPassword, edPublic, cb) {
|
|
|
|
|
if (!href) { return void cb({ error: 'EINVAL_HREF' }); }
|
|
|
|
|
var parsed = Hash.parsePadUrl(href);
|
|
|
|
|
if (!parsed.hash) { return void cb({ error: 'EINVAL_HREF' }); }
|
|
|
|
@ -787,6 +787,8 @@ define([
|
|
|
|
|
var warning = false;
|
|
|
|
|
var newHash, newRoHref;
|
|
|
|
|
var oldChannel;
|
|
|
|
|
var oldSecret;
|
|
|
|
|
var oldMetadata;
|
|
|
|
|
var newSecret;
|
|
|
|
|
|
|
|
|
|
if (parsed.hashData.version >= 2) {
|
|
|
|
@ -803,27 +805,61 @@ define([
|
|
|
|
|
|
|
|
|
|
var optsGet = {};
|
|
|
|
|
var optsPut = {
|
|
|
|
|
password: newPassword
|
|
|
|
|
password: newPassword,
|
|
|
|
|
metadata: {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Nthen(function (waitFor) {
|
|
|
|
|
if (parsed.hashData && parsed.hashData.password) {
|
|
|
|
|
common.getPadAttribute('password', waitFor(function (err, password) {
|
|
|
|
|
optsGet.password = password;
|
|
|
|
|
}), href);
|
|
|
|
|
}
|
|
|
|
|
common.getPadAttribute('owners', waitFor(function (err, owners) {
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
oldSecret = Hash.getSecrets(parsed.type, parsed.hash, optsGet.password);
|
|
|
|
|
oldChannel = oldSecret.channel;
|
|
|
|
|
common.getPadMetadata({channel: oldChannel}, waitFor(function (metadata) {
|
|
|
|
|
oldMetadata = metadata;
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
// Get owners, mailbox and expiration time
|
|
|
|
|
|
|
|
|
|
var owners = oldMetadata.owners;
|
|
|
|
|
if (!Array.isArray(owners) || owners.indexOf(edPublic) === -1) {
|
|
|
|
|
// We're not an owner, we shouldn't be able to change the password!
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
return void cb({ error: 'EPERM' });
|
|
|
|
|
}
|
|
|
|
|
optsPut.owners = owners;
|
|
|
|
|
}), href);
|
|
|
|
|
// XXX get the mailbox fields, decrypt all the mailboxes, reencrypt them, and put them in the metadata
|
|
|
|
|
// XXX also use optsPut.metadata (and fix it in cryptget) instead of optsPut.owners
|
|
|
|
|
common.getPadAttribute('expire', waitFor(function (err, expire) {
|
|
|
|
|
optsPut.expire = (expire - (+new Date())) / 1000; // Lifetime in seconds
|
|
|
|
|
}), href);
|
|
|
|
|
optsPut.metadata.owners = owners;
|
|
|
|
|
|
|
|
|
|
var mailbox = oldMetadata.mailbox;
|
|
|
|
|
if (mailbox) {
|
|
|
|
|
// Create the encryptors to be able to decrypt and re-encrypt the mailboxes
|
|
|
|
|
var oldCrypto = Crypto.createEncryptor(oldSecret.keys);
|
|
|
|
|
var newCrypto = Crypto.createEncryptor(newSecret.keys);
|
|
|
|
|
|
|
|
|
|
var m;
|
|
|
|
|
if (typeof(mailbox) === "string") {
|
|
|
|
|
try {
|
|
|
|
|
m = newCrypto.encrypt(oldCrypto.decrypt(mailbox, true, true));
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
} else if (mailbox && typeof(mailbox) == "object") {
|
|
|
|
|
m = {};
|
|
|
|
|
Object.keys(mailbox).forEach(function (ed) {
|
|
|
|
|
console.log(mailbox[ed]);
|
|
|
|
|
try {
|
|
|
|
|
m[ed] = newCrypto.encrypt(oldCrypto.decrypt(mailbox[ed], true, true));
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
optsPut.metadata.mailbox = m;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var expire = oldMetadata.expire;
|
|
|
|
|
optsPut.metadata.expire = (expire - (+new Date())) / 1000; // Lifetime in seconds
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
Crypt.get(parsed.hash, waitFor(function (err, val) {
|
|
|
|
|
if (err) {
|
|
|
|
@ -838,8 +874,6 @@ define([
|
|
|
|
|
}), optsPut);
|
|
|
|
|
}), optsGet);
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
var secret = Hash.getSecrets(parsed.type, parsed.hash, optsGet.password);
|
|
|
|
|
oldChannel = secret.channel;
|
|
|
|
|
pad.leavePad({
|
|
|
|
|
channel: oldChannel
|
|
|
|
|
}, waitFor());
|
|
|
|
|