Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions apps/server/src/cli/commands/tls.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { AUTO_TLS_LOW_PORT_COMMAND, AUTO_TLS_VALIDATION_PORT, type AutoTlsErrorCode, type AutoTlsStatus } from '@monky/shared';
import { AcmeChallenges, AutoTlsFailure, AutoTlsService, LetsEncryptIssuer, acmeTestOverrides, allowValidationPort } from '@monky/shared/dist/tls';
import { getPublicIp } from '../../infrastructure/discovery/ServerIpScanner';
import { AcmeChallenges } from '../../infrastructure/tls/AcmeChallenges';
import { AutoTlsFailure, AutoTlsService } from '../../infrastructure/tls/AutoTlsService';
import { CertificateStore } from '../../infrastructure/tls/CertificateStore';
import { LetsEncryptIssuer, acmeTestOverrides, allowValidationPort } from '../../infrastructure/tls/LetsEncryptIssuer';
import { serverTlsStorage } from '../../infrastructure/tls/sharedTls';
import { ANSI, color } from '../constants';
import type { GlobalArgs } from '../context';
import { formatDate } from '../formatters';
Expand Down Expand Up @@ -32,10 +30,13 @@ export function describeAutoTlsError(code: AutoTlsErrorCode): string {

/** The service as the CLI runs it: issuing here, serving later in the server process. */
function cliService(dataDir: string): AutoTlsService {
const store = new CertificateStore(dataDir);
const storage = serverTlsStorage(dataDir);
const store = storage.store;
const overrides = acmeTestOverrides();
return new AutoTlsService({
store,
settings: storage.settings,
legacyDirectory: storage.legacyDirectory,
// The server may be running on its own port; the CLI always answers on the validation port itself.
issuer: new LetsEncryptIssuer({
store, challenges: new AcmeChallenges(), serverPort: -1,
Expand Down Expand Up @@ -85,7 +86,7 @@ async function enable(dataDir: string): Promise<void> {
if (!(await confirm(t('tls.askGrant', { port: AUTO_TLS_VALIDATION_PORT, command: AUTO_TLS_LOW_PORT_COMMAND }), true))) throw error;
status = await service.enable({ grantPortPermission: true });
}
console.log(color(t('tls.enabledNow', { address: `wss://${status.ip}` }), ANSI.green));
console.log(color(t(service.reusedSharedCertificate ? 'tls.enabledReused' : 'tls.enabledNow', { address: `wss://${status.ip}` }), ANSI.green));
printStatus(status);
} catch (error) {
if (error instanceof AutoTlsFailure) throw new Error(`${t('tls.notEnabled')} ${describeAutoTlsError(error.code)}`);
Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/cli/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ export const en: CliTranslationMap = {
'tls.checking': 'Asking Let\'s Encrypt for a test certificate to check that port {port} is reachable from the internet. This takes a few seconds...',
'tls.askGrant': 'Linux does not let the server open port {port} without permission. Allow it now with sudo? (runs: {command})',
'tls.enabledNow': 'Secure connection enabled. The server also accepts {address}.',
'tls.enabledReused': 'Secure connection enabled with the certificate already shared on this machine. The server also accepts {address}.',
'tls.notEnabled': 'The secure connection was not enabled.',
'tls.disabledNow': 'Secure connection disabled. The server accepts ws:// only.',
'tls.restartNow': 'The server is running. Restart it now to apply the secure connection?',
Expand All @@ -534,5 +535,5 @@ export const en: CliTranslationMap = {
'tls.error.rateLimited': 'Let\'s Encrypt asked to wait before issuing another certificate. Try again later.',
'tls.error.rejected': 'Let\'s Encrypt refused the request. See the server logs for the reason.',
'tls.error.network': 'Could not reach Let\'s Encrypt. Check the internet connection.',
'tls.error.storage': 'Could not save the certificate in the server\'s data folder.',
'tls.error.storage': 'Could not save the certificate in the shared certificate folder (~/.monky/tls or MONKY_TLS_DIR).',
};
3 changes: 2 additions & 1 deletion apps/server/src/cli/i18n/locales/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ export const ptBR = {
'tls.checking': 'Pedindo à Let\'s Encrypt um certificado de teste para conferir se a porta {port} está acessível pela internet. Isso leva alguns segundos...',
'tls.askGrant': 'O Linux não deixa o servidor abrir a porta {port} sem permissão. Liberar agora com sudo? (executa: {command})',
'tls.enabledNow': 'Conexão segura ativada. O servidor também aceita {address}.',
'tls.enabledReused': 'Conexão segura ativada com o certificado já compartilhado nesta máquina. O servidor também aceita {address}.',
'tls.notEnabled': 'A conexão segura não foi ativada.',
'tls.disabledNow': 'Conexão segura desativada. O servidor aceita apenas ws://.',
'tls.restartNow': 'O servidor está rodando. Reiniciar agora para aplicar a conexão segura?',
Expand All @@ -534,5 +535,5 @@ export const ptBR = {
'tls.error.rateLimited': 'A Let\'s Encrypt pediu para esperar antes de emitir outro certificado. Tente de novo mais tarde.',
'tls.error.rejected': 'A Let\'s Encrypt recusou o pedido. Veja os logs do servidor para o motivo.',
'tls.error.network': 'Não foi possível falar com a Let\'s Encrypt. Confira a conexão com a internet.',
'tls.error.storage': 'Não foi possível gravar o certificado na pasta de dados do servidor.',
'tls.error.storage': 'Não foi possível gravar o certificado na pasta compartilhada de certificados (~/.monky/tls ou MONKY_TLS_DIR).',
} as const;
60 changes: 0 additions & 60 deletions apps/server/src/infrastructure/tls/AcmeChallenges.ts

This file was deleted.

Loading
Loading