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:
		@@ -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:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user