mirror of
https://git.phreedom.club/localhost_frssoft/compy.git
synced 2024-11-20 15:19:17 +00:00
f69a0b7e0e
Fixes #21. Reference: https://mtersch.wordpress.com/2015/03/17/certificate-import-in-firefox-on-android/
48 lines
903 B
Go
48 lines
903 B
Go
package proxy
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"net"
|
|
)
|
|
|
|
type mitmListener struct {
|
|
c chan net.Conn
|
|
cf *certFaker
|
|
config *tls.Config
|
|
}
|
|
|
|
func newMitmListener(cf *certFaker, config *tls.Config) *mitmListener {
|
|
return &mitmListener{
|
|
c: make(chan net.Conn),
|
|
cf: cf,
|
|
config: config,
|
|
}
|
|
}
|
|
|
|
func (l *mitmListener) Accept() (net.Conn, error) {
|
|
return <-l.c, nil
|
|
}
|
|
|
|
func (l *mitmListener) Close() error {
|
|
return nil
|
|
}
|
|
|
|
func (l *mitmListener) Addr() net.Addr {
|
|
return nil
|
|
}
|
|
|
|
func (l *mitmListener) Serve(conn net.Conn, host string) (net.Conn, error) {
|
|
sconn, err := tls.Dial("tcp", host, l.config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
fakeCert, err := l.cf.FakeCert(sconn.ConnectionState().PeerCertificates[0])
|
|
if err != nil {
|
|
sconn.Close()
|
|
return nil, err
|
|
}
|
|
tlsconf := &tls.Config{Certificates: []tls.Certificate{*fakeCert}}
|
|
l.c <- tls.Server(conn, tlsconf)
|
|
return sconn, nil
|
|
}
|