Validate messages not coming from history-keeper

pull/1/head
yflory 7 years ago
parent 2381dd0e39
commit e37aab492b

@ -918,8 +918,12 @@ define([
channel.data = padData || {}; channel.data = padData || {};
postMessage("PAD_READY"); postMessage("PAD_READY");
}, // post EV_PAD_READY }, // post EV_PAD_READY
onMessage: function (m) { onMessage: function (user, m, validateKey) {
postMessage("PAD_MESSAGE", m); postMessage("PAD_MESSAGE", {
user: user,
msg: m,
validateKey: validateKey
});
}, // post EV_PAD_MESSAGE }, // post EV_PAD_MESSAGE
onJoin: function (m) { onJoin: function (m) {
postMessage("PAD_JOIN", m); postMessage("PAD_JOIN", m);

@ -130,7 +130,7 @@ define([], function () {
message = unBencode(message);//.slice(message.indexOf(':[') + 1); message = unBencode(message);//.slice(message.indexOf(':[') + 1);
// pass the message into Chainpad // pass the message into Chainpad
onMessage(message); onMessage(peer, message, validateKey);
//sframeChan.query('Q_RT_MESSAGE', message, function () { }); //sframeChan.query('Q_RT_MESSAGE', message, function () { });
}; };

@ -39,9 +39,11 @@ define([], function () {
}); });
// shim between chainpad and netflux // shim between chainpad and netflux
var msgIn = function (msg) { var msgIn = function (peer, msg) {
try { try {
var decryptedMsg = Crypto.decrypt(msg, isNewHash); var isHk = peer.length !== 32;
var key = isNewHash ? validateKey : false;
var decryptedMsg = Crypto.decrypt(msg, key, isHk);
return decryptedMsg; return decryptedMsg;
} catch (err) { } catch (err) {
console.error(err); console.error(err);
@ -67,8 +69,11 @@ define([], function () {
padRpc.sendPadMsg(msg, cb); padRpc.sendPadMsg(msg, cb);
}); });
var onMessage = function(msg) { var onMessage = function(msgObj) {
var message = msgIn(msg); if (msgObj.validateKey && !validateKey) {
validateKey = msgObj.validateKey;
}
var message = msgIn(msgObj.user, msgObj.msg);
verbose(message); verbose(message);

@ -325,7 +325,9 @@ define([
validateKey: secret.keys.validateKey validateKey: secret.keys.validateKey
}, function (encryptedMsgs) { }, function (encryptedMsgs) {
cb(encryptedMsgs.map(function (msg) { cb(encryptedMsgs.map(function (msg) {
return crypto.decrypt(msg, true); // The 3rd parameter "true" means we're going to skip signature validation.
// We don't need it since the message is already validated serverside by hk
return crypto.decrypt(msg, true, true);
})); }));
}); });
}); });

Loading…
Cancel
Save