Skip to content

Commit

Permalink
Allow manual Hello after StartTLS
Browse files Browse the repository at this point in the history
(cherry picked from commit 75e52af)
  • Loading branch information
torikki-tou authored and emersion committed Jul 11, 2024
1 parent e74d8b3 commit 591442c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Client struct {
ext map[string]string // supported extensions
localName string // the name to use in HELO/EHLO/LHLO
didHello bool // whether we've said HELO/EHLO/LHLO
didGreet bool // whether we've received greeting from server
helloError error // the error from the hello
rcpts []string // recipients accumulated for the current session

Expand Down Expand Up @@ -179,6 +180,10 @@ func (c *Client) Close() error {
}

func (c *Client) greet() error {
if c.didGreet {
return nil
}

// Initial greeting timeout. RFC 5321 recommends 5 minutes.
c.conn.SetDeadline(time.Now().Add(c.CommandTimeout))
defer c.conn.SetDeadline(time.Time{})
Expand All @@ -189,6 +194,7 @@ func (c *Client) greet() error {
return err
}

c.didGreet = true
return nil
}

Expand Down Expand Up @@ -321,7 +327,8 @@ func (c *Client) startTLS(config *tls.Config) error {
testHookStartTLS(config)
}
c.setConn(tls.Client(c.conn, config))
return c.ehlo()
c.didHello = false
return nil
}

// TLSConnectionState returns the client's TLS connection state.
Expand Down
4 changes: 4 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,10 @@ func TestTLSConnState(t *testing.T) {
return
}
defer c.Quit()
if err := c.Hello("localhost"); err != nil {
t.Errorf("Client hello: %v", err)
return
}
cs, ok := c.TLSConnectionState()
if !ok {
t.Errorf("TLSConnectionState returned ok == false; want true")
Expand Down

0 comments on commit 591442c

Please sign in to comment.