update
This commit is contained in:
@ -103,56 +103,39 @@ export class TlsHandler implements ITlsHandler {
|
||||
// Get the session for this socket
|
||||
const session = this.sessionManager.getSession(socket);
|
||||
|
||||
// Use certificate strings directly without Buffer conversion
|
||||
// For ASN.1 encoding issues, keep the raw format which Node.js can parse natively
|
||||
const key = this.options.key.trim();
|
||||
const cert = this.options.cert.trim();
|
||||
const ca = this.options.ca ? this.options.ca.trim() : undefined;
|
||||
|
||||
// Log certificate buffer lengths for debugging
|
||||
SmtpLogger.debug('Upgrading connection with certificates', {
|
||||
keyBufferLength: key.length,
|
||||
certBufferLength: cert.length,
|
||||
caBufferLength: ca ? ca.length : 0
|
||||
});
|
||||
|
||||
// For testing/production compatibility, allow older TLS versions
|
||||
const context: plugins.tls.TlsOptions = {
|
||||
key: key,
|
||||
cert: cert,
|
||||
ca: ca,
|
||||
isServer: true,
|
||||
// Allow older TLS versions for better compatibility with clients
|
||||
minVersion: 'TLSv1',
|
||||
maxVersion: 'TLSv1.3',
|
||||
// Enforce server cipher preference for better security
|
||||
honorCipherOrder: true,
|
||||
// For testing, allow unauthorized (self-signed certs)
|
||||
rejectUnauthorized: false,
|
||||
// Use a more permissive cipher list for testing compatibility
|
||||
ciphers: 'ALL:!aNULL',
|
||||
// Allow legacy renegotiation for SMTP
|
||||
allowRenegotiation: true,
|
||||
// Handling handshake timeout
|
||||
handshakeTimeout: 10000, // 10 seconds
|
||||
};
|
||||
|
||||
try {
|
||||
// Direct options approach without separate secureContext creation
|
||||
// Use the simplest possible TLS setup to avoid ASN.1 errors
|
||||
// Use certificate strings directly without Buffer conversion
|
||||
// For ASN.1 encoding issues, keep the raw format which Node.js can parse natively
|
||||
const key = this.options.key.trim();
|
||||
const cert = this.options.cert.trim();
|
||||
const ca = this.options.ca ? this.options.ca.trim() : undefined;
|
||||
|
||||
// Create secure socket directly with minimal options
|
||||
// Log certificate lengths for debugging
|
||||
SmtpLogger.debug('Upgrading connection with certificates', {
|
||||
keyLength: key.length,
|
||||
certLength: cert.length,
|
||||
caLength: ca ? ca.length : 0
|
||||
});
|
||||
|
||||
// Create secure socket directly with minimal options for maximum compatibility
|
||||
const secureSocket = new plugins.tls.TLSSocket(socket, {
|
||||
isServer: true,
|
||||
key: key,
|
||||
cert: cert,
|
||||
ca: ca,
|
||||
// Allow older TLS versions for better compatibility with clients
|
||||
minVersion: 'TLSv1',
|
||||
maxVersion: 'TLSv1.3',
|
||||
// Use a permissive cipher list for testing compatibility
|
||||
ciphers: 'ALL',
|
||||
honorCipherOrder: true,
|
||||
// For testing, allow unauthorized (self-signed certs)
|
||||
rejectUnauthorized: false,
|
||||
// Don't request client certificates
|
||||
requestCert: false,
|
||||
rejectUnauthorized: false
|
||||
// Allow legacy renegotiation for SMTP
|
||||
allowRenegotiation: true,
|
||||
// No server - prevents potential reference issues
|
||||
server: undefined
|
||||
});
|
||||
|
||||
// Add a specific check for secure event to make sure the handshake completes
|
||||
@ -290,32 +273,34 @@ export class TlsHandler implements ITlsHandler {
|
||||
const cert = this.options.cert.trim();
|
||||
const ca = this.options.ca ? this.options.ca.trim() : undefined;
|
||||
|
||||
// Log certificate buffer lengths for debugging
|
||||
// Log certificate lengths for debugging
|
||||
SmtpLogger.debug('Creating secure server with certificates', {
|
||||
keyBufferLength: key.length,
|
||||
certBufferLength: cert.length,
|
||||
caBufferLength: ca ? ca.length : 0
|
||||
keyLength: key.length,
|
||||
certLength: cert.length,
|
||||
caLength: ca ? ca.length : 0
|
||||
});
|
||||
|
||||
// Simplify options to minimal necessary for test compatibility
|
||||
const context: plugins.tls.TlsOptions = {
|
||||
// Use consistent options with startTLS for maximum compatibility
|
||||
const tlsOptions: plugins.tls.TlsOptions = {
|
||||
key: key,
|
||||
cert: cert,
|
||||
ca: ca,
|
||||
// Allow all TLS versions for maximum compatibility
|
||||
// Allow older TLS versions for better compatibility with clients
|
||||
minVersion: 'TLSv1',
|
||||
maxVersion: 'TLSv1.3',
|
||||
// Accept all ciphers for testing
|
||||
// Use a permissive cipher list for testing compatibility
|
||||
ciphers: 'ALL',
|
||||
// For testing, always allow self-signed certs
|
||||
// For testing, allow unauthorized (self-signed certs)
|
||||
rejectUnauthorized: false,
|
||||
// Shorter handshake timeout for testing
|
||||
handshakeTimeout: 5000
|
||||
handshakeTimeout: 5000,
|
||||
// Accept non-ALPN connections (legacy clients)
|
||||
ALPNProtocols: ['smtp']
|
||||
};
|
||||
|
||||
// Create a simple, standalone server that explicitly doesn't try to
|
||||
// verify or validate client certificates for testing
|
||||
return new plugins.tls.Server(context);
|
||||
// Create a simple, standalone server with minimal options
|
||||
return new plugins.tls.Server(tlsOptions);
|
||||
} catch (error) {
|
||||
SmtpLogger.error(`Failed to create secure server: ${error instanceof Error ? error.message : String(error)}`, {
|
||||
error: error instanceof Error ? error : new Error(String(error)),
|
||||
|
Reference in New Issue
Block a user