Merge pull request #940 from chaotixkilla/fix-machine-token-creation

Fix pairing token creation
This commit is contained in:
Rafael Taranto 2021-11-19 09:45:46 +00:00 committed by GitHub
commit ee6d70d6f8

View file

@ -3,7 +3,7 @@ const pify = require('pify')
const readFile = pify(fs.readFile) const readFile = pify(fs.readFile)
const crypto = require('crypto') const crypto = require('crypto')
const baseX = require('base-x') const baseX = require('base-x')
const { NIL } = require('uuid') const { parse, NIL } = require('uuid')
const options = require('../../options') const options = require('../../options')
const db = require('../../db') const db = require('../../db')
@ -16,11 +16,13 @@ const unpair = pairing.unpair
function totem (name) { function totem (name) {
const caPath = options.caPath const caPath = options.caPath
const cleanNil = [...parse(NIL)].map(it => it.toString(16).padStart(2, '0')).join('')
const nilBuffer = Buffer.from(cleanNil, 'hex')
return readFile(caPath) return readFile(caPath)
.then(data => { .then(data => {
const caHash = crypto.createHash('sha256').update(data).digest() const caHash = crypto.createHash('sha256').update(data).digest()
const token = Buffer.concat([crypto.randomBytes(32), NIL]) const token = Buffer.concat([crypto.randomBytes(32), nilBuffer])
const hexToken = token.toString('hex') const hexToken = token.toString('hex')
const caHexToken = crypto.createHash('sha256').update(hexToken).digest('hex') const caHexToken = crypto.createHash('sha256').update(hexToken).digest('hex')
const buf = Buffer.concat([caHash, token, Buffer.from(options.hostname)]) const buf = Buffer.concat([caHash, token, Buffer.from(options.hostname)])