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/config/config.go | 20 +++++++++---------- internal/client/gateway/gateway.go | 39 +++++++++++++++++++------------------- internal/client/ui/core/core.go | 2 ++ internal/data/members.sql.go | 2 +- 4 files changed, 33 insertions(+), 30 deletions(-) (limited to 'internal') diff --git a/internal/client/config/config.go b/internal/client/config/config.go index 0d81405..4a4bafc 100644 --- a/internal/client/config/config.go +++ b/internal/client/config/config.go @@ -10,20 +10,20 @@ import ( ) type Config struct { - ServerName string `json:"server_name"` - PrivateKeyPath string `json:"private_key_path"` - InsertModeTabToSpace bool `json:"insert_mode_tab_to_space"` - InsertModeSpacesPerTab uint8 `json:"insert_mode_spaces_per_tab"` - InsecureSkipServerVerification bool `json:"insecure_skip_server_verification"` + ServerName string `json:"server_name"` + PrivateKeyPath string `json:"private_key_path"` + InsertModeTabToSpace bool `json:"insert_mode_tab_to_space"` + InsertModeSpacesPerTab uint8 `json:"insert_mode_spaces_per_tab"` + InsecureDebugMode bool `json:"insecure_debug_mode"` } func Default() Config { return Config{ - ServerName: "eko.kyren.codes", - PrivateKeyPath: "", - InsertModeTabToSpace: true, - InsertModeSpacesPerTab: 4, - InsecureSkipServerVerification: false, + ServerName: "eko.kyren.codes", + PrivateKeyPath: "", + InsertModeTabToSpace: true, + InsertModeSpacesPerTab: 4, + InsecureDebugMode: false, } } 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 diff --git a/internal/client/ui/core/core.go b/internal/client/ui/core/core.go index 5c45f05..16ad7cd 100644 --- a/internal/client/ui/core/core.go +++ b/internal/client/ui/core/core.go @@ -3,6 +3,7 @@ package core import ( "crypto/ed25519" "fmt" + "log" "time" "github.com/charmbracelet/bubbles/spinner" @@ -134,6 +135,7 @@ func (m *Model) updateNotConnected(msg tea.Msg) tea.Cmd { return m.timer.Stop() case gateway.ConnectionFailed: + log.Println("failed to connect:", msg) m.timer = newTimer(m.timeout) m.updateLoadScreenContent() return m.timer.Start() diff --git a/internal/data/members.sql.go b/internal/data/members.sql.go index fd66dba..8d90512 100644 --- a/internal/data/members.sql.go +++ b/internal/data/members.sql.go @@ -184,7 +184,7 @@ INSERT INTO members ( ON CONFLICT DO UPDATE SET is_member = EXCLUDED.is_member, is_admin = EXCLUDED.is_admin, is_muted = EXCLUDED.is_muted, - is_banned = EXCLUDED.is_banned, ban_reason = EXCLUDED.ban_reason, position = EXCLUDED.position + is_banned = EXCLUDED.is_banned, ban_reason = EXCLUDED.ban_reason WHERE user_id = EXCLUDED.user_id AND network_id = EXCLUDED.network_id RETURNING user_id, network_id, joined_at, is_member, is_admin, is_muted, is_banned, ban_reason ` -- cgit v1.3.1