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) } }