summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudius2019-05-13 12:55:03 +0200
committerClaudius2019-05-13 19:37:21 +0200
commit4833f300c527b96cc5d6d16c605df8cf04d06c1d (patch)
treebd7e65d1ebf0edf41cd5de625a0f7fef79a3b8f7
parent1d403e183d50001bf0f20113d15994007b14696b (diff)
polyfilling scrypt for node 8.5+
Signed-off-by: Claudius <opensource@amenthes.de>
-rw-r--r--lib/models/user.js17
-rw-r--r--package.json1
-rw-r--r--test/user.js2
3 files changed, 15 insertions, 5 deletions
diff --git a/lib/models/user.js b/lib/models/user.js
index 8da12b83..76e20a32 100644
--- a/lib/models/user.js
+++ b/lib/models/user.js
@@ -1,11 +1,20 @@
'use strict'
// external modules
-var Sequelize = require('sequelize')
-var scrypt = require('scrypt-kdf')
+const Sequelize = require('sequelize')
+const crypto = require('crypto')
+if (!crypto.scrypt) {
+ // polyfill for node.js 8.0, see https://github.com/chrisveness/scrypt-kdf#openssl-implementation
+ const scryptAsync = require('scrypt-async')
+ crypto.scrypt = function (password, salt, keylen, options, callback) {
+ const opt = Object.assign({}, options, { dkLen: keylen })
+ scryptAsync(password, salt, opt, (derivedKey) => callback(null, Buffer.from(derivedKey)))
+ }
+}
+const scrypt = require('scrypt-kdf')
// core
-var logger = require('../logger')
-var { generateAvatarURL } = require('../letter-avatars')
+const logger = require('../logger')
+const { generateAvatarURL } = require('../letter-avatars')
module.exports = function (sequelize, DataTypes) {
var User = sequelize.define('User', {
diff --git a/package.json b/package.json
index 8cfcfe63..374a047e 100644
--- a/package.json
+++ b/package.json
@@ -110,6 +110,7 @@
"readline-sync": "^1.4.7",
"request": "^2.88.0",
"reveal.js": "~3.7.0",
+ "scrypt-async": "^2.0.1",
"scrypt-kdf": "^2.0.1",
"select2": "^3.5.2-browserify",
"sequelize": "^3.28.0",
diff --git a/test/user.js b/test/user.js
index f2c8a223..38776a8f 100644
--- a/test/user.js
+++ b/test/user.js
@@ -43,9 +43,9 @@ describe('User Sequelize model', function () {
const combinations = [
// ['correct password', 'scrypt syle hash']
['test', '736372797074000e00000008000000018c7b8c1ac273fd339badde759b3efc418bc61b776debd02dfe95989383cf9980ad21d2403dce33f4b551f5e98ce84edb792aee62600b1303ab8d4e6f0a53b0746e73193dbf557b888efc83a2d6a055a9'],
- ['my secret pw', /* different hash! */ '736372797074000f0000000800000001f6083e9593365acd07550f7c72f19973fb7d52c3ef0a78026ff66c48ab14493843c642167b5e6b7f31927e8eeb912bc2639e41955fae15da5099998948cfeacd022f705624931c3b30104e6bb296b805'],
['ohai', '736372797074000e00000008000000010efec4e5ce6a5294491f1b1cccc38d3562f84844b9271aef635f8bc338cf4e0e0bac62ebb11379e85894c1f694e038fc39b087b4fdacd1280b50a7382d7ffbfc82f2190bef70d47708d2a94b75126294'],
['my secret pw', '736372797074000f0000000800000001ffb4cd10a1dfe9e64c1e5416fd6d55b390b6822e78b46fd1f963fe9f317a1e05f9c5fee15e1f618286f4e38b55364ae1e7dc295c9dc33ee0f5712e86afe37e5784ff9c7cf84cf0e631dd11f84f3621e7'],
+ ['my secret pw', /* different hash! */ '736372797074000f0000000800000001f6083e9593365acd07550f7c72f19973fb7d52c3ef0a78026ff66c48ab14493843c642167b5e6b7f31927e8eeb912bc2639e41955fae15da5099998948cfeacd022f705624931c3b30104e6bb296b805'],
['i am so extremely long, it\'s not even funny. Wait, you\'re still reading?', '736372797074000f00000008000000012d205f7bb529bb3a8b8bb25f5ab46197c7e9baf1aad64cf5e7b2584c84748cacf5e60631d58d21cb51fa34ea93b517e2fe2eb722931db5a70ff5a1330d821288ee7380c4136369f064b71b191a785a5b']
]
const intentionallyInvalidPassword = 'stuff'