summaryrefslogtreecommitdiff
path: root/internal/client
diff options
context:
space:
mode:
Diffstat (limited to 'internal/client')
-rw-r--r--internal/client/config/config.go20
-rw-r--r--internal/client/gateway/gateway.go39
-rw-r--r--internal/client/ui/core/core.go2
3 files changed, 32 insertions, 29 deletions
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()