From 43115476f8448c744f437155397d6573382195f2 Mon Sep 17 00:00:00 2001 From: cheetah Date: Sun, 13 Nov 2022 23:39:09 +0000 Subject: [PATCH] added boskrypt support for 2 connectors --- types/connectors/eCityrufConnector.js | 18 +++++++++++++++++- types/connectors/eMessageConnector.js | 15 ++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/types/connectors/eCityrufConnector.js b/types/connectors/eCityrufConnector.js index c9dcbf9..c6c9517 100644 --- a/types/connectors/eCityrufConnector.js +++ b/types/connectors/eCityrufConnector.js @@ -1,5 +1,6 @@ const Connector = require("./Connector") const config = require('../../config.json') +const boskrypt = require('../../boskrypt') const md5 = require('md5') const axios = require('axios') // [ "ecityruf", "123456789" ] @@ -13,13 +14,28 @@ class eCityrufConnector extends Connector { async transmitMessage(msg, params) { const UUID = this.name+':'+md5(JSON.stringify([this.name,...params])) if (params.length !== 1) return false + + + const $device = msg.routingParams.device + let payloadBuffer = Buffer.from(msg.payload) + const boskryptSupport = require("../DeviceRegistry").Devices[ $device ].supportBOSkrypt || false + if (boskryptSupport && !!config.pagers[ $device ] && config.pagers[ $device ].boskrypt.enabled) { + //payloadBuffer + const keyTable = config.pagers[ $device ].boskrypt.keys + const FunkrufNummer = "em-"+params[ 0 ] + if (!!keyTable[ FunkrufNummer ]) { + payloadBuffer = Buffer.from(boskrypt.encrypt(payloadBuffer, keyTable[ FunkrufNummer ], 0)) + } + } + + const cityrufRequest = require('querystring').stringify({ service: 1, class: 7, language: 'en', action: 'SendMessage', number: params[ 0 ], - message: msg.payload, + message: payloadBuffer.toString('ascii'), lengthAlert: '', }) console.log(cityrufRequest) diff --git a/types/connectors/eMessageConnector.js b/types/connectors/eMessageConnector.js index 80b00d9..a1c5280 100644 --- a/types/connectors/eMessageConnector.js +++ b/types/connectors/eMessageConnector.js @@ -17,6 +17,19 @@ class eCityrufConnector extends Connector { const serviceName = target.split('#')[ 0 ], identifier = target.split('#')[ 1 ] // eCityruf#8907737 + const $device = msg.routingParams.device + let payloadBuffer = Buffer.from(msg.payload) + const boskryptSupport = require("../DeviceRegistry").Devices[ $device ].supportBOSkrypt || false + if (boskryptSupport && !!config.pagers[ $device ] && config.pagers[ $device ].boskrypt.enabled) { + //payloadBuffer + const keyTable = config.pagers[ $device ].boskrypt.keys + const FunkrufNummer = "em-"+identifier + if (!!keyTable[ FunkrufNummer ]) { + payloadBuffer = Buffer.from(boskrypt.encrypt(payloadBuffer, keyTable[ FunkrufNummer ], 0)) + } + } + + let jwtToken = '', msgTrackID = '' // login axios.post('https://api.emessage.de/auth/login', { @@ -30,7 +43,7 @@ class eCityrufConnector extends Connector { }) .then(() => { // send Message Request return axios.post('https://api.emessage.de/rs/eSendMessages', { - messageText: msg.payload, + messageText: payloadBuffer.toString('ascii'), recipients: [{ serviceName, identifier }] }, { headers: {