diff --git a/src/index.ts b/src/index.ts index 12bf1fc..ee51c81 100755 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,7 @@ import * as fs from 'fs-extra'; import * as path from 'path'; import { createA } from './utils/a'; -import { port } from './config'; +import { port, gpgSigningKey } from './config'; import driver from './db/driver'; import store from './files/store'; import appRouter from './rest/app'; @@ -106,6 +106,13 @@ d('Setting up server'); d(err); return; } + d('Initializing public GPG key'); + await store.putFile( + 'public.key', + Buffer.from(gpgSigningKey.split('-----BEGIN PGP PRIVATE KEY BLOCK-----')[0]), + true, + ); + d('GPG key now public at:', `${await store.getPublicBaseUrl()}/public.key`); app.listen(port, () => { d('Nucleus Server started on port:', port); }); diff --git a/src/rest/app.ts b/src/rest/app.ts index 2271b72..b08bf08 100755 --- a/src/rest/app.ts +++ b/src/rest/app.ts @@ -69,14 +69,19 @@ router.get('/', requireLogin, a(async (req, res) => { res.json(onlyPermission(req, sortApps(await driver.getApps()))); })); +const MAGIC_NAMES = [ + '__healthcheck', + 'public.key', +]; + router.post('/', requireLogin, a(async (req, res) => { if (checkField(req, res, 'name')) { // It's unlikely but let's not shoot ourselves in the foot // In the healthcheck we use __healthcheck as a magic file to // ensure that the file store is alive and working. // We need to disallow that app name from being created - if (req.body.name === '__healthcheck') { - return res.status(400).json({ error: 'You can not call your application __healthcheck' }); + if (MAGIC_NAMES.includes(req.body.name)) { + return res.status(400).json({ error: `You can not call your application ${req.body.name}` }); } if (req.files && req.files.icon) { diff --git a/tsconfig.json b/tsconfig.json index f9ea67f..87fca91 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,8 @@ "outDir": "lib", "lib": [ "es6", - "dom" + "dom", + "es7" ], "sourceMap": true, "rootDir": "src",