Skip to content

Commit 591442c

Browse files
torikki-touemersion
authored andcommitted
Allow manual Hello after StartTLS
(cherry picked from commit 75e52af)
1 parent e74d8b3 commit 591442c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

client.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type Client struct {
3030
ext map[string]string // supported extensions
3131
localName string // the name to use in HELO/EHLO/LHLO
3232
didHello bool // whether we've said HELO/EHLO/LHLO
33+
didGreet bool // whether we've received greeting from server
3334
helloError error // the error from the hello
3435
rcpts []string // recipients accumulated for the current session
3536

@@ -179,6 +180,10 @@ func (c *Client) Close() error {
179180
}
180181

181182
func (c *Client) greet() error {
183+
if c.didGreet {
184+
return nil
185+
}
186+
182187
// Initial greeting timeout. RFC 5321 recommends 5 minutes.
183188
c.conn.SetDeadline(time.Now().Add(c.CommandTimeout))
184189
defer c.conn.SetDeadline(time.Time{})
@@ -189,6 +194,7 @@ func (c *Client) greet() error {
189194
return err
190195
}
191196

197+
c.didGreet = true
192198
return nil
193199
}
194200

@@ -321,7 +327,8 @@ func (c *Client) startTLS(config *tls.Config) error {
321327
testHookStartTLS(config)
322328
}
323329
c.setConn(tls.Client(c.conn, config))
324-
return c.ehlo()
330+
c.didHello = false
331+
return nil
325332
}
326333

327334
// TLSConnectionState returns the client's TLS connection state.

client_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,10 @@ func TestTLSConnState(t *testing.T) {
653653
return
654654
}
655655
defer c.Quit()
656+
if err := c.Hello("localhost"); err != nil {
657+
t.Errorf("Client hello: %v", err)
658+
return
659+
}
656660
cs, ok := c.TLSConnectionState()
657661
if !ok {
658662
t.Errorf("TLSConnectionState returned ok == false; want true")

0 commit comments

Comments
 (0)