Merge pull request #418 from shocknet/bug/bad-mac-logs
bug/bad-mac-logs
This commit is contained in:
commit
6de0adb7bd
1 changed files with 36 additions and 16 deletions
|
|
@ -40,21 +40,35 @@ const isEncryptedMessage = message =>
|
||||||
* @param {string} deviceId
|
* @param {string} deviceId
|
||||||
*/
|
*/
|
||||||
const generateKeyPair = deviceId => {
|
const generateKeyPair = deviceId => {
|
||||||
const privateKey = ECCrypto.generatePrivate()
|
try {
|
||||||
const publicKey = ECCrypto.getPublic(privateKey)
|
const privateKey = ECCrypto.generatePrivate()
|
||||||
const privateKeyBase64 = convertBufferToBase64(privateKey)
|
const publicKey = ECCrypto.getPublic(privateKey)
|
||||||
const publicKeyBase64 = convertBufferToBase64(publicKey)
|
const privateKeyBase64 = convertBufferToBase64(privateKey)
|
||||||
|
const publicKeyBase64 = convertBufferToBase64(publicKey)
|
||||||
|
|
||||||
nodeKeyPairs.set(deviceId, {
|
if (!Buffer.isBuffer(privateKey) || !Buffer.isBuffer(publicKey)) {
|
||||||
privateKey,
|
throw new Error('Invalid KeyPair Generated')
|
||||||
publicKey
|
}
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
nodeKeyPairs.set(deviceId, {
|
||||||
privateKey,
|
privateKey,
|
||||||
publicKey,
|
publicKey
|
||||||
privateKeyBase64,
|
})
|
||||||
publicKeyBase64
|
|
||||||
|
return {
|
||||||
|
privateKey,
|
||||||
|
publicKey,
|
||||||
|
privateKeyBase64,
|
||||||
|
publicKeyBase64
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(
|
||||||
|
'[ENCRYPTION] An error has occurred while generating a new KeyPair',
|
||||||
|
err
|
||||||
|
)
|
||||||
|
logger.error('Device ID:', deviceId)
|
||||||
|
|
||||||
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,9 +134,8 @@ const encryptMessage = async ({ message = '', deviceId }) => {
|
||||||
* @param {{ encryptedMessage: EncryptedMessage, deviceId: string }} arg0
|
* @param {{ encryptedMessage: EncryptedMessage, deviceId: string }} arg0
|
||||||
*/
|
*/
|
||||||
const decryptMessage = async ({ encryptedMessage, deviceId }) => {
|
const decryptMessage = async ({ encryptedMessage, deviceId }) => {
|
||||||
|
const keyPair = nodeKeyPairs.get(deviceId)
|
||||||
try {
|
try {
|
||||||
const keyPair = nodeKeyPairs.get(deviceId)
|
|
||||||
|
|
||||||
if (!keyPair) {
|
if (!keyPair) {
|
||||||
throw new FieldError({
|
throw new FieldError({
|
||||||
field: 'deviceId',
|
field: 'deviceId',
|
||||||
|
|
@ -138,7 +151,14 @@ const decryptMessage = async ({ encryptedMessage, deviceId }) => {
|
||||||
const parsedMessage = decryptedMessage.toString('utf8')
|
const parsedMessage = decryptedMessage.toString('utf8')
|
||||||
return parsedMessage
|
return parsedMessage
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err)
|
if (err.message?.toLowerCase() === 'bad mac') {
|
||||||
|
logger.error(
|
||||||
|
'Bad Mac!',
|
||||||
|
err,
|
||||||
|
convertToEncryptedMessage(encryptedMessage),
|
||||||
|
!!keyPair
|
||||||
|
)
|
||||||
|
}
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue