Send a mailbox address (encrypted) to the owned pads metadata
This commit is contained in:
@@ -700,6 +700,10 @@ define([
|
|||||||
postMessage("GIVE_PAD_ACCESS", data, cb);
|
postMessage("GIVE_PAD_ACCESS", data, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
common.getPadMetadata = function (data, cb) {
|
||||||
|
postMessage('GET_PAD_METADATA', data, cb);
|
||||||
|
};
|
||||||
|
|
||||||
common.changePadPassword = function (Crypt, href, newPassword, edPublic, cb) {
|
common.changePadPassword = function (Crypt, href, newPassword, edPublic, cb) {
|
||||||
if (!href) { return void cb({ error: 'EINVAL_HREF' }); }
|
if (!href) { return void cb({ error: 'EINVAL_HREF' }); }
|
||||||
var parsed = Hash.parsePadUrl(href);
|
var parsed = Hash.parsePadUrl(href);
|
||||||
|
|||||||
@@ -1242,10 +1242,9 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
Store.requestPadAccess = function (clientId, data, cb) {
|
Store.requestPadAccess = function (clientId, data, cb) {
|
||||||
// Get owners from pad metadata
|
var owner = data.owner;
|
||||||
// Try to find an owner in our friend list
|
|
||||||
// Mailbox...
|
|
||||||
var channel = channels[data.channel];
|
var channel = channels[data.channel];
|
||||||
|
if (!channel) { return void cb({error: 'ENOTFOUND'}); }
|
||||||
if (!data.send && channel && (!channel.data || !channel.data.channel)) {
|
if (!data.send && channel && (!channel.data || !channel.data.channel)) {
|
||||||
var i = 0;
|
var i = 0;
|
||||||
var it = setInterval(function () {
|
var it = setInterval(function () {
|
||||||
@@ -1261,11 +1260,12 @@ define([
|
|||||||
}, 200);
|
}, 200);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the owner was not is the pad metadata, check if it is a friend
|
||||||
var fData = channel.data || {};
|
var fData = channel.data || {};
|
||||||
if (fData.owners) {
|
if (!owner && fData.owners) {
|
||||||
var friends = store.proxy.friends || {};
|
var friends = store.proxy.friends || {};
|
||||||
if (Object.keys(friends).length > 1) {
|
if (Object.keys(friends).length > 1) {
|
||||||
var owner;
|
|
||||||
fData.owners.some(function (edPublic) {
|
fData.owners.some(function (edPublic) {
|
||||||
return Object.keys(friends).some(function (curve) {
|
return Object.keys(friends).some(function (curve) {
|
||||||
if (curve === "me") { return; }
|
if (curve === "me") { return; }
|
||||||
@@ -1276,26 +1276,28 @@ define([
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
if (owner) {
|
|
||||||
if (data.send) {
|
|
||||||
var myData = Messaging.createData(store.proxy);
|
|
||||||
delete myData.channel;
|
|
||||||
store.mailbox.sendTo('REQUEST_PAD_ACCESS', {
|
|
||||||
channel: data.channel,
|
|
||||||
user: myData
|
|
||||||
}, {
|
|
||||||
channel: owner.notifications,
|
|
||||||
curvePublic: owner.curvePublic
|
|
||||||
}, function () {
|
|
||||||
cb({state: true});
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return void cb({state: true});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cb({sent: false});
|
|
||||||
|
// If send is true, send the request to the owner.
|
||||||
|
if (owner) {
|
||||||
|
if (data.send) {
|
||||||
|
var myData = Messaging.createData(store.proxy);
|
||||||
|
delete myData.channel;
|
||||||
|
store.mailbox.sendTo('REQUEST_PAD_ACCESS', {
|
||||||
|
channel: data.channel,
|
||||||
|
user: myData
|
||||||
|
}, {
|
||||||
|
channel: owner.notifications,
|
||||||
|
curvePublic: owner.curvePublic
|
||||||
|
}, function () {
|
||||||
|
cb({state: true});
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return void cb({state: true});
|
||||||
|
}
|
||||||
|
cb({state: false});
|
||||||
};
|
};
|
||||||
Store.givePadAccess = function (clientId, data, cb) {
|
Store.givePadAccess = function (clientId, data, cb) {
|
||||||
var edPublic = store.proxy.edPublic;
|
var edPublic = store.proxy.edPublic;
|
||||||
@@ -1332,6 +1334,28 @@ define([
|
|||||||
cb();
|
cb();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Store.getPadMetadata = function (clientId, data, cb) {
|
||||||
|
if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); }
|
||||||
|
var channel = channels[data.channel];
|
||||||
|
if (!channel) { return void cb({ error: 'ENOTFOUND' }); }
|
||||||
|
if (!channel.data || !channel.data.channel) {
|
||||||
|
var i = 0;
|
||||||
|
var it = setInterval(function () {
|
||||||
|
if (channel.data && channel.data.channel) {
|
||||||
|
clearInterval(it);
|
||||||
|
Store.getPadMetadata(clientId, data, cb);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (i >= 300) { // One minute timeout
|
||||||
|
clearInterval(it);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}, 200);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cb(channel.data || {});
|
||||||
|
};
|
||||||
|
|
||||||
// GET_FULL_HISTORY from sframe-common-outer
|
// GET_FULL_HISTORY from sframe-common-outer
|
||||||
Store.getFullHistory = function (clientId, data, cb) {
|
Store.getFullHistory = function (clientId, data, cb) {
|
||||||
var network = store.network;
|
var network = store.network;
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ define([
|
|||||||
IS_NEW_CHANNEL: Store.isNewChannel,
|
IS_NEW_CHANNEL: Store.isNewChannel,
|
||||||
REQUEST_PAD_ACCESS: Store.requestPadAccess,
|
REQUEST_PAD_ACCESS: Store.requestPadAccess,
|
||||||
GIVE_PAD_ACCESS: Store.givePadAccess,
|
GIVE_PAD_ACCESS: Store.givePadAccess,
|
||||||
|
GET_PAD_METADATA: Store.getPadMetadata,
|
||||||
// Drive
|
// Drive
|
||||||
DRIVE_USEROBJECT: Store.userObjectCommand,
|
DRIVE_USEROBJECT: Store.userObjectCommand,
|
||||||
// Settings,
|
// Settings,
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ define([
|
|||||||
var parsed = Utils.Hash.parsePadUrl(window.location.href);
|
var parsed = Utils.Hash.parsePadUrl(window.location.href);
|
||||||
if (!parsed.type) { throw new Error(); }
|
if (!parsed.type) { throw new Error(); }
|
||||||
var defaultTitle = Utils.Hash.getDefaultName(parsed);
|
var defaultTitle = Utils.Hash.getDefaultName(parsed);
|
||||||
var edPublic;
|
var edPublic, curvePublic, notifications;
|
||||||
var forceCreationScreen = cfg.useCreationScreen &&
|
var forceCreationScreen = cfg.useCreationScreen &&
|
||||||
sessionStorage[Utils.Constants.displayPadCreationScreen];
|
sessionStorage[Utils.Constants.displayPadCreationScreen];
|
||||||
delete sessionStorage[Utils.Constants.displayPadCreationScreen];
|
delete sessionStorage[Utils.Constants.displayPadCreationScreen];
|
||||||
@@ -284,6 +284,8 @@ define([
|
|||||||
if (err) { console.log(err); }
|
if (err) { console.log(err); }
|
||||||
metaObj = m;
|
metaObj = m;
|
||||||
edPublic = metaObj.priv.edPublic; // needed to create an owned pad
|
edPublic = metaObj.priv.edPublic; // needed to create an owned pad
|
||||||
|
curvePublic = metaObj.user.curvePublic;
|
||||||
|
notifications = metaObj.user.notifications;
|
||||||
}));
|
}));
|
||||||
Cryptpad.isTemplate(window.location.href, waitFor(function (err, t) {
|
Cryptpad.isTemplate(window.location.href, waitFor(function (err, t) {
|
||||||
if (err) { console.log(err); }
|
if (err) { console.log(err); }
|
||||||
@@ -948,10 +950,33 @@ define([
|
|||||||
if (readOnly && hashes.editHash) {
|
if (readOnly && hashes.editHash) {
|
||||||
return void cb({error: 'ALREADYKNOWN'});
|
return void cb({error: 'ALREADYKNOWN'});
|
||||||
}
|
}
|
||||||
Cryptpad.padRpc.requestAccess({
|
var owner;
|
||||||
send: data,
|
var crypto = Crypto.createEncryptor(secret.keys);
|
||||||
channel: secret.channel
|
nThen(function (waitFor) {
|
||||||
}, cb);
|
// Try to get the owner's mailbox from the pad metadata first.
|
||||||
|
// If it's is an older owned pad, check if the owner is a friend
|
||||||
|
// or an acquaintance (from async-store directly in requestAccess)
|
||||||
|
Cryptpad.getPadMetadata({
|
||||||
|
channel: secret.channel
|
||||||
|
}, waitFor(function (obj) {
|
||||||
|
obj = obj || {};
|
||||||
|
if (obj.error) { return; }
|
||||||
|
if (obj.mailbox) {
|
||||||
|
try {
|
||||||
|
var dataStr = crypto.decrypt(obj.mailbox, true, true);
|
||||||
|
var data = JSON.parse(dataStr);
|
||||||
|
if (!data.notifications || !data.curvePublic) { return; }
|
||||||
|
owner = data;
|
||||||
|
} catch (e) { console.error(e); }
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}).nThen(function () {
|
||||||
|
Cryptpad.padRpc.requestAccess({
|
||||||
|
send: data,
|
||||||
|
channel: secret.channel,
|
||||||
|
owner: owner
|
||||||
|
}, cb);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (cfg.messaging) {
|
if (cfg.messaging) {
|
||||||
@@ -1079,6 +1104,10 @@ define([
|
|||||||
};
|
};
|
||||||
if (data.owned) {
|
if (data.owned) {
|
||||||
rtConfig.metadata.owners = [edPublic];
|
rtConfig.metadata.owners = [edPublic];
|
||||||
|
rtConfig.metadata.mailbox = Utils.crypto.encrypt(JSON.stringify({
|
||||||
|
notifications: notifications,
|
||||||
|
curvePublic: curvePublic
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
if (data.expire) {
|
if (data.expire) {
|
||||||
rtConfig.metadata.expire = data.expire;
|
rtConfig.metadata.expire = data.expire;
|
||||||
|
|||||||
@@ -575,7 +575,6 @@ MessengerUI, Messages) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var createRequest = function (toolbar, config) {
|
var createRequest = function (toolbar, config) {
|
||||||
console.error('test');
|
|
||||||
if (!config.metadataMgr) {
|
if (!config.metadataMgr) {
|
||||||
throw new Error("You must provide a `metadataMgr` to display the request access button");
|
throw new Error("You must provide a `metadataMgr` to display the request access button");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user