-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
35 lines (30 loc) · 991 Bytes
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package sniproxy
import (
"crypto/tls"
"io"
"net"
"sync"
"time"
)
type readOnlyConn struct{ io.Reader }
func (readOnlyConn) Write([]byte) (int, error) { return 0, net.ErrClosed }
func (readOnlyConn) Close() error { return nil }
func (readOnlyConn) LocalAddr() net.Addr { return nil }
func (readOnlyConn) RemoteAddr() net.Addr { return nil }
func (readOnlyConn) SetDeadline(time.Time) error { return nil }
func (readOnlyConn) SetReadDeadline(time.Time) error { return nil }
func (readOnlyConn) SetWriteDeadline(time.Time) error { return nil }
func copyConn(dst, src net.Conn, wg *sync.WaitGroup) {
_, _ = io.Copy(dst, src)
_ = dst.Close()
wg.Done()
}
func readClientHello(r io.Reader) (fqdn string) {
config := new(tls.Config)
config.GetConfigForClient = func(info *tls.ClientHelloInfo) (*tls.Config, error) {
fqdn = info.ServerName
return nil, nil
}
_ = tls.Server(readOnlyConn{r}, config).Handshake()
return
}