Fixed encryption errors caused by caching

This commit is contained in:
emad-salah 2020-05-13 22:08:38 +00:00 committed by Daniel Lugo
parent 857e61fc23
commit cc03e4acbc
2 changed files with 13 additions and 5 deletions

View file

@ -73,11 +73,11 @@ const server = program => {
} }
const dataHash = hashData(args[0]).slice(-8) const dataHash = hashData(args[0]).slice(-8)
res.set('ETag', dataHash) res.set('shock-cache-hash', dataHash)
logger.debug('ETag:', req.headers.etag) logger.debug('shock-cache-hash:', req.headers['shock-cache-hash'])
logger.debug('Data Hash:', dataHash) logger.debug('Data Hash:', dataHash)
if (req.headers.etag === dataHash) { if (req.headers['shock-cache-hash'] === dataHash) {
logger.debug('Same Hash Detected!') logger.debug('Same Hash Detected!')
args[0] = null args[0] = null
res.status(304) res.status(304)

View file

@ -38,6 +38,7 @@ const Encryption = {
}, },
data data
) )
return encryptedData.toString('base64') return encryptedData.toString('base64')
}, },
/** /**
@ -62,7 +63,7 @@ const Encryption = {
/** /**
* @param {{ deviceId: string , message: any , metadata?: any}} arg0 * @param {{ deviceId: string , message: any , metadata?: any}} arg0
*/ */
encryptMessage: ({ deviceId, message, metadata }) => { encryptMessage: ({ deviceId, message, metadata = {} }) => {
const parsedMessage = const parsedMessage =
typeof message === 'object' ? JSON.stringify(message) : message typeof message === 'object' ? JSON.stringify(message) : message
const data = Buffer.from(parsedMessage) const data = Buffer.from(parsedMessage)
@ -79,7 +80,14 @@ const Encryption = {
Buffer.from(cipher.final()) Buffer.from(cipher.final())
]) ])
const encryptedData = encryptedBuffer.toString('base64') const encryptedData = encryptedBuffer.toString('base64')
return { encryptedData, encryptedKey, iv: iv.toString('hex'), metadata } const encryptedMessage = {
encryptedData,
encryptedKey,
iv: iv.toString('hex'),
metadata
}
return encryptedMessage
}, },
/** /**
* @param {{ message: string , key: string , iv: string }} arg0 * @param {{ message: string , key: string , iv: string }} arg0