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:
Přemysl Eric Janouch 2018-08-06 21:39:40 +02:00
parent f8bcfe447c
commit cc08b5457c
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 15 additions and 16 deletions

View File

@ -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,7 +74,7 @@ func detectTLS(sysconn syscall.RawConn) (isTLS bool) {
// --- Declarations ------------------------------------------------------------
type connCloseWrite interface {
type connCloseWriter interface {
net.Conn
CloseWrite() error
}
@ -82,7 +82,7 @@ type connCloseWrite interface {
type client struct {
transport net.Conn // underlying connection
tls *tls.Conn // TLS, if detected
conn connCloseWrite // high-level connection
conn connCloseWriter // high-level connection
inQ []byte // unprocessed input
outQ []byte // unprocessed output
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.
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: