manyuanrong / deno-smtp

SMTP implements for deno
MIT License
80 stars 26 forks source link

[Feature Request] STARTTLS #47

Open dbellingroth opened 3 years ago

dbellingroth commented 3 years ago

How hard would it be to implement support for upgrading unencrypted connections via the STARTTLS command? Deno seems to include an new unstable API Deno.startTls which in theory should support upgrading connections.

manyuanrong commented 3 years ago

It shouldn't be difficult. I contributed the Deno.startTLS function to complete this function. But I don’t currently have much energy to develop new features for open source projects

dbellingroth commented 3 years ago

I tried to implement it myself using the following Code:

while (true) {
      const cmd = await this.readCmd();
      if (!cmd || !cmd.args.startsWith("-")) break;
      if (cmd.args == "-STARTTLS") startTLS = true
    }

    if (startTLS) {
      await this.writeCmd("STARTTLS")
      this.assertCode(await this.readCmd(), CommandCode.READY)

      this._conn = await Deno.startTls(this._conn, { hostname: config.hostname });

      const reader = new BufReader(this._conn);
      this._writer = new BufWriter(this._conn);
      this._reader = new TextProtoReader(reader);

      await this.writeCmd("EHLO", config.hostname);

      while (true) {
        const cmd = await this.readCmd();
        if (!cmd || !cmd.args.startsWith("-")) break;
      }
    }

But I'm always getting an error message: error: Uncaught (in promise) UnexpectedEof: tls handshake eof await Deno.writeAll(

dbellingroth commented 3 years ago

I tried to implement it myself using the following Code:

while (true) {
      const cmd = await this.readCmd();
      if (!cmd || !cmd.args.startsWith("-")) break;
      if (cmd.args == "-STARTTLS") startTLS = true
    }

    if (startTLS) {
      await this.writeCmd("STARTTLS")
      this.assertCode(await this.readCmd(), CommandCode.READY)

      this._conn = await Deno.startTls(this._conn, { hostname: config.hostname });

      const reader = new BufReader(this._conn);
      this._writer = new BufWriter(this._conn);
      this._reader = new TextProtoReader(reader);

      await this.writeCmd("EHLO", config.hostname);

      while (true) {
        const cmd = await this.readCmd();
        if (!cmd || !cmd.args.startsWith("-")) break;
      }
    }

But I'm always getting an error message: error: Uncaught (in promise) UnexpectedEof: tls handshake eof await Deno.writeAll(

OK. Seems like this is a problem with the mail server only supporting older cypher suites.

Bettelstab commented 2 years ago

@dbellingroth works for me. I hope you don't mind I put it in a PR: https://github.com/manyuanrong/deno-smtp/pull/54

dbellingroth commented 2 years ago

@dbellingroth works for me. I hope you don't mind I put it in a PR: #54

👍