@@ -90,6 +90,8 @@ type proxyApp struct {
9090 httpClient * http.Client
9191 sockDialer proxy.Dialer
9292 logger * zerolog.Logger
93+ certFile string
94+ keyFile string
9395}
9496
9597func (p * proxyApp ) doReq (w http.ResponseWriter , r * http.Request , socks bool ) * http.Response {
@@ -312,8 +314,14 @@ func (p *proxyApp) handler() http.HandlerFunc {
312314
313315func (p * proxyApp ) Run () {
314316 p .httpServer .Handler = p .handler ()
315- if err := p .httpServer .ListenAndServe (); err != nil {
316- p .logger .Fatal ().Err (err ).Msg ("Unable to start HTTP server" )
317+ if p .certFile != "" && p .keyFile != "" {
318+ if err := p .httpServer .ListenAndServeTLS (p .certFile , p .keyFile ); err != nil {
319+ p .logger .Fatal ().Err (err ).Msg ("Unable to start HTTPS server" )
320+ }
321+ } else {
322+ if err := p .httpServer .ListenAndServe (); err != nil {
323+ p .logger .Fatal ().Err (err ).Msg ("Unable to start HTTP server" )
324+ }
317325 }
318326}
319327
@@ -324,6 +332,8 @@ type Config struct {
324332 Json bool
325333 User string
326334 Pass string
335+ CertFile string
336+ KeyFile string
327337}
328338
329339func New (conf * Config ) * proxyApp {
@@ -364,6 +374,16 @@ func New(conf *Config) *proxyApp {
364374 WriteTimeout : writeTimeout ,
365375 MaxHeaderBytes : 1 << 20 ,
366376 Protocols : new (http.Protocols ),
377+ TLSConfig : & tls.Config {
378+ MinVersion : tls .VersionTLS12 ,
379+ CurvePreferences : []tls.CurveID {tls .CurveP521 , tls .CurveP384 , tls .CurveP256 },
380+ CipherSuites : []uint16 {
381+ tls .TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 ,
382+ tls .TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA ,
383+ tls .TLS_RSA_WITH_AES_256_GCM_SHA384 ,
384+ tls .TLS_RSA_WITH_AES_256_CBC_SHA ,
385+ },
386+ },
367387 }
368388 hs .TLSNextProto = make (map [string ]func (* http.Server , * tls.Conn , http.Handler ))
369389 hs .Protocols .SetHTTP1 (true )
@@ -376,6 +396,18 @@ func New(conf *Config) *proxyApp {
376396 },
377397 }
378398 logger .Info ().Msgf ("SOCKS5 Proxy: %s" , conf .AddrSOCKS )
379- logger .Info ().Msgf ("HTTP Proxy: %s" , conf .AddrHTTP )
380- return & proxyApp {httpServer : hs , sockClient : socks , httpClient : hc , sockDialer : dialer , logger : & logger }
399+ if conf .CertFile != "" && conf .KeyFile != "" {
400+ logger .Info ().Msgf ("HTTPS Proxy: %s" , conf .AddrHTTP )
401+ } else {
402+ logger .Info ().Msgf ("HTTP Proxy: %s" , conf .AddrHTTP )
403+ }
404+ return & proxyApp {
405+ httpServer : hs ,
406+ sockClient : socks ,
407+ httpClient : hc ,
408+ sockDialer : dialer ,
409+ logger : & logger ,
410+ certFile : conf .CertFile ,
411+ keyFile : conf .KeyFile ,
412+ }
381413}
0 commit comments