mic.git


mic

~ proxy for JA4-TLS fingerprinting evasion
git clone https://github.com/djnnvx/mic.git
log | files | refs | archive | README | LICENSE

commit 2896ba9819f94149d962e60c4e6dda742ad2722e
parent 7c6c8f7248497ef46ad2b9130cf138a36ce6e53e
Author: djnn <[email protected]>
Date: Sun, 17 May 2026 18:41:06 +0900

cleanup(meta): use single-handler instead of handling chain not possible to actually chain all handlers, since the first one consumes the request anyway

Diffstat:
Mcmd/client.go | 2+-
Mcmd/server.go | 2+-
Mproxy/proxy.go | 21+++++++--------------

3 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/cmd/client.go b/cmd/client.go
@@ -55,7 +55,7 @@ func newClientCmd() *cobra.Command {
 			}
 
 			log.Printf("[+] Mode: client (HTTP CONNECT proxy on %s)", listen)
-			p.RegisterHandler(proxy.HttpsHandler)
+			p.Handler = proxy.HttpsHandler
 			return p.Run()
 		},
 	}
diff --git a/cmd/server.go b/cmd/server.go
@@ -56,7 +56,7 @@ func newServerCmd() *cobra.Command {
 			}
 
 			log.Printf("[+] Mode: server (TLS termination → backend %s)", backend)
-			p.RegisterHandler(proxy.ServerFrontHandler(cert, key))
+			p.Handler = proxy.ServerFrontHandler(cert, key)
 			return p.Run()
 		},
 	}
diff --git a/proxy/proxy.go b/proxy/proxy.go
@@ -2,6 +2,7 @@ package proxy
 
 import (
 	"crypto/x509"
+	"fmt"
 	"io"
 	"log"
 	"net"
@@ -18,16 +19,11 @@ type Proxy struct {
 	CAPool      *x509.CertPool
 	Fingerprint fingerprint.TLSApplier
 	LocalCA     *LocalCA // client-front: MitM CA for TLS interception
-
-	handlers []Handler
+	Handler     Handler
 }
 
 type Handler func(conn net.Conn, p *Proxy)
 
-func (p *Proxy) RegisterHandler(h Handler) {
-	p.handlers = append(p.handlers, h)
-}
-
 // dialTarget dials host (host:port) and returns a uTLS connection after a
 // successful handshake. Falls back to HelloRandomized when no fingerprint is set.
 func (p *Proxy) dialTarget(host string) (*utls.UConn, error) {
@@ -81,6 +77,9 @@ func pipe(client io.ReadWriteCloser, r io.Reader, target io.ReadWriteCloser) {
 }
 
 func (p *Proxy) Run() error {
+	if p.Handler == nil {
+		return fmt.Errorf("proxy: Handler is required")
+	}
 	ln, err := net.Listen("tcp", p.ListenAddr)
 	if err != nil {
 		return err
@@ -89,17 +88,11 @@ func (p *Proxy) Run() error {
 
 	log.Printf("[+] Starting proxy on %s", p.ListenAddr)
 	for {
-		c, err := ln.Accept()
+		conn, err := ln.Accept()
 		if err != nil {
 			log.Printf("Failed to accept connection: %v", err)
 			continue
 		}
-
-		conn := c
-		go func() {
-			for _, h := range p.handlers {
-				h(conn, p)
-			}
-		}()
+		go p.Handler(conn, p)
 	}
 }