From f0382c2f93c2676f9754a0a60a7e33099a19bdd3 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Fri, 10 Jan 2025 17:29:14 +0200 Subject: Fixed gateway issues and some other stuff --- internal/client/gateway/gateway.go | 39 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'internal/client/gateway') diff --git a/internal/client/gateway/gateway.go b/internal/client/gateway/gateway.go index 641cb53..e272ca5 100644 --- a/internal/client/gateway/gateway.go +++ b/internal/client/gateway/gateway.go @@ -23,8 +23,6 @@ import ( ) var ( - tlsConfig *tls.Config - framer packet.PacketFramer conn net.Conn writeMu sync.Mutex @@ -38,23 +36,6 @@ type ( ConnectionClosed struct{} ) -func init() { - certPool := x509.NewCertPool() - if !certPool.AppendCertsFromPEM(certs.CertPEM) { - log.Fatalln("failed to append server certificate") - } - - tlsConfig = &tls.Config{ - RootCAs: certPool, - ServerName: config.Read().ServerName, - MinVersion: tls.VersionTLS12, - // This is fine, it's always false by default - // The user may change the config, the name should be clear enough - // that this is insecure (valid use cases are for testing purposes) - InsecureSkipVerify: config.Read().InsecureSkipServerVerification, // #nosec 402 - } -} - func Connect(privKey ed25519.PrivateKey, timeout time.Duration) tea.Cmd { return func() tea.Msg { ctx, cancel := context.WithTimeout(context.Background(), timeout) @@ -76,7 +57,27 @@ func connect(ctx context.Context, privKey ed25519.PrivateKey) (snowflake.ID, err errChan := make(chan error, 1) go func() { framer = packet.NewFramer() + + certPool := x509.NewCertPool() + if !certPool.AppendCertsFromPEM(certs.CertPEM) { + log.Fatalln("failed to append server certificate") + } + + tlsConfig := &tls.Config{ + RootCAs: certPool, + ServerName: config.Read().ServerName, + MinVersion: tls.VersionTLS12, + // This is fine, it's always false by default + // The user may change the config, the name should be clear enough + // that this is insecure (valid use cases are for testing purposes) + InsecureSkipVerify: config.Read().InsecureDebugMode, // #nosec 402 + } + address := config.Read().ServerName + if config.Read().InsecureDebugMode { + address = "localhost" + } + connection, err := tls.Dial("tcp4", address+":7223", tlsConfig) if err != nil { errChan <- err -- cgit v1.3.1