tls-autodetect: updates, now that hid is ported
- fix SSL 2.0 detection - give up on using the resolved hostname later - rename connCloseWrite to connCloseWriter
This commit is contained in:
parent
f8bcfe447c
commit
cc08b5457c
@ -61,7 +61,7 @@ func detectTLS(sysconn syscall.RawConn) (isTLS bool) {
|
||||
isTLS = buf[0]&0x80 != 0 && buf[2] == 1
|
||||
fallthrough
|
||||
case n == 2:
|
||||
isTLS = buf[0] == 22 && buf[1] == 3
|
||||
isTLS = isTLS || buf[0] == 22 && buf[1] == 3
|
||||
case n == 1:
|
||||
isTLS = buf[0] == 22
|
||||
case err == syscall.EAGAIN:
|
||||
@ -74,21 +74,21 @@ func detectTLS(sysconn syscall.RawConn) (isTLS bool) {
|
||||
|
||||
// --- Declarations ------------------------------------------------------------
|
||||
|
||||
type connCloseWrite interface {
|
||||
type connCloseWriter interface {
|
||||
net.Conn
|
||||
CloseWrite() error
|
||||
}
|
||||
|
||||
type client struct {
|
||||
transport net.Conn // underlying connection
|
||||
tls *tls.Conn // TLS, if detected
|
||||
conn connCloseWrite // high-level connection
|
||||
inQ []byte // unprocessed input
|
||||
outQ []byte // unprocessed output
|
||||
reading bool // whether a reading goroutine is running
|
||||
writing bool // whether a writing goroutine is running
|
||||
closing bool // whether we're closing the connection
|
||||
killTimer *time.Timer // timeout
|
||||
transport net.Conn // underlying connection
|
||||
tls *tls.Conn // TLS, if detected
|
||||
conn connCloseWriter // high-level connection
|
||||
inQ []byte // unprocessed input
|
||||
outQ []byte // unprocessed output
|
||||
reading bool // whether a reading goroutine is running
|
||||
writing bool // whether a writing goroutine is running
|
||||
closing bool // whether we're closing the connection
|
||||
killTimer *time.Timer // timeout
|
||||
}
|
||||
|
||||
type preparedEvent struct {
|
||||
@ -210,15 +210,14 @@ func (c *client) destroy() {
|
||||
}
|
||||
|
||||
// Handle the results from initializing the client's connection.
|
||||
func (c *client) onPrepared(host string, isTLS bool) {
|
||||
func (c *client) onPrepared(isTLS bool) {
|
||||
if isTLS {
|
||||
c.tls = tls.Server(c.transport, tlsConf)
|
||||
c.conn = c.tls
|
||||
} else {
|
||||
c.conn = c.transport.(connCloseWrite)
|
||||
c.conn = c.transport.(connCloseWriter)
|
||||
}
|
||||
|
||||
// TODO: Save the host in the client structure.
|
||||
// TODO: If we've tried to send any data before now, we need to flushOutQ.
|
||||
go read(c)
|
||||
c.reading = true
|
||||
@ -399,9 +398,9 @@ func processOneEvent() {
|
||||
go prepare(c)
|
||||
|
||||
case ev := <-prepared:
|
||||
log.Println("client is ready:", ev.host)
|
||||
log.Println("client is ready, resolved to", ev.host)
|
||||
if _, ok := clients[ev.client]; ok {
|
||||
ev.client.onPrepared(ev.host, ev.isTLS)
|
||||
ev.client.onPrepared(ev.isTLS)
|
||||
}
|
||||
|
||||
case ev := <-reads:
|
||||
|
Loading…
Reference in New Issue
Block a user