Skip to content

Commit

Permalink
feat(core-platform): host the public key of the gpg key pair on the f…
Browse files Browse the repository at this point in the history
…ile store
  • Loading branch information
MarshallOfSound committed Mar 26, 2018
1 parent f7da3f3 commit d1c155e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/index.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
});
Expand Down
9 changes: 7 additions & 2 deletions src/rest/app.ts
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Expand Up @@ -5,7 +5,8 @@
"outDir": "lib",
"lib": [
"es6",
"dom"
"dom",
"es7"
],
"sourceMap": true,
"rootDir": "src",
Expand Down

0 comments on commit d1c155e

Please sign in to comment.