From feae4fe75e9c38b6381d75cca66216d8dd15d9a7 Mon Sep 17 00:00:00 2001 From: ale Date: Sat, 27 Dec 2025 04:00:53 +0100 Subject: [PATCH] fix tls connect Signed-off-by: ale --- src/core/xmpp-stream.js | 42 +++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/core/xmpp-stream.js b/src/core/xmpp-stream.js index 163ca73..e0643fa 100644 --- a/src/core/xmpp-stream.js +++ b/src/core/xmpp-stream.js @@ -9,6 +9,7 @@ const Logger = require('../utils/logger'); const crypto = require('crypto'); const tls = require('tls'); const fs = require('fs'); +const path = require('path'); // Simple XML stream parser class StreamParser extends EventEmitter { @@ -346,18 +347,47 @@ class XMPPStream extends EventEmitter { }; try { - const keyPath = tlsConfig.keyPath || '/home/ale/projects/xmpp/prosody-nodejs/certs/localhost-key.pem'; - const certPath = tlsConfig.certPath || '/home/ale/projects/xmpp/prosody-nodejs/certs/localhost.pem'; + // Try multiple possible locations for certificates + const possiblePaths = [ + tlsConfig.keyPath || path.join(__dirname, '../../certs/localhost-key.pem'), + path.join(process.cwd(), 'certs/localhost-key.pem'), + '/home/ale/projects/xmpp/prosody-nodejs/certs/localhost-key.pem' + ]; + + const possibleCertPaths = [ + tlsConfig.certPath || path.join(__dirname, '../../certs/localhost.pem'), + path.join(process.cwd(), 'certs/localhost.pem'), + '/home/ale/projects/xmpp/prosody-nodejs/certs/localhost.pem' + ]; - if (fs.existsSync(keyPath) && fs.existsSync(certPath)) { + let keyPath = null; + let certPath = null; + + // Find the first existing key file + for (const p of possiblePaths) { + if (fs.existsSync(p)) { + keyPath = p; + break; + } + } + + // Find the first existing cert file + for (const p of possibleCertPaths) { + if (fs.existsSync(p)) { + certPath = p; + break; + } + } + + if (keyPath && certPath) { options.key = fs.readFileSync(keyPath); options.cert = fs.readFileSync(certPath); - this.logger.debug('Using configured TLS certificates'); + this.logger.debug(`Loaded TLS certificates from ${keyPath}`); } else { - this.logger.warn('TLS certificates not found, using default options'); + this.logger.warn(`TLS certificates not found (checked: ${possiblePaths[0]}, ${possibleCertPaths[0]})`); } } catch (error) { - this.logger.warn('Error loading TLS certificates:', error); + this.logger.warn('Error loading TLS certificates:', error.message); } return options;