From ffc078530f20d3de7be492d032ebe1dac358bd8a Mon Sep 17 00:00:00 2001 From: Kristof Jakab Date: Sat, 3 Aug 2024 18:31:57 +0100 Subject: [PATCH 1/2] Update --- .github/workflows/pr-check.yml | 6 +++--- .github/workflows/release.yml | 4 ++-- go.mod | 4 ++-- go.sum | 12 ++++++++++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 8623b92a..908eec96 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: golangci/golangci-lint-action@v3 + - uses: golangci/golangci-lint-action@v6 test: name: Test strategy: @@ -21,7 +21,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v5 with: - go-version: ^1.18 + go-version: ^1.22 - run: go test -race -timeout 1m diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c4d4a7a8..60090526 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,9 +9,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v5 with: - go-version: "^1.18" + go-version: "^1.22" - run: go build -o sshesame-linux-amd64 env: GOOS: linux diff --git a/go.mod b/go.mod index 0556ed41..8fead337 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ module github.com/jaksi/sshesame -go 1.18 +go 1.22 require ( github.com/adrg/xdg v0.5.0 - github.com/jaksi/sshutils v0.0.11 + github.com/jaksi/sshutils v0.0.13 github.com/prometheus/client_golang v1.19.1 golang.org/x/crypto v0.25.0 golang.org/x/term v0.22.0 diff --git a/go.sum b/go.sum index c5b15ed0..b308c8b1 100644 --- a/go.sum +++ b/go.sum @@ -6,13 +6,17 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/jaksi/sshutils v0.0.11 h1:MNFPPHkDD+FQJl+SPTL1U8LQ9AJrx87lArEyR35yvsk= -github.com/jaksi/sshutils v0.0.11/go.mod h1:H1/OsmZrqUwTydEeQVT4cTMXO7IDUDb2ClYvGQNg5Ss= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/jaksi/sshutils v0.0.13 h1:0XKYoXU4xzeur8q5uCAerjkcLh9DaEe9OQOhVKuSSJ0= +github.com/jaksi/sshutils v0.0.13/go.mod h1:H1/OsmZrqUwTydEeQVT4cTMXO7IDUDb2ClYvGQNg5Ss= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= @@ -22,7 +26,9 @@ github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5E github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= @@ -33,6 +39,8 @@ google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGm google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 1b314b4bd656b5c059e737f214d7d69e14e8ca51 Mon Sep 17 00:00:00 2001 From: Kristof Jakab Date: Sat, 3 Aug 2024 18:37:15 +0100 Subject: [PATCH 2/2] Remove uses of ioutil --- config.go | 5 ++--- config_test.go | 20 ++++++++++---------- main.go | 5 ++--- replay_test.go | 4 ++-- testproxy/main.go | 6 +++--- testutils.go | 4 ++-- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/config.go b/config.go index c29877d0..12d780c7 100644 --- a/config.go +++ b/config.go @@ -11,7 +11,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "os" "path" @@ -148,14 +147,14 @@ func generateKey(dataDir string, signature keySignature) (string, error) { if err != nil { return "", err } - if err := ioutil.WriteFile(keyFile, pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: keyBytes}), 0600); err != nil { + if err := os.WriteFile(keyFile, pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: keyBytes}), 0600); err != nil { return "", err } return keyFile, nil } func loadKey(keyFile string) (ssh.Signer, error) { - keyBytes, err := ioutil.ReadFile(keyFile) + keyBytes, err := os.ReadFile(keyFile) if err != nil { return nil, err } diff --git a/config_test.go b/config_test.go index 6b466585..a21e49b1 100644 --- a/config_test.go +++ b/config_test.go @@ -3,8 +3,8 @@ package main import ( "errors" "fmt" - "io/ioutil" "log" + "os" "path" "reflect" "testing" @@ -114,7 +114,7 @@ func verifyConfig(t *testing.T, cfg *config, expected *config) { } func verifyDefaultKeys(t *testing.T, dataDir string) { - files, err := ioutil.ReadDir(dataDir) + files, err := os.ReadDir(dataDir) if err != nil { t.Fatalf("Faield to list directory: %v", err) } @@ -125,7 +125,7 @@ func verifyDefaultKeys(t *testing.T, dataDir string) { } keys := map[string]string{} for _, file := range files { - keyBytes, err := ioutil.ReadFile(path.Join(dataDir, file.Name())) + keyBytes, err := os.ReadFile(path.Join(dataDir, file.Name())) if err != nil { t.Fatalf("Failed to read key: %v", err) } @@ -281,7 +281,7 @@ server: expectedConfig.SSHProto.Version = "SSH-2.0-sshesame" expectedConfig.SSHProto.Banner = "This is an SSH honeypot. Everything is logged and monitored." verifyConfig(t, cfg, expectedConfig) - files, err := ioutil.ReadDir(dataDir) + files, err := os.ReadDir(dataDir) if err != nil { t.Fatalf("Failed to read directory: %v", err) } @@ -316,7 +316,7 @@ func TestLogReloadSameFile(t *testing.T) { if err := cfg.logFileHandle.Close(); err != nil { t.Fatalf("Failed to close log file: %v", err) } - logs, err := ioutil.ReadFile(cfg.Logging.File) + logs, err := os.ReadFile(cfg.Logging.File) if err != nil { t.Fatalf("Failed to read log file: %v", err) } @@ -344,7 +344,7 @@ func TestLogReloadDifferentFile(t *testing.T) { if err := cfg.logFileHandle.Close(); err != nil { t.Fatalf("Failed to close log file: %v", err) } - logs1, err := ioutil.ReadFile(logFile1) + logs1, err := os.ReadFile(logFile1) if err != nil { t.Fatalf("Failed to read log file: %v", err) } @@ -352,7 +352,7 @@ func TestLogReloadDifferentFile(t *testing.T) { if string(logs1) != expectedLogs1 { t.Errorf("logs1=%v, want %v", string(logs1), expectedLogs1) } - logs2, err := ioutil.ReadFile(logFile2) + logs2, err := os.ReadFile(logFile2) if err != nil { t.Fatalf("Failed to read log file: %v", err) } @@ -368,7 +368,7 @@ func TestExistingKey(t *testing.T) { if err != nil { t.Fatalf("Failed to generate key: %v", err) } - oldKey, err := ioutil.ReadFile(oldKeyFile) + oldKey, err := os.ReadFile(oldKeyFile) if err != nil { t.Fatalf("Failed to read key: %v", err) } @@ -376,7 +376,7 @@ func TestExistingKey(t *testing.T) { if err != nil { t.Fatalf("Failed to generate key: %v", err) } - newKey, err := ioutil.ReadFile(newKeyFile) + newKey, err := os.ReadFile(newKeyFile) if err != nil { t.Fatalf("Failed to read key: %v", err) } @@ -386,7 +386,7 @@ func TestExistingKey(t *testing.T) { } func TestDefaultConfigFile(t *testing.T) { - configBytes, err := ioutil.ReadFile("sshesame.yaml") + configBytes, err := os.ReadFile("sshesame.yaml") if err != nil { t.Fatalf("Failed to read config file: %v", err) } diff --git a/main.go b/main.go index 255ee48c..ac1759a4 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "flag" - "io/ioutil" "log" "net/http" "os" @@ -35,7 +34,7 @@ func main() { cfg := &config{} configString := "" if *configFile != "" { - configBytes, err := ioutil.ReadFile(*configFile) + configBytes, err := os.ReadFile(*configFile) if err != nil { errorLogger.Fatalf("Failed to read config file: %v", err) } @@ -50,7 +49,7 @@ func main() { go func() { for signal := range reloadSignals { infoLogger.Printf("Reloading config due to %s", signal) - configBytes, err := ioutil.ReadFile(*configFile) + configBytes, err := os.ReadFile(*configFile) if err != nil { warningLogger.Printf("Failed to read config file: %v", err) } diff --git a/replay_test.go b/replay_test.go index d7f5a56e..2e5f52ba 100644 --- a/replay_test.go +++ b/replay_test.go @@ -5,8 +5,8 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net" + "os" "path" "path/filepath" "reflect" @@ -520,7 +520,7 @@ func TestReplay(t *testing.T) { } t.Run(testName, func(t *testing.T) { logBuffer := setupLogBuffer(t, cfg) - testCaseBytes, err := ioutil.ReadFile(testFile) + testCaseBytes, err := os.ReadFile(testFile) if err != nil { t.Fatal(err) } diff --git a/testproxy/main.go b/testproxy/main.go index 45778408..69ab1d01 100644 --- a/testproxy/main.go +++ b/testproxy/main.go @@ -6,8 +6,8 @@ import ( "flag" "fmt" "io" - "io/ioutil" "net" + "os" "golang.org/x/crypto/ssh" ) @@ -479,7 +479,7 @@ func main() { NoClientAuth: true, ServerVersion: "SSH-2.0-OpenSSH_7.2", } - hostKeyBytes, err := ioutil.ReadFile(*hostKeyFile) + hostKeyBytes, err := os.ReadFile(*hostKeyFile) if err != nil { panic(err) } @@ -489,7 +489,7 @@ func main() { } serverConfig.AddHostKey(hostKey) - clientKeyBytes, err := ioutil.ReadFile(*clientKeyFile) + clientKeyBytes, err := os.ReadFile(*clientKeyFile) if err != nil { panic(err) } diff --git a/testutils.go b/testutils.go index 11288ace..bfb636c9 100644 --- a/testutils.go +++ b/testutils.go @@ -2,8 +2,8 @@ package main import ( "bytes" - "io/ioutil" "log" + "os" "path/filepath" "testing" ) @@ -75,7 +75,7 @@ func writeTestKeys(t *testing.T, dataDir string) { "host_ecdsa_key": testECDSAKey, "host_ed25519_key": testEd25519Key, } { - if err := ioutil.WriteFile(filepath.Join(dataDir, fileName), []byte(content), 0600); err != nil { + if err := os.WriteFile(filepath.Join(dataDir, fileName), []byte(content), 0600); err != nil { t.Fatal(err) } }