fix: machine pairing token creation
This commit is contained in:
parent
d138b26903
commit
6dee47a171
1 changed files with 4 additions and 2 deletions
|
|
@ -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)])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue