Browse Source

refactor key exchange

docker-workflow-build
Evan Feenstra 4 years ago
parent
commit
252320a312
  1. 2
      app.ts
  2. 2
      dist/app.js
  3. 2
      dist/app.js.map
  4. 9
      dist/src/controllers/contacts.js
  5. 2
      dist/src/controllers/contacts.js.map
  6. 28
      dist/src/helpers.js
  7. 2
      dist/src/helpers.js.map
  8. 9
      src/controllers/contacts.ts
  9. 25
      src/helpers.ts

2
app.ts

@ -19,7 +19,7 @@ const config = loadConfig()
const port = process.env.PORT || config.node_http_port || 3001
console.log("=> env:", env)
console.log('=> config: ',config)
// console.log('=> config: ',config)
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA'

2
dist/app.js

@ -28,7 +28,7 @@ const env = process.env.NODE_ENV || 'development';
const config = config_1.loadConfig();
const port = process.env.PORT || config.node_http_port || 3001;
console.log("=> env:", env);
console.log('=> config: ', config);
// console.log('=> config: ',config)
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
// START SETUP!
function start() {

2
dist/app.js.map

@ -1 +1 @@
{"version":3,"file":"app.js","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mCAAkC;AAClC,0CAAyC;AACzC,iCAAgC;AAChC,8CAA6C;AAC7C,6BAA4B;AAC5B,+CAAuC;AACvC,mCAAoE;AACpE,6CAA4D;AAC5D,iDAAgD;AAChD,6CAA4C;AAC5C,yCAAwC;AACxC,qCAAiD;AACjD,mCAAkC;AAClC,yCAAwC;AACxC,+CAA6C;AAE7C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;AAClD,MAAM,MAAM,GAAG,mBAAU,EAAE,CAAA;AAC3B,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM,CAAC,cAAc,IAAI,IAAI,CAAA;AAE9D,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,CAAA;AAC3B,OAAO,CAAC,GA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AAG,CAAC,CAAC;SACrC;QAED,IAAI,CAAC,MAAM;YAAE,OAAO,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;QAC7D,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE;YAC3B,IAAI,GAAG;gBAAE,MAAM,GAAG,CAAC;YACnB,+BAA+B;YAC/B,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,GAAG,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;QAEH,oBAAoB;QACpB,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;YACnB,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACrB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;YACtB,OAAO,EAAE,CAAA;SACT;aAAM;YACN,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,UAAgB,GAAG,EAAE,GAAG;;oBAC3C,MAAM,EAAE,GAAG,MAAM,eAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;oBACnC,IAAI,EAAE,EAAE;wBACP,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;wBACjC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;wBACrB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;wBACtB,OAAO,EAAE,CAAA;qBACT;gBACF,CAAC;aAAA,CAAC,CAAA;SACF;IAEF,CAAC,CAAA,CAAC,CAAA;AACH,CAAC"}

9
dist/src/controllers/contacts.js

@ -112,6 +112,7 @@ exports.updateContact = (req, res) => __awaiter(void 0, void 0, void 0, function
contactIds: contactIds,
sender: owner,
type: constants_1.default.message_types.contact_key,
dontActuallySendContactKey: !contactKeyChanged
});
});
exports.exchangeKeys = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
@ -210,10 +211,10 @@ exports.receiveContactKey = (payload) => __awaiter(void 0, void 0, void 0, funct
}
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants_1.default.contact_statuses.confirmed } });
let contactKeyChanged = true; // ???????
let msgIncludedContactKey = false; // ???????
if (sender_contact_key && sender) {
if (sender_contact_key !== sender.contactKey) {
contactKeyChanged = true;
msgIncludedContactKey = true;
}
const objToUpdate = { contactKey: sender_contact_key };
if (sender_alias)
@ -229,9 +230,9 @@ exports.receiveContactKey = (payload) => __awaiter(void 0, void 0, void 0, funct
else {
console.log("DID NOT FIND SENDER");
}
if (contactKeyChanged) {
if (msgIncludedContactKey && sender) {
helpers.sendContactKeys({
contactPubKey: sender_pub_key,
contactIds: [sender.id],
sender: owner,
type: constants_1.default.message_types.contact_key_confirmation,
});

2
dist/src/controllers/contacts.js.map

File diff suppressed because one or more lines are too long

28
dist/src/helpers.js

@ -41,26 +41,20 @@ exports.findOrCreateChat = (params) => __awaiter(void 0, void 0, void 0, functio
}
return chat;
});
exports.sendContactKeys = (args) => __awaiter(void 0, void 0, void 0, function* () {
const { type, contactIds, contactPubKey, sender, success, failure } = args;
const msg = newkeyexchangemsg(type, sender);
exports.sendContactKeys = ({ type, contactIds, sender, success, failure, dontActuallySendContactKey }) => __awaiter(void 0, void 0, void 0, function* () {
const msg = newkeyexchangemsg(type, sender, dontActuallySendContactKey || false);
let yes = null;
let no = null;
let cids = contactIds;
if (!contactIds)
cids = [null]; // nully
let cids = contactIds || [];
yield asyncForEach(cids, (contactId) => __awaiter(void 0, void 0, void 0, function* () {
let destination_key;
if (!contactId) { // nully
destination_key = contactPubKey;
}
else {
if (contactId == sender.id) {
return;
}
const contact = yield models_1.models.Contact.findOne({ where: { id: contactId } });
destination_key = contact.publicKey;
if (contactId == sender.id) {
return;
}
const contact = yield models_1.models.Contact.findOne({ where: { id: contactId } });
if (!(contact && contact.publicKey))
return;
destination_key = contact.publicKey;
exports.performKeysendMessage({
sender,
destination_key,
@ -201,11 +195,11 @@ function asyncForEach(array, callback) {
}
});
}
function newkeyexchangemsg(type, sender) {
function newkeyexchangemsg(type, sender, dontActuallySendContactKey) {
const includePhotoUrl = sender && sender.photoUrl && !sender.privatePhoto;
return {
type: type,
sender: Object.assign(Object.assign({ pub_key: sender.publicKey, contact_key: sender.contactKey }, sender.alias && { alias: sender.alias }), includePhotoUrl && { photo_url: sender.photoUrl })
sender: Object.assign(Object.assign(Object.assign({ pub_key: sender.publicKey }, !dontActuallySendContactKey && { contact_key: sender.contactKey }), sender.alias && { alias: sender.alias }), includePhotoUrl && { photo_url: sender.photoUrl })
};
}
//# sourceMappingURL=helpers.js.map

2
dist/src/helpers.js.map

File diff suppressed because one or more lines are too long

9
src/controllers/contacts.ts

@ -116,6 +116,7 @@ export const updateContact = async (req, res) => {
contactIds: contactIds,
sender: owner,
type: constants.message_types.contact_key,
dontActuallySendContactKey: !contactKeyChanged
})
}
@ -232,10 +233,10 @@ export const receiveContactKey = async (payload) => {
const owner = await models.Contact.findOne({ where: { isOwner: true } })
const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants.contact_statuses.confirmed } })
let contactKeyChanged = true // ???????
let msgIncludedContactKey = false // ???????
if (sender_contact_key && sender) {
if (sender_contact_key !== sender.contactKey) {
contactKeyChanged = true
msgIncludedContactKey = true
}
const objToUpdate: { [k: string]: any } = { contactKey: sender_contact_key }
if (sender_alias) objToUpdate.alias = sender_alias
@ -250,9 +251,9 @@ export const receiveContactKey = async (payload) => {
console.log("DID NOT FIND SENDER")
}
if (contactKeyChanged) {
if (msgIncludedContactKey && sender) {
helpers.sendContactKeys({
contactPubKey: sender_pub_key,
contactIds: [sender.id],
sender: owner,
type: constants.message_types.contact_key_confirmation,
})

25
src/helpers.ts

@ -34,26 +34,21 @@ export const findOrCreateChat = async (params) => {
return chat
}
export const sendContactKeys = async (args) => {
const { type, contactIds, contactPubKey, sender, success, failure } = args
const msg = newkeyexchangemsg(type, sender)
export const sendContactKeys = async ({ type, contactIds, sender, success, failure, dontActuallySendContactKey }:{type:number,contactIds:number[],sender:any,success?:Function,failure?:Function,dontActuallySendContactKey?:boolean}) => {
const msg = newkeyexchangemsg(type, sender, dontActuallySendContactKey||false)
let yes: any = null
let no: any = null
let cids = contactIds
let cids = contactIds || []
if (!contactIds) cids = [null] // nully
await asyncForEach(cids, async contactId => {
let destination_key: string
if (!contactId) { // nully
destination_key = contactPubKey
} else {
if (contactId == sender.id) {
return
}
const contact = await models.Contact.findOne({ where: { id: contactId } })
destination_key = contact.publicKey
if (contactId == sender.id) {
return
}
const contact = await models.Contact.findOne({ where: { id: contactId } })
if(!(contact && contact.publicKey)) return
destination_key = contact.publicKey
performKeysendMessage({
sender,
destination_key,
@ -187,13 +182,13 @@ async function asyncForEach(array, callback) {
}
}
function newkeyexchangemsg(type, sender) {
function newkeyexchangemsg(type, sender, dontActuallySendContactKey) {
const includePhotoUrl = sender && sender.photoUrl && !sender.privatePhoto
return {
type: type,
sender: {
pub_key: sender.publicKey,
contact_key: sender.contactKey,
...!dontActuallySendContactKey && {contact_key: sender.contactKey},
...sender.alias && { alias: sender.alias },
...includePhotoUrl && { photo_url: sender.photoUrl }
}

Loading…
Cancel
Save