diff options
| author | Kyren223 <Kyren223@proton.me> | 2025-01-10 17:29:14 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2025-01-10 17:29:14 +0200 |
| commit | f0382c2f93c2676f9754a0a60a7e33099a19bdd3 (patch) | |
| tree | bfc5a245f8b0e558b092cebd6c678af8ef9f29fd /internal/client/gateway | |
| parent | c86d41fe662079b20f36d1d7bda22e9206c753da (diff) | |
Fixed gateway issues and some other stuff
Diffstat (limited to 'internal/client/gateway')
| -rw-r--r-- | internal/client/gateway/gateway.go | 39 |
1 files changed, 20 insertions, 19 deletions
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 |
