From 8795d6f254bd8f88c385bf77b82cc6f177c94df9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 26 Feb 2021 14:22:25 +0100 Subject: Fix broken local actors Some channels can't federate because they don't have public/private keys, maybe because the generation failed for various reasons --- server/initializers/constants.ts | 7 +++-- .../migrations/0605-actor-missing-keys.ts | 34 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 server/initializers/migrations/0605-actor-missing-keys.ts (limited to 'server/initializers') diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index bbf55d7a4..74192d590 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -1,8 +1,8 @@ -import { randomInt } from '../../shared/core-utils/miscs/miscs' import { CronRepeatOptions, EveryRepeatOptions } from 'bull' import { randomBytes } from 'crypto' import { invert } from 'lodash' import { join } from 'path' +import { randomInt } from '../../shared/core-utils/miscs/miscs' import { AbuseState, JobType, @@ -24,7 +24,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 600 +const LAST_MIGRATION_VERSION = 605 // --------------------------------------------------------------------------- @@ -141,6 +141,7 @@ const JOB_ATTEMPTS: { [id in JobType]: number } = { 'video-transcoding': 1, 'video-import': 1, 'email': 5, + 'actor-keys': 3, 'videos-views': 1, 'activitypub-refresher': 1, 'video-redundancy': 1, @@ -153,6 +154,7 @@ const JOB_CONCURRENCY: { [id in JobType]?: number } = { 'activitypub-follow': 1, 'video-file-import': 1, 'email': 5, + 'actor-keys': 1, 'videos-views': 1, 'activitypub-refresher': 1, 'video-redundancy': 1, @@ -167,6 +169,7 @@ const JOB_TTL: { [id in JobType]: number } = { 'video-transcoding': 1000 * 3600 * 48, // 2 days, transcoding could be long 'video-import': 1000 * 3600 * 2, // 2 hours 'email': 60000 * 10, // 10 minutes + 'actor-keys': 60000 * 20, // 20 minutes 'videos-views': undefined, // Unlimited 'activitypub-refresher': 60000 * 10, // 10 minutes 'video-redundancy': 1000 * 3600 * 3, // 3 hours diff --git a/server/initializers/migrations/0605-actor-missing-keys.ts b/server/initializers/migrations/0605-actor-missing-keys.ts new file mode 100644 index 000000000..72d9b359d --- /dev/null +++ b/server/initializers/migrations/0605-actor-missing-keys.ts @@ -0,0 +1,34 @@ +import * as Sequelize from 'sequelize' +import { createPrivateKey, getPublicKey } from '../../helpers/core-utils' +import { PRIVATE_RSA_KEY_SIZE } from '../constants' + +async function up (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize + db: any +}): Promise { + + { + const query = 'SELECT * FROM "actor" WHERE "serverId" IS NULL AND "publicKey" IS NULL' + const options = { type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT } + const actors = await utils.sequelize.query(query, options) + + for (const actor of actors) { + const { key } = await createPrivateKey(PRIVATE_RSA_KEY_SIZE) + const { publicKey } = await getPublicKey(key) + + const queryUpdate = `UPDATE "actor" SET "publicKey" = '${publicKey}', "privateKey" = '${key}' WHERE id = ${actor.id}` + await utils.sequelize.query(queryUpdate) + } + } +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} -- cgit v1.2.3