A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
feat(admin): check Bluesky keys on save and show a PEM example
Hampusf6ebf93afd34
diff --git a/fluxer_admin/src/templates/pages/instance_config/integrations.rs b/fluxer_admin/src/templates/pages/instance_config/integrations.rsindex d8902f7f2..8e71b8604 100644--- a/fluxer_admin/src/templates/pages/instance_config/integrations.rs+++ b/fluxer_admin/src/templates/pages/instance_config/integrations.rs@@ -40,6 +40,22 @@ fn password_input(name: &str, label: &str, helper: Option<&str>) -> Markup {)}+const PEM_PLACEHOLDER: &str = "-----BEGIN PRIVATE KEY-----\nMIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg...\n-----END PRIVATE KEY-----";++fn private_key_input(name: &str, label: &str, helper: &str) -> Markup {+ form_field_group(+ label,+ name,+ false,+ None,+ Some(helper),+ html! {+ textarea id=(name) name=(name) rows="5" placeholder=(PEM_PLACEHOLDER) class={(FORM_INPUT_CLASS) " font-mono text-xs"}+ autocomplete="off" spellcheck="false" {}+ },+ )+}+fn smtp_tls_mode_summary(mode: &str) -> &str {match mode {"implicit" => "implicit TLS",@@ -259,7 +275,7 @@ pub(super) fn integrations_config_section("https://example.com/privacy",))(text_input("integration_bluesky_key_id", "New signing key ID", "", "atproto-key-1"))- (password_input("integration_bluesky_private_key", "New private key", Some("Provide this only when adding or replacing runtime Bluesky keys.")))+ (private_key_input("integration_bluesky_private_key", "New private key", "Paste the whole PEM file, including the BEGIN and END lines. Provide this only when adding or replacing runtime Bluesky keys."))}}diff --git a/fluxer_api/src/api/admin/controllers/InstanceConfigAdminController.ts b/fluxer_api/src/api/admin/controllers/InstanceConfigAdminController.tsindex 636e4fbba..51b209b69 100644--- a/fluxer_api/src/api/admin/controllers/InstanceConfigAdminController.ts+++ b/fluxer_api/src/api/admin/controllers/InstanceConfigAdminController.ts@@ -7,6 +7,7 @@ import {startAttachmentDecayReconcile} from '@app/api/attachment/AttachmentDecayimport {maybeAutoJoinInvite} from '@app/api/auth/AuthRegistration';import {ssoDiscoveryCacheKey} from '@app/api/auth/services/SsoService';import {createGuildID, createInviteCode, createUserID} from '@app/api/BrandedTypes';+import {loadSigningKey} from '@app/api/bluesky/BlueskyOAuthService';import {Config} from '@app/api/Config';import {enqueueEndUnassignedGuildVisits} from '@app/api/guild/visits/GuildVisitLifecycle';import {brandingAssetStorageKey, resolveBrandingAsset} from '@app/api/instance/BrandingAssetReferences';@@ -425,6 +426,20 @@ function emailDeliveryPatchField(patch: InstanceIntegrationsConfigPatch['email']return null;}+async function assertValidBlueskyKeys(patch: InstanceIntegrationsConfigPatch | null): Promise<void> {+ for (const [index, key] of (patch?.bluesky?.keys ?? []).entries()) {+ if (!key.kid || !key.private_key) continue;+ try {+ await loadSigningKey({kid: key.kid, private_key: key.private_key}, index);+ } catch {+ throw InputValidationError.create(+ `integrations.bluesky.keys.${index}.private_key`,+ 'The private key must be the whole PEM file, from the BEGIN PRIVATE KEY line to the END PRIVATE KEY line',+ );+ }+ }+}+async function assertConsistentInstanceConfig(data: InstanceConfigUpdateRequest,integrationsPatch: InstanceIntegrationsConfigPatch | null,@@ -880,6 +895,7 @@ export function InstanceConfigAdminController(app: HonoApp) {await assertBillingCompatibleWithPremiumMode(data);const integrationsPatch = toIntegrationsPatch(data.integrations, await readSavedSmtpConfig());await assertConsistentInstanceConfig(data, integrationsPatch);+ await assertValidBlueskyKeys(integrationsPatch);const updateContext = {ctx, data, instanceConfigRepository, integrationsPatch};for (const applySection of Object.values(INSTANCE_CONFIG_SECTION_APPLIERS)) {const pendingUpdate = applySection(updateContext);diff --git a/fluxer_api/src/api/bluesky/BlueskyOAuthService.ts b/fluxer_api/src/api/bluesky/BlueskyOAuthService.tsindex 9450903dc..68a8bc48a 100644--- a/fluxer_api/src/api/bluesky/BlueskyOAuthService.ts+++ b/fluxer_api/src/api/bluesky/BlueskyOAuthService.ts@@ -76,7 +76,7 @@ interface BlueskyClientSession {sessionStore: NodeSavedSessionStore;}-async function loadSigningKey(config: BlueskyOAuthKeyConfig, index: number): Promise<JoseKey> {+export async function loadSigningKey(config: BlueskyOAuthKeyConfig, index: number): Promise<JoseKey> {const field = `Bluesky OAuth keys[${index}]`;let keyData = config.private_key;if (keyData == null) {