user rsa key for federation
This commit is contained in:
@@ -25,10 +25,14 @@ html, body {
|
||||
// }
|
||||
|
||||
.el-card {
|
||||
max-width: 670px;
|
||||
max-width: 630px;
|
||||
margin: 30px auto;
|
||||
}
|
||||
|
||||
#admin.el-card {
|
||||
max-width: 850px;
|
||||
}
|
||||
|
||||
.el-dialog {
|
||||
margin-top: 0px !important;
|
||||
border-radius: 0px;
|
||||
|
||||
@@ -6,6 +6,8 @@ div
|
||||
template(slot='title')
|
||||
h4 <v-icon name='plus'/> {{$t('common.new_user')}}
|
||||
el-form(inline)
|
||||
el-form-item(:label="$t('common.username')")
|
||||
el-input(v-model='new_user.username')
|
||||
el-form-item(:label="$t('common.email')")
|
||||
el-input(v-model='new_user.email')
|
||||
el-form-item(:label="$t('common.admin')")
|
||||
@@ -14,23 +16,26 @@ div
|
||||
|
||||
//- USERS LIST
|
||||
el-table(:data='paginatedUsers' small)
|
||||
el-table-column(label='Username')
|
||||
template(slot-scope='data')
|
||||
span(slot='reference') {{data.row.username}}
|
||||
el-table-column(label='Email')
|
||||
template(slot-scope='data')
|
||||
el-popover(trigger='hover' :content='data.row.description' width='400')
|
||||
span(slot='reference') {{data.row.email}}
|
||||
|
||||
el-table-column(:label="$t('common.actions')")
|
||||
template(slot-scope='data')
|
||||
div(v-if='data.row.id!==$auth.user.id')
|
||||
el-button.mr-1(size='mini'
|
||||
:type='data.row.is_active?"warning":"success"'
|
||||
@click='toggle(data.row)') {{data.row.is_active?$t('common.deactivate'):$t('common.activate')}}
|
||||
el-button(size='mini'
|
||||
:type='data.row.is_admin?"danger":"warning"'
|
||||
@click='toggleAdmin(data.row)') {{data.row.is_admin?$t('admin.remove_admin'):$t('common.admin')}}
|
||||
el-button(size='mini'
|
||||
type='danger'
|
||||
@click='delete_user(data.row)') {{$t('admin.delete_user')}}
|
||||
el-button-group
|
||||
el-button(size='mini'
|
||||
:type='data.row.is_active?"warning":"success"'
|
||||
@click='toggle(data.row)') {{data.row.is_active?$t('common.deactivate'):$t('common.activate')}}
|
||||
el-button(size='mini'
|
||||
:type='data.row.is_admin?"danger":"warning"'
|
||||
@click='toggleAdmin(data.row)') {{data.row.is_admin?$t('admin.remove_admin'):$t('common.admin')}}
|
||||
el-button(size='mini'
|
||||
type='danger'
|
||||
@click='delete_user(data.row)') {{$t('admin.delete_user')}}
|
||||
div(v-else)
|
||||
span {{$t('common.me')}}
|
||||
|
||||
|
||||
@@ -48,7 +48,8 @@ export default {
|
||||
enable: 'Abilita',
|
||||
disable: 'Disabilita',
|
||||
me: 'Sei te',
|
||||
password_updated: 'Password modificata!'
|
||||
password_updated: 'Password modificata!',
|
||||
username: 'Nickname'
|
||||
},
|
||||
|
||||
login: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template lang="pug">
|
||||
el-card
|
||||
el-card#admin
|
||||
nuxt-link.float-right(to='/')
|
||||
v-icon(name='times' color='red')
|
||||
h5 {{$t('common.admin')}}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
'use strict'
|
||||
const bcrypt = require('bcryptjs')
|
||||
const crypto = require('crypto')
|
||||
const util = require('util')
|
||||
|
||||
const generateKeyPair = util.promisify(crypto.generateKeyPair)
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const user = sequelize.define('user', {
|
||||
@@ -20,7 +24,8 @@ module.exports = (sequelize, DataTypes) => {
|
||||
password: DataTypes.STRING,
|
||||
recover_code: DataTypes.STRING,
|
||||
is_admin: DataTypes.BOOLEAN,
|
||||
is_active: DataTypes.BOOLEAN
|
||||
is_active: DataTypes.BOOLEAN,
|
||||
rsa: DataTypes.JSONB
|
||||
}, {
|
||||
scopes: {
|
||||
withoutPassword: {
|
||||
@@ -48,5 +53,22 @@ module.exports = (sequelize, DataTypes) => {
|
||||
}
|
||||
})
|
||||
|
||||
user.beforeCreate(async (user, options) => {
|
||||
// generate rsa keys
|
||||
console.error('generate rsa key')
|
||||
const rsa = await generateKeyPair('rsa', {
|
||||
modulusLength: 4096,
|
||||
publicKeyEncoding: {
|
||||
type: 'spki',
|
||||
format: 'pem'
|
||||
},
|
||||
privateKeyEncoding: {
|
||||
type: 'pkcs8',
|
||||
format: 'pem'
|
||||
}
|
||||
})
|
||||
user.rsa = rsa
|
||||
})
|
||||
|
||||
return user
|
||||
};
|
||||
|
||||
@@ -8,7 +8,6 @@ router.get('/u/:name', async (req, res) => {
|
||||
if (!name) return res.status(400).send('Bad request.')
|
||||
const user = await User.findOne({where: { username: name }})
|
||||
if (!user) return res.status(404).send(`No record found for ${name}`)
|
||||
const domain = 'local'
|
||||
const ret = {
|
||||
'@context': [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
@@ -22,7 +21,7 @@ router.get('/u/:name', async (req, res) => {
|
||||
'publicKey': {
|
||||
'id': `${config.baseurl}/federation/u/${name}#main-key`,
|
||||
'owner': `${config.baseurl}/federation/u/${name}`,
|
||||
'publicKeyPem': user.pubkey
|
||||
'publicKeyPem': user.rsa.publicKey
|
||||
}
|
||||
}
|
||||
res.json(ret)
|
||||
|
||||
26
server/migrations/20190729103119-add_rsa.js
Normal file
26
server/migrations/20190729103119-add_rsa.js
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.addColumn('users', 'rsa', {
|
||||
type: Sequelize.JSONB
|
||||
})
|
||||
/*
|
||||
Add altering commands here.
|
||||
Return a promise to correctly handle asynchronicity.
|
||||
|
||||
Example:
|
||||
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
|
||||
*/
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
/*
|
||||
Add reverting commands here.
|
||||
Return a promise to correctly handle asynchronicity.
|
||||
|
||||
Example:
|
||||
return queryInterface.dropTable('users');
|
||||
*/
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user