Commit 80317ea1 authored by Marten Seemann's avatar Marten Seemann Committed by Steven Allen

close the underlying connection when the handshake fails

parent 66963cfa
Pipeline #646 failed with stages
in 0 seconds
......@@ -54,7 +54,11 @@ var _ cs.Transport = &Transport{}
// SecureInbound runs the TLS handshake as a server.
func (t *Transport) SecureInbound(ctx context.Context, insecure net.Conn) (cs.Conn, error) {
config, keyCh := t.identity.ConfigForAny()
return t.handshake(ctx, tls.Server(insecure, config), keyCh)
cs, err := t.handshake(ctx, tls.Server(insecure, config), keyCh)
if err != nil {
insecure.Close()
}
return cs, err
}
// SecureOutbound runs the TLS handshake as a client.
......@@ -66,7 +70,11 @@ func (t *Transport) SecureInbound(ctx context.Context, insecure net.Conn) (cs.Co
// notice this after 1 RTT when calling Read.
func (t *Transport) SecureOutbound(ctx context.Context, insecure net.Conn, p peer.ID) (cs.Conn, error) {
config, keyCh := t.identity.ConfigForPeer(p)
return t.handshake(ctx, tls.Client(insecure, config), keyCh)
cs, err := t.handshake(ctx, tls.Client(insecure, config), keyCh)
if err != nil {
insecure.Close()
}
return cs, err
}
func (t *Transport) handshake(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment