moved l-a-s in here
This commit is contained in:
parent
1e3e55e362
commit
836ab07776
18 changed files with 3946 additions and 281 deletions
32
lib/admin/pairing.js
Normal file
32
lib/admin/pairing.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
const fs = require('fs')
|
||||
const pify = require('pify')
|
||||
const readFile = pify(fs.readFile)
|
||||
const crypto = require('crypto')
|
||||
|
||||
const options = require('../options')
|
||||
const db = require('../db')
|
||||
|
||||
function unpair (deviceId) {
|
||||
const sql = 'update devices set paired=FALSE where device_id=$1'
|
||||
|
||||
return db.none(sql, [deviceId])
|
||||
}
|
||||
|
||||
function totem (hostname, name) {
|
||||
const caPath = options.caPath
|
||||
|
||||
return readFile(caPath)
|
||||
.then(data => {
|
||||
const caHash = crypto.createHash('sha256').update(data).digest()
|
||||
const token = crypto.randomBytes(32)
|
||||
const hexToken = token.toString('hex')
|
||||
const caHexToken = crypto.createHash('sha256').update(hexToken).digest('hex')
|
||||
const buf = Buffer.concat([caHash, token, Buffer.from(hostname)])
|
||||
const sql = 'insert into pairing_tokens (token, name) values ($1, $3), ($2, $3)'
|
||||
|
||||
return db.none(sql, [hexToken, caHexToken, name])
|
||||
.then(() => buf.toString('base64'))
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {totem, unpair}
|
||||
Loading…
Add table
Add a link
Reference in a new issue