#include "__SMTP_STARTTLS.h" #include "SMTPServer.h" #include "SMTPSyntax.h" #include "Log.h" namespace mail { int __SMTP_STARTTLS::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) { if (session.isTLS()) { session.out << "503 5.5.1 TLS already active" << CRLF; return 1; } if (!server.startTLSContext) { session.out << "454 4.7.0 TLS not available due to temporary reason" << CRLF; return 1; } // RFC 3207 4: "STARTTLS" CRLF - no parameters. if (!SMTPSyntax::argument(line(request)).empty()) { session.out << "501 5.5.4 Syntax error (no parameters allowed)" << CRLF; return 1; } // RFC 3207 4.2: once the handshake starts the server MUST discard // everything it learned from the client before it - the EHLO name, // any AUTH, any transaction - none of it was protected. The client // sends EHLO again over the encrypted channel. session.resetAll(); session.out << "220 2.0.0 Ready to start TLS" << CRLF; // Sends the 220 in clear, drops anything the client pipelined // after STARTTLS (RFC 3207 4 forbids it; acting on it is the // CVE-2011-0411 injection hole), then starts the handshake. if (!session.startTLS(server.startTLSContext)) coreutils::Log(coreutils::LOG_INFO) << "STARTTLS upgrade failed; connection closed."; return 1; } }