move to sha-256 fingerprints

This commit is contained in:
Josh Harvey 2017-04-24 14:08:12 +03:00
parent 8674816d27
commit 91e1077daa
4 changed files with 39 additions and 65 deletions

View file

@ -297,9 +297,18 @@ localApp.post('/dbChange', (req, res, next) => {
})
})
function sha256 (buf) {
const crypto = require('crypto')
const hash = crypto.createHash('sha256')
hash.update(buf)
return hash.digest('hex').toString('hex')
}
function populateDeviceId (req, res, next) {
const deviceId = ((typeof req.connection.getPeerCertificate === 'function' &&
req.connection.getPeerCertificate().fingerprint)) || null
const deviceId = _.isFunction(req.connection.getPeerCertificate)
? sha256(req.connection.getPeerCertificate().raw)
: null
req.deviceId = deviceId
req.deviceTime = Date.parse(req.get('date'))