* dev: (39 commits) chore: re-add build files fix: mailgun as default fix: backwards compatibility on cashout fixed fee chore: remove coinbase as a ticker fix: expire temporary cookies on browser close fix: optimize and normalize bills and blacklist chore: data for cypress chore: deprecate old unused tables chore: remove dependency on async local storage fix: proper datetime name chore: remove extra comment chore: update build chore: migrating to nodejs 22 feat: show unpaired device names on transactions chore: deprecate old migrations fix: update yup usage on custom info requests fix: loading svg on usdc chore: lamassu coins version bump chore: lamassu coins bump on admin fix: fee for sweeps ...
27 lines
739 B
JavaScript
27 lines
739 B
JavaScript
const crypto = require('crypto')
|
|
|
|
const IS_STRESS_TESTING = process.env.LAMASSU_STRESS_TESTING === "YES"
|
|
|
|
function sha256 (buf) {
|
|
if (!buf) return null
|
|
const hash = crypto.createHash('sha256')
|
|
|
|
hash.update(buf)
|
|
return hash.digest('hex').toString('hex')
|
|
}
|
|
|
|
const populateDeviceId = function (req, res, next) {
|
|
const peerCert = req.socket.getPeerCertificate ? req.socket.getPeerCertificate() : null
|
|
let deviceId = peerCert?.raw ? sha256(peerCert.raw) : null
|
|
|
|
if (!deviceId && IS_STRESS_TESTING)
|
|
deviceId = req.headers.device_id
|
|
|
|
if (!deviceId) return res.status(500).json({ error: 'Unable to find certificate' })
|
|
req.deviceId = deviceId
|
|
req.deviceTime = req.get('date')
|
|
|
|
next()
|
|
}
|
|
|
|
module.exports = populateDeviceId
|