diff --git a/pkg/ssh/server_test.go b/pkg/ssh/server_test.go index 993eafd6b8..83410a35a4 100644 --- a/pkg/ssh/server_test.go +++ b/pkg/ssh/server_test.go @@ -6,12 +6,12 @@ import ( "crypto/ecdsa" "crypto/elliptic" "crypto/md5" - "crypto/rand" "crypto/rsa" "encoding/binary" "errors" "fmt" "io" + "math/rand" "net" "net/http" "os" @@ -107,11 +107,11 @@ func prepareSSHServer(t *testing.T, authorizedKeys ...any) (sshServer *SSHServer authorizedKeys: authorizedKeys, } - rsaKey, err := rsa.GenerateKey(rand.Reader, 4096) + rsaKey, err := rsa.GenerateKey(rand.New(rand.NewSource(time.Now().UnixNano())), 2048) if err != nil { t.Fatal(err) } - ecdsaKey, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader) + ecdsaKey, err := ecdsa.GenerateKey(elliptic.P384(), rand.New(rand.NewSource(time.Now().UnixNano()))) if err != nil { t.Fatal(err) } diff --git a/pkg/ssh/ssh_dialer_test.go b/pkg/ssh/ssh_dialer_test.go index 9ee59ad85a..912e9363a0 100644 --- a/pkg/ssh/ssh_dialer_test.go +++ b/pkg/ssh/ssh_dialer_test.go @@ -5,12 +5,12 @@ import ( "context" "crypto/ecdsa" "crypto/elliptic" - "crypto/rand" "crypto/rsa" "crypto/x509" "encoding/pem" "fmt" "io" + "math/rand" "net" "net/http" "net/url" @@ -49,7 +49,7 @@ type testParams struct { func TestCreateDialer(t *testing.T) { - clientPrivKeyRSA, clientPrivKeyECDSA := generateKeys(t) + clientPrivKeyRSA, clientPrivKeyECDSA := generateClientKeys(t) withoutSSHAgent(t) withCleanHome(t) @@ -504,7 +504,7 @@ func marshallKey(t *testing.T, key any, destPath, passphrase string) { } if passphrase != "" { - blk, err = x509.EncryptPEMBlock(rand.Reader, blk.Type, blk.Bytes, []byte(passphrase), x509.PEMCipherAES256) + blk, err = x509.EncryptPEMBlock(rand.New(rand.NewSource(time.Now().UnixNano())), blk.Type, blk.Bytes, []byte(passphrase), x509.PEMCipherAES256) th.AssertNil(t, err) } @@ -847,7 +847,7 @@ func (a signerAgent) Sign(key ssh.PublicKey, data []byte) (*ssh.Signature, error } if signer.PublicKey().Type() == key.Type() && bytes.Equal(signer.PublicKey().Marshal(), key.Marshal()) { - return signer.Sign(rand.Reader, data) + return signer.Sign(rand.New(rand.NewSource(time.Now().UnixNano())), data) } } return nil, errors.New("key not found") @@ -993,15 +993,15 @@ func withRemoteDockerHost(host string, sshServer *SSHServer) setUpEnvFn { } } -func generateKeys(t *testing.T) (privKeyRSA *rsa.PrivateKey, privKeyECDSA *ecdsa.PrivateKey) { +func generateClientKeys(t *testing.T) (privKeyRSA *rsa.PrivateKey, privKeyECDSA *ecdsa.PrivateKey) { var err error - privKeyRSA, err = rsa.GenerateKey(rand.Reader, 4096) + privKeyRSA, err = rsa.GenerateKey(rand.New(rand.NewSource(time.Now().UnixNano())), 2048) if err != nil { t.Fatal(err) } - privKeyECDSA, err = ecdsa.GenerateKey(elliptic.P384(), rand.Reader) + privKeyECDSA, err = ecdsa.GenerateKey(elliptic.P384(), rand.New(rand.NewSource(time.Now().UnixNano()))) if err != nil { t.Fatal(err) }