tls.go 668 B

12345678910111213141516171819202122232425262728
  1. package crypt
  2. import (
  3. "crypto/tls"
  4. "github.com/cnlh/nps/vender/github.com/astaxie/beego"
  5. "github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
  6. "net"
  7. "os"
  8. "path/filepath"
  9. )
  10. func NewTlsServerConn(conn net.Conn) net.Conn {
  11. cert, err := tls.LoadX509KeyPair(filepath.Join(beego.AppPath, "conf", "server.pem"), filepath.Join(beego.AppPath, "conf", "server.key"))
  12. if err != nil {
  13. logs.Error(err)
  14. os.Exit(0)
  15. return nil
  16. }
  17. config := &tls.Config{Certificates: []tls.Certificate{cert}}
  18. return tls.Server(conn, config)
  19. }
  20. func NewTlsClientConn(conn net.Conn) net.Conn {
  21. conf := &tls.Config{
  22. InsecureSkipVerify: true,
  23. }
  24. return tls.Client(conn, conf)
  25. }