aboutsummaryrefslogtreecommitdiff
path: root/prototypes/tls-autodetect.go
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2018-08-06 21:39:40 +0200
committerPřemysl Janouch <p@janouch.name>2018-08-06 21:41:49 +0200
commitcc08b5457ca9545111141b0f7a27320d9bd3116d (patch)
tree8270a8257ce72037b2dfb0f990c78e8280a52594 /prototypes/tls-autodetect.go
parentf8bcfe447c748b47681afaa996a782768fabf30b (diff)
downloadhaven-cc08b5457ca9545111141b0f7a27320d9bd3116d.tar.gz
haven-cc08b5457ca9545111141b0f7a27320d9bd3116d.tar.xz
haven-cc08b5457ca9545111141b0f7a27320d9bd3116d.zip
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
Diffstat (limited to 'prototypes/tls-autodetect.go')
-rw-r--r--prototypes/tls-autodetect.go31
1 files changed, 15 insertions, 16 deletions
diff --git a/prototypes/tls-autodetect.go b/prototypes/tls-autodetect.go
index a5642d6..0427465 100644
--- a/prototypes/tls-autodetect.go
+++ b/prototypes/tls-autodetect.go
@@ -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: