feat: add TLS support

This commit is contained in:
2025-02-07 21:21:29 +07:00
parent 710dc544c4
commit 1508ade537
7 changed files with 125 additions and 9 deletions

View File

@ -1,12 +1,14 @@
package server
import (
"crypto/tls"
"fmt"
"golang.org/x/crypto/ssh"
"log"
"net"
"net/http"
httpServer "tunnel_pls/http"
"tunnel_pls/utils"
)
type Server struct {
@ -22,6 +24,15 @@ func NewServer(config ssh.ServerConfig) *Server {
return nil
}
go httpServer.Listen()
if utils.Getenv("tls_enabled") == "true" {
cert, err := tls.LoadX509KeyPair(utils.Getenv("cert_loc"), utils.Getenv("key_loc"))
if err != nil {
log.Fatal("Failed to load key pair:", err)
}
tlsConfig := &tls.Config{Certificates: []tls.Certificate{cert}}
go httpServer.ListenTLS(tlsConfig)
}
return &Server{
Conn: &listener,
Config: &config,