https_proxy.go 949 B

123456789101112131415161718192021222324252627282930313233343536
  1. package process
  2. import (
  3. "crypto/tls"
  4. "ehang.io/nps/core/action"
  5. "ehang.io/nps/lib/enet"
  6. )
  7. type HttpsProxyProcess struct {
  8. CertFile string `json:"cert_file" required:"true" placeholder:"/var/cert/cert.pem" zh_name:"cert文件路径"`
  9. KeyFile string `json:"key_file" required:"true" placeholder:"/var/cert/key.pem" zh_name:"key文件路径"`
  10. config *tls.Config
  11. HttpProxyProcess
  12. }
  13. func (hpp *HttpsProxyProcess) GetName() string {
  14. return "https_proxy"
  15. }
  16. func (hpp *HttpsProxyProcess) GetZhName() string {
  17. return "https代理"
  18. }
  19. func (hpp *HttpsProxyProcess) Init(ac action.Action) error {
  20. cer, err := tls.LoadX509KeyPair(hpp.CertFile, hpp.KeyFile)
  21. if err != nil {
  22. return err
  23. }
  24. hpp.config = &tls.Config{Certificates: []tls.Certificate{cer}}
  25. hpp.ac = ac
  26. return nil
  27. }
  28. func (hpp *HttpsProxyProcess) ProcessConn(c enet.Conn) (bool, error) {
  29. return hpp.HttpProxyProcess.ProcessConn(enet.NewReaderConn(tls.Server(c, hpp.config)))
  30. }