haraka / Haraka

A fast, highly extensible, and event driven SMTP server
https://haraka.github.io
MIT License
5.02k stars 662 forks source link

500 Unrecognized command when tls plugin enabled #1534

Closed xpepermint closed 7 years ago

xpepermint commented 8 years ago

Version: 2.8.7

I try to build a simple SMTP server for sending and receiving emails. The server listens on ports 25 and 587 (smtp.ini).

  1. I created a custom plugin which authenticates a user.
exports.register = function() {
  this.inherits('auth/auth_base');
};

exports.hook_capabilities = function(next, connection) {
  let methods = ['PLAIN'];
  connection.capabilities.push(`AUTH ${methods.join(' ')}`);
  connection.notes.allowed_auth_methods = methods;
  next();
};

exports.check_plain_passwd = function(connection, user, secret, next) {
   ... // verify credentials
   next(true);
};
  1. I also create a custom plugin which stores an incoming email.
const constants = require('haraka-constants');

exports.hook_queue = function(next, connection) {
  ... // save email
  next(constants.ok);
};
  1. When I add the tls plugin I can not receive an email from e.g. GMail. I see an error
...
[core] S: 250 STARTTLS
[core] C: STARTTLS state=1
[core] running unrecognized_command hooks
[core] running unrecognized_command hook in tls plugin
[core] S: 220 Go ahead.
[core] Upgrading to TLS
[tls] timeout
[core] hook=unrecognized_command plugin=tls function=tls_unrecognized_command params="STARTTLS" retval=DENYSOFTDISCONNECT msg=""
[core] running deny hooks
[core] S: 500 Unrecognized command
...

What I'm dogin wrong? I suspect there is a bug in the tls plugin.

xpepermint commented 8 years ago

I found the problem. I set the config/plugin_timeout to 0 based on the description from the docs:

Note also that each plugin can have a config/.timeout file specifying a per-plugin timeout. In this file you can set a timeout of 0 to mean that this plugin’s hooks never time out. Use this with care.*

If I change the value to > 0 the error goes away.