deno-smtp icon indicating copy to clipboard operation
deno-smtp copied to clipboard

[Feature Request] STARTTLS

Open dbellingroth opened this issue 3 years ago • 5 comments

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.

dbellingroth avatar Aug 09 '21 09:08 dbellingroth

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

manyuanrong avatar Aug 09 '21 09:08 manyuanrong

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 avatar Aug 10 '21 14:08 dbellingroth

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.

dbellingroth avatar Aug 12 '21 06:08 dbellingroth

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

Bettelstab avatar Nov 08 '21 16:11 Bettelstab

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

👍

dbellingroth avatar Nov 09 '21 05:11 dbellingroth