1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-02-20 23:47:21 -05:00

receive handshake address from tls conn

This commit is contained in:
Darien Raymond 2018-07-14 13:58:24 +02:00
parent 9a9b6f9077
commit 14dc6371d3
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 23 additions and 2 deletions

View File

@ -54,6 +54,10 @@ func (d *DokodemoDoor) policy() core.Policy {
return p return p
} }
type hasHandshakeAddress interface {
HandshakeAddress() net.Address
}
func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher core.Dispatcher) error { func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher core.Dispatcher) error {
newError("processing connection from: ", conn.RemoteAddr()).AtDebug().WriteToLog(session.ExportIDToError(ctx)) newError("processing connection from: ", conn.RemoteAddr()).AtDebug().WriteToLog(session.ExportIDToError(ctx))
dest := net.Destination{ dest := net.Destination{
@ -65,6 +69,12 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
if origDest, ok := proxy.OriginalTargetFromContext(ctx); ok { if origDest, ok := proxy.OriginalTargetFromContext(ctx); ok {
dest = origDest dest = origDest
} }
if handshake, ok := conn.(hasHandshakeAddress); ok {
addr := handshake.HandshakeAddress()
if addr != nil {
dest.Address = addr
}
}
} }
if !dest.IsValid() || dest.Address == nil { if !dest.IsValid() || dest.Address == nil {
return newError("unable to get destination") return newError("unable to get destination")

View File

@ -2,9 +2,9 @@ package tls
import ( import (
"crypto/tls" "crypto/tls"
"net"
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
"v2ray.com/core/common/net"
) )
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg tls -path Transport,Internet,TLS //go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg tls -path Transport,Internet,TLS
@ -14,7 +14,7 @@ var (
) )
type conn struct { type conn struct {
net.Conn *tls.Conn
mergingWriter *buf.BufferedWriter mergingWriter *buf.BufferedWriter
} }
@ -29,6 +29,17 @@ func (c *conn) WriteMultiBuffer(mb buf.MultiBuffer) error {
return c.mergingWriter.Flush() return c.mergingWriter.Flush()
} }
func (c *conn) HandshakeAddress() net.Address {
if err := c.Handshake(); err != nil {
return nil
}
state := c.Conn.ConnectionState()
if len(state.ServerName) == 0 {
return nil
}
return net.ParseAddress(state.ServerName)
}
// Client initiates a TLS client handshake on the given connection. // Client initiates a TLS client handshake on the given connection.
func Client(c net.Conn, config *tls.Config) net.Conn { func Client(c net.Conn, config *tls.Config) net.Conn {
tlsConn := tls.Client(c, config) tlsConn := tls.Client(c, config)