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
|
isTLS = buf[0]&0x80 != 0 && buf[2] == 1
|
||||||
fallthrough
|
fallthrough
|
||||||
case n == 2:
|
case n == 2:
|
||||||
isTLS = buf[0] == 22 && buf[1] == 3
|
isTLS = isTLS || buf[0] == 22 && buf[1] == 3
|
||||||
case n == 1:
|
case n == 1:
|
||||||
isTLS = buf[0] == 22
|
isTLS = buf[0] == 22
|
||||||
case err == syscall.EAGAIN:
|
case err == syscall.EAGAIN:
|
||||||
|
@ -74,7 +74,7 @@ func detectTLS(sysconn syscall.RawConn) (isTLS bool) {
|
||||||
|
|
||||||
// --- Declarations ------------------------------------------------------------
|
// --- Declarations ------------------------------------------------------------
|
||||||
|
|
||||||
type connCloseWrite interface {
|
type connCloseWriter interface {
|
||||||
net.Conn
|
net.Conn
|
||||||
CloseWrite() error
|
CloseWrite() error
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ type connCloseWrite interface {
|
||||||
type client struct {
|
type client struct {
|
||||||
transport net.Conn // underlying connection
|
transport net.Conn // underlying connection
|
||||||
tls *tls.Conn // TLS, if detected
|
tls *tls.Conn // TLS, if detected
|
||||||
conn connCloseWrite // high-level connection
|
conn connCloseWriter // high-level connection
|
||||||
inQ []byte // unprocessed input
|
inQ []byte // unprocessed input
|
||||||
outQ []byte // unprocessed output
|
outQ []byte // unprocessed output
|
||||||
reading bool // whether a reading goroutine is running
|
reading bool // whether a reading goroutine is running
|
||||||
|
@ -210,15 +210,14 @@ func (c *client) destroy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle the results from initializing the client's connection.
|
// 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 {
|
if isTLS {
|
||||||
c.tls = tls.Server(c.transport, tlsConf)
|
c.tls = tls.Server(c.transport, tlsConf)
|
||||||
c.conn = c.tls
|
c.conn = c.tls
|
||||||
} else {
|
} 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.
|
// TODO: If we've tried to send any data before now, we need to flushOutQ.
|
||||||
go read(c)
|
go read(c)
|
||||||
c.reading = true
|
c.reading = true
|
||||||
|
@ -399,9 +398,9 @@ func processOneEvent() {
|
||||||
go prepare(c)
|
go prepare(c)
|
||||||
|
|
||||||
case ev := <-prepared:
|
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 {
|
if _, ok := clients[ev.client]; ok {
|
||||||
ev.client.onPrepared(ev.host, ev.isTLS)
|
ev.client.onPrepared(ev.isTLS)
|
||||||
}
|
}
|
||||||
|
|
||||||
case ev := <-reads:
|
case ev := <-reads:
|
||||||
|
|
Loading…
Reference in New Issue