I have the following piece of code:
l, err := tls.Listen("tcp", "localhost:0", cfg)
dieIf(err)
c, err := l.Accept()
dieIf(err)
err = c.(*tls.Conn).Handshake()
dieIf(err)
It works just fine, but I'd like to intercept tls.Conn
's reads and writes.
I thought about doing this:
type MitmConn struct {
net.Conn
}
func (self *MitmConn) Read(b []byte) (n int, err error) {
...
}
func (self *MitmConn) Write(b []byte) (n int, err error) {
...
}
l, err := tls.Listen("tcp", "localhost:0", cfg)
dieIf(err)
c, err := l.Accept()
dieIf(err)
c = &MitmConn{c}
But then, this would fail:
// panic: interface conversion: net.Conn is *MitmConn, not *tls.Conn
err = c.(*tls.Conn).Handshake()
dieIf(err)
Any ideas?