Browse Source

reencrypt for tribe owner receive

feature/dockerfile-arm
Evan Feenstra 5 years ago
parent
commit
d267d8dff0
  1. 23
      api/network/receive.ts
  2. 8
      api/utils/msg.ts
  3. 27
      dist/api/network/receive.js
  4. 2
      dist/api/network/receive.js.map
  5. 7
      dist/api/utils/msg.js
  6. 2
      dist/api/utils/msg.js.map

23
api/network/receive.ts

@ -7,6 +7,7 @@ import {SPHINX_CUSTOM_RECORD_KEY, verifyAscii} from '../utils/lightning'
import { models } from '../models' import { models } from '../models'
import {sendMessage} from './send' import {sendMessage} from './send'
import {modifyPayload} from './modify' import {modifyPayload} from './modify'
import {decryptMessage,encryptTribeBroadcast} from '../utils/msg'
const constants = require(path.join(__dirname,'../../config/constants.json')) const constants = require(path.join(__dirname,'../../config/constants.json'))
const msgtypes = constants.message_types const msgtypes = constants.message_types
@ -40,12 +41,22 @@ async function onReceive(payload){
else console.log('=> insufficient payment for this action') else console.log('=> insufficient payment for this action')
} }
} }
if(doAction) { if(doAction) doTheAction({...payload, ...toAddIn})
if(ACTIONS[payload.type]) { }
ACTIONS[payload.type]({...payload, ...toAddIn})
} else { async function doTheAction(data){
console.log('Incorrect payload type:', payload.type) let payload = data
} if(payload.isTribeOwner) {
// decrypt and re-encrypt with self pubkey
const chat = await models.Chat.findOne({where:{uuid:payload.chat.uuid}})
const pld = await decryptMessage(data, chat)
const me = await models.Contact.findOne({where:{isOwner:true}})
payload = await encryptTribeBroadcast(pld, me, true) // true=isTribeOwner
}
if(ACTIONS[payload.type]) {
ACTIONS[payload.type](payload)
} else {
console.log('Incorrect payload type:', payload.type)
} }
} }

8
api/utils/msg.ts

@ -40,14 +40,14 @@ function removeAllNonAdminMembersIfTribe(full:{[k:string]:any}, destkey){
// THIS IS ONLY FOR TRIBE OWNER // THIS IS ONLY FOR TRIBE OWNER
// by this time the content and mediaKey are already in message as string // by this time the content and mediaKey are already in message as string
async function encryptTribeBroadcast(full:{[k:string]:any}, contact, isTribe:boolean, isTribeOwner:boolean){ async function encryptTribeBroadcast(full:{[k:string]:any}, contact, isTribeOwner:boolean){
if(!isTribeOwner) return full if(!isTribeOwner) return full
const chat = full && full.chat const chat = full && full.chat
const message = full && full.message const message = full && full.message
if (!message || !(chat && chat.type && chat.uuid)) return full if (!message || !(chat && chat.type && chat.uuid)) return full
const obj: {[k:string]:any} = {} const obj: {[k:string]:any} = {}
if(isTribe && isTribeOwner) { // has been previously decrypted if(isTribeOwner) { // has been previously decrypted
if(message.content) { if(message.content) {
const encContent = await rsa.encrypt(contact.contactKey, message.content) const encContent = await rsa.encrypt(contact.contactKey, message.content)
obj.content = encContent obj.content = encContent
@ -144,7 +144,7 @@ async function personalizeMessage(m,contact,isTribeOwner:boolean){
const cleanerMsg = removeAllNonAdminMembersIfTribe(cleanMsg, destkey) const cleanerMsg = removeAllNonAdminMembersIfTribe(cleanMsg, destkey)
const msgWithMediaKey = addInMediaKey(cleanerMsg, contactId, isTribe) const msgWithMediaKey = addInMediaKey(cleanerMsg, contactId, isTribe)
const msgWithMediaToken = await finishTermsAndReceipt(msgWithMediaKey, destkey) const msgWithMediaToken = await finishTermsAndReceipt(msgWithMediaKey, destkey)
const encMsg = await encryptTribeBroadcast(msgWithMediaToken, contact, isTribe, isTribeOwner) const encMsg = await encryptTribeBroadcast(msgWithMediaToken, contact, isTribeOwner)
return encMsg return encMsg
} }
@ -167,5 +167,5 @@ function fillchatmsg(full, props){
} }
export { export {
personalizeMessage, decryptMessage, personalizeMessage, decryptMessage, encryptTribeBroadcast,
} }

27
dist/api/network/receive.js

@ -18,6 +18,7 @@ const lightning_2 = require("../utils/lightning");
const models_1 = require("../models"); const models_1 = require("../models");
const send_1 = require("./send"); const send_1 = require("./send");
const modify_1 = require("./modify"); const modify_1 = require("./modify");
const msg_1 = require("../utils/msg");
const constants = require(path.join(__dirname, '../../config/constants.json')); const constants = require(path.join(__dirname, '../../config/constants.json'));
const msgtypes = constants.message_types; const msgtypes = constants.message_types;
const typesToForward = [ const typesToForward = [
@ -54,13 +55,25 @@ function onReceive(payload) {
console.log('=> insufficient payment for this action'); console.log('=> insufficient payment for this action');
} }
} }
if (doAction) { if (doAction)
if (ACTIONS[payload.type]) { doTheAction(Object.assign(Object.assign({}, payload), toAddIn));
ACTIONS[payload.type](Object.assign(Object.assign({}, payload), toAddIn)); });
} }
else { function doTheAction(data) {
console.log('Incorrect payload type:', payload.type); return __awaiter(this, void 0, void 0, function* () {
} let payload = data;
if (payload.isTribeOwner) {
// decrypt and re-encrypt with self pubkey
const chat = yield models_1.models.Chat.findOne({ where: { uuid: payload.chat.uuid } });
const pld = yield msg_1.decryptMessage(data, chat);
const me = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
payload = yield msg_1.encryptTribeBroadcast(pld, me, true); // true=isTribeOwner
}
if (ACTIONS[payload.type]) {
ACTIONS[payload.type](payload);
}
else {
console.log('Incorrect payload type:', payload.type);
} }
}); });
} }

2
dist/api/network/receive.js.map

File diff suppressed because one or more lines are too long

7
dist/api/utils/msg.js

@ -49,7 +49,7 @@ function removeAllNonAdminMembersIfTribe(full, destkey) {
} }
// THIS IS ONLY FOR TRIBE OWNER // THIS IS ONLY FOR TRIBE OWNER
// by this time the content and mediaKey are already in message as string // by this time the content and mediaKey are already in message as string
function encryptTribeBroadcast(full, contact, isTribe, isTribeOwner) { function encryptTribeBroadcast(full, contact, isTribeOwner) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (!isTribeOwner) if (!isTribeOwner)
return full; return full;
@ -58,7 +58,7 @@ function encryptTribeBroadcast(full, contact, isTribe, isTribeOwner) {
if (!message || !(chat && chat.type && chat.uuid)) if (!message || !(chat && chat.type && chat.uuid))
return full; return full;
const obj = {}; const obj = {};
if (isTribe && isTribeOwner) { // has been previously decrypted if (isTribeOwner) { // has been previously decrypted
if (message.content) { if (message.content) {
const encContent = yield rsa.encrypt(contact.contactKey, message.content); const encContent = yield rsa.encrypt(contact.contactKey, message.content);
obj.content = encContent; obj.content = encContent;
@ -71,6 +71,7 @@ function encryptTribeBroadcast(full, contact, isTribe, isTribeOwner) {
return fillmsg(full, obj); return fillmsg(full, obj);
}); });
} }
exports.encryptTribeBroadcast = encryptTribeBroadcast;
function addInMediaKey(full, contactId, isTribe) { function addInMediaKey(full, contactId, isTribe) {
const m = full && full.message; const m = full && full.message;
if (!(m && m.mediaKey)) if (!(m && m.mediaKey))
@ -157,7 +158,7 @@ function personalizeMessage(m, contact, isTribeOwner) {
const cleanerMsg = removeAllNonAdminMembersIfTribe(cleanMsg, destkey); const cleanerMsg = removeAllNonAdminMembersIfTribe(cleanMsg, destkey);
const msgWithMediaKey = addInMediaKey(cleanerMsg, contactId, isTribe); const msgWithMediaKey = addInMediaKey(cleanerMsg, contactId, isTribe);
const msgWithMediaToken = yield finishTermsAndReceipt(msgWithMediaKey, destkey); const msgWithMediaToken = yield finishTermsAndReceipt(msgWithMediaKey, destkey);
const encMsg = yield encryptTribeBroadcast(msgWithMediaToken, contact, isTribe, isTribeOwner); const encMsg = yield encryptTribeBroadcast(msgWithMediaToken, contact, isTribeOwner);
return encMsg; return encMsg;
}); });
} }

2
dist/api/utils/msg.js.map

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save