Ind.ie is now Small Technology Foundation.
Commit ea80463e authored by wim-vantomme's avatar wim-vantomme

Added ed25519 sign key-pair generation.

parent db247c3c
// Basic helper functions to directly write stuff to indexedDB through the browserAPI.
// Might be that we need to implement a shim for older browsers (shimIndexedDB)
function callOnStore (dbname, storeName, fn_) {
const indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB
// Open or create the database.
const request = indexedDB.open(dbname, 1)
// Create the schema
request.onupgradeneeded = () => {
let db = request.result
let store = db.createObjectStore(storeName, {keyPath: 'id'})
}
request.onsuccess = () => {
let db = request.result
let transaction = db.transaction(storeName, 'readwrite')
let store = transaction.objectStore(storeName)
fn_(store)
transaction.oncomplete = () => db.close()
}
}
module.exports = {
callOnStore
}
const axios = require('axios')
const sodium = require('libsodium-wrappers')
// Custom modules
const indexedDB = require('./indexedDB')
const form = document.getElementById('register')
function loadedKeyPair () {
indexedDB.callOnStore('testkeystore', 'keyStore', (store) => {
const getData = store.get(1)
getData.onsuccess = (event) => {
const keys = getData.result.keys
}
})
}
//loadedKeyPair()
form.addEventListener('submit', (e) => {
e.preventDefault()
const password = e.target.password.value
const salt = sodium.randombytes_buf(sodium.crypto_pwhash_SALTBYTES)
const keyPair = sodium.crypto_sign_keypair()
console.log(keyPair)
const keyLength = sodium.crypto_pwhash_BYTES_MIN
const opslimit = sodium.crypto_pwhash_OPSLIMIT_MAX
const memlimit = sodium.crypto_pwhash_MEMLIMIT_MAX
const algorithm = sodium.crypto_pwhash_ALG_DEFAULT
const encryptPassword = sodium.crypto_pwhash(keyLength, password, salt, opslimit, memlimit, algorithm)
const encryptedPrivateKey = sodium.crypto_pwhash(keyLength, keyPair.privateKey, encryptPassword, opslimit, memlimit, algorithm)
const postKeys = axios.post('register',
{
salt: salt,
publicKey: keyPair.publicKey,
privateKey: encryptedPrivateKey
})
postKeys.then((values) => {
indexedDB.callOnStore('libsodium_testkeystore', 'keyStore', (store) => {
store.put({
id: 1,
keys: keyPair.privateKey
})
})
}).catch((err) => {
console.log(err)
})
})
var browserify = require('browserify')
var gulp = require('gulp')
var source = require('vinyl-source-stream')
var rename = require('gulp-rename')
var glob = require('glob')
var es = require('event-stream')
gulp.task('js:bundle', function (done) {
glob('./client/**/**.js', function (err, files) {
if (err) done(err)
var tasks = files.map(function (entry) {
return browserify({ entries: [entry] })
.bundle()
.pipe(source(entry))
.pipe(rename({
dirname: ''
}))
.pipe(gulp.dest('./public/js'))
})
es.merge(tasks).on('end', done)
})
})
gulp.task('watch', () =>
gulp.watch('./client/**/*.js', ['js:bundle'])
)
......@@ -382,6 +382,15 @@
"integrity": "sha1-g+9cqGCysy5KDe7e6MdxudtXRx4=",
"dev": true
},
"axios": {
"version": "0.17.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.17.1.tgz",
"integrity": "sha1-LY4+XQvb1zJ/kbyBT1xXZg+Bgk0=",
"requires": {
"follow-redirects": "1.4.0",
"is-buffer": "1.1.6"
}
},
"babel-code-frame": {
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz",
......@@ -2448,6 +2457,14 @@
"write": "0.2.1"
}
},
"follow-redirects": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.4.0.tgz",
"integrity": "sha512-SLUmsiaGeQa2qgJJzJgHpQ6lARP3uyVr0SkMryJmoE86XvUeM7RkYD5FT0rNyjCV5zHlNUpcp3l/6oUkqMEOqg==",
"requires": {
"debug": "3.1.0"
}
},
"for-in": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
......@@ -3322,8 +3339,7 @@
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==",
"dev": true
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
},
"is-callable": {
"version": "1.1.3",
......@@ -3699,8 +3715,15 @@
"libsodium": {
"version": "0.7.3",
"resolved": "https://registry.npmjs.org/libsodium/-/libsodium-0.7.3.tgz",
"integrity": "sha512-ld+deUNqSsZYbAobUs63UyduPq8ICp/Ul/5lbvBIYpuSNWpPRU0PIxbW+xXipVZtuopR6fIz9e0tTnNuPMNeqw==",
"dev": true
"integrity": "sha512-ld+deUNqSsZYbAobUs63UyduPq8ICp/Ul/5lbvBIYpuSNWpPRU0PIxbW+xXipVZtuopR6fIz9e0tTnNuPMNeqw=="
},
"libsodium-wrappers": {
"version": "0.7.3",
"resolved": "https://registry.npmjs.org/libsodium-wrappers/-/libsodium-wrappers-0.7.3.tgz",
"integrity": "sha512-dw5Jh6TZ5qc5rQVZe3JrSO/J05CE+DmAPnqD7Q2glBUE969xZ6o3fchnUxyPlp6ss3x0MFxmdJntveFN+XTg1g==",
"requires": {
"libsodium": "0.7.3"
}
},
"liftoff": {
"version": "2.5.0",
......
......@@ -31,7 +31,7 @@
"scripts": {
"test": "npm run eslint && npm run mocha",
"start": "node server/",
"watch": "nodemon server/",
"watch": "nodemon server",
"mocha": "mocha test/ --recursive --exit"
},
"dependencies": {
......@@ -40,9 +40,11 @@
"@feathersjs/express": "^1.1.2",
"@feathersjs/feathers": "^3.0.5",
"@feathersjs/socketio": "^3.0.2",
"axios": "^0.17.1",
"compression": "^1.7.1",
"cors": "^2.8.4",
"helmet": "^3.9.0",
"libsodium-wrappers": "^0.7.3",
"serve-favicon": "^2.4.5",
"winston": "^2.4.0"
},
......@@ -52,7 +54,6 @@
"glob": "^7.1.2",
"gulp": "^3.9.1",
"gulp-rename": "^1.2.2",
"libsodium": "^0.7.3",
"mocha": "^5.0.0",
"request": "^2.83.0",
"request-promise": "^4.2.2",
......
This diff is collapsed.
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
// Basic helper functions to directly write stuff to indexedDB through the browserAPI.
// Might be that we need to implement a shim for older browsers (shimIndexedDB)
function callOnStore (dbname, storeName, fn_) {
const indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB
// Open or create the database.
const request = indexedDB.open(dbname, 1)
// Create the schema
request.onupgradeneeded = () => {
let db = request.result
let store = db.createObjectStore(storeName, {keyPath: 'id'})
}
request.onsuccess = () => {
let db = request.result
let transaction = db.transaction(storeName, 'readwrite')
let store = transaction.objectStore(storeName)
fn_(store)
transaction.oncomplete = () => db.close()
}
}
module.exports = {
callOnStore
}
},{}]},{},[1]);
This diff is collapsed.
const path = require('path');
const favicon = require('serve-favicon');
const compress = require('compression');
const cors = require('cors');
const helmet = require('helmet');
const logger = require('winston');
const path = require('path')
const favicon = require('serve-favicon')
const compress = require('compression')
const cors = require('cors')
const helmet = require('helmet')
const logger = require('winston')
const feathers = require('@feathersjs/feathers');
const configuration = require('@feathersjs/configuration');
const express = require('@feathersjs/express');
const socketio = require('@feathersjs/socketio');
const feathers = require('@feathersjs/feathers')
const configuration = require('@feathersjs/configuration')
const express = require('@feathersjs/express')
const socketio = require('@feathersjs/socketio')
const middleware = require('./middleware')
const services = require('./services')
const appHooks = require('./app.hooks')
const channels = require('./channels')
const middleware = require('./middleware');
const services = require('./services');
const appHooks = require('./app.hooks');
const channels = require('./channels');
const app = express(feathers());
const app = express(feathers())
// Load app configuration
app.configure(configuration());
app.configure(configuration())
// Enable CORS, security, compression, favicon and body parsing
app.use(cors());
app.use(helmet());
app.use(compress());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(favicon(path.join(app.get('public'), 'favicon.ico')));
app.use(cors())
app.use(helmet())
app.use(compress())
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(favicon(path.join(app.get('public'), 'favicon.ico')))
// Host the public folder
app.use('/', express.static(app.get('public')));
app.use('/', express.static(app.get('public')))
// Set up Plugins and providers
app.configure(express.rest());
app.configure(socketio());
app.configure(express.rest())
app.configure(socketio())
// Configure other middleware (see `middleware/index.js`)
app.configure(middleware);
app.configure(middleware)
// Set up our services (see `services/index.js`)
app.configure(services);
app.configure(services)
// Set up event channels (see channels.js)
app.configure(channels);
app.configure(channels)
// Configure a middleware for 404s and the error handler
app.use(express.notFound());
app.use(express.errorHandler({ logger }));
app.use(express.notFound())
app.use(express.errorHandler({ logger }))
app.hooks(appHooks);
app.hooks(appHooks)
module.exports = app;
module.exports = app
module.exports = function(app) {
if(typeof app.channel !== 'function') {
module.exports = function (app) {
if (typeof app.channel !== 'function') {
// If no real-time functionality has been configured just return
return;
return
}
app.on('connection', connection => {
// On a new real-time connection, add it to the anonymous channel
app.channel('anonymous').join(connection);
});
app.channel('anonymous').join(connection)
})
app.on('login', (authResult, { connection }) => {
// connection can be undefined if there is no
// real-time connection, e.g. when logging in via REST
if(connection) {
if (connection) {
// Obtain the logged in user from the connection
// const user = connection.user;
// The connection is no longer anonymous, remove it
app.channel('anonymous').leave(connection);
app.channel('anonymous').leave(connection)
// Add it to the authenticated user channel
app.channel('authenticated').join(connection);
app.channel('authenticated').join(connection)
// Channels can be named anything and joined on any condition
// Channels can be named anything and joined on any condition
// E.g. to send real-time events only to admins use
// if(user.isAdmin) { app.channel('admins').join(connection); }
// If the user has joined e.g. chat rooms
// if(Array.isArray(user.rooms)) user.rooms.forEach(room => app.channel(`rooms/${room.id}`).join(channel));
// Easily organize users by email and userid for things like messaging
// app.channel(`emails/${user.email}`).join(channel);
// app.channel(`userIds/$(user.id}`).join(channel);
}
});
})
app.publish((data, hook) => { // eslint-disable-line no-unused-vars
// Here you can add event publishers to channels set up in `channels.js`
......@@ -43,13 +43,13 @@ module.exports = function(app) {
console.log('Publishing all events to all authenticated users. See `channels.js` and https://docs.feathersjs.com/api/channels.html for more information.'); // eslint-disable-line
// e.g. to publish all service events to all authenticated users use
return app.channel('authenticated');
});
return app.channel('authenticated')
})
// Here you can also add service specific event publishers
// e..g the publish the `users` service `created` event to the `admins` channel
// app.service('users').publish('created', () => app.channel('admins'));
// With the userid and email organization from above you can easily select involved users
// app.service('messages').publish(() => {
// return [
......
/* eslint-disable no-console */
const logger = require('winston');
const app = require('./app');
const port = app.get('port');
const server = app.listen(port);
const logger = require('winston')
const app = require('./app')
const port = app.get('port')
const server = app.listen(port)
process.on('unhandledRejection', (reason, p) =>
logger.error('Unhandled Rejection at: Promise ', p, reason)
);
)
server.on('listening', () =>
logger.info('Feathers application started on http://%s:%d', app.get('host'), port)
);
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment