From 6e2f7ab8bd724cec32fb3753554fbc2c97b0747f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 6 Feb 2019 06:08:59 -0500 Subject: [PATCH] Drop unnecessary native module --- package.json | 3 +-- routes/admin.js | 35 ++++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 89b33d2..3c36cbf 100644 --- a/package.json +++ b/package.json @@ -9,11 +9,10 @@ "cors": "^2.8.4", "express": "^4.16.3", "express-basic-auth": "^1.1.5", - "generate-rsa-keypair": "^0.1.2", "request": "^2.87.0" }, "engines": { - "node": ">=10.10.0" + "node": ">=10.12.0" }, "devDependencies": {}, "scripts": { diff --git a/routes/admin.js b/routes/admin.js index 0398389..fa15632 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -1,8 +1,7 @@ 'use strict'; const express = require('express'), router = express.Router(), - crypto = require('crypto'), - generateRSAKeypair = require('generate-rsa-keypair'); + crypto = require('crypto'); function createActor(name, domain, pubkey) { return { @@ -48,17 +47,27 @@ router.post('/create', function (req, res) { let db = req.app.get('db'); let domain = req.app.get('domain'); // create keypair - var pair = generateRSAKeypair(); - let actorRecord = createActor(account, domain, pair.public); - let webfingerRecord = createWebfinger(account, domain); - const apikey = crypto.randomBytes(16).toString('hex'); - try { - db.prepare('insert or replace into accounts(name, actor, apikey, pubkey, privkey, webfinger) values(?, ?, ?, ?, ?, ?)').run(`${account}@${domain}`, JSON.stringify(actorRecord), apikey, pair.public, pair.private, JSON.stringify(webfingerRecord)); - res.status(200).json({msg: 'ok', apikey}); - } - catch(e) { - res.status(200).json({error: e}); - } + crypto.generateKeyPair('rsa', { + modulusLength: 4096, + publicKeyEncoding: { + type: 'spki', + format: 'pem' + }, + privateKeyEncoding: { + type: 'pkcs8', + format: 'pem' + } + }, (err, publicKey, privateKey) => { + let actorRecord = createActor(account, domain, publicKey); + let webfingerRecord = createWebfinger(account, domain); + const apikey = crypto.randomBytes(16).toString('hex'); + try { + db.prepare('insert or replace into accounts(name, actor, apikey, pubkey, privkey, webfinger) values(?, ?, ?, ?, ?, ?)').run(`${account}@${domain}`, JSON.stringify(actorRecord), apikey, publicKey, privateKey, JSON.stringify(webfingerRecord)); + res.status(200).json({msg: 'ok', apikey}); + } + catch(e) { + res.status(200).json({error: e}); + } }); module.exports = router;