ssh/test: reset the random source before capturing a recording
If a recording file exists but is invalid for any reason, the random source may have already been used, resulting in a recording that cannot be replayed. Change-Id: Ib81aaf163f5783fede2c14a0ac10a8d2af6019c6 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/664917 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Filippo Valsorda <filippo@golang.org> Auto-Submit: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
committed by
Gopher Robot
parent
88199028d7
commit
9c1aa6af88
@@ -23,6 +23,7 @@ import (
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/sha3"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
@@ -412,6 +413,15 @@ func writeFile(path string, contents []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
// setDeterministicRandomSource sets a deterministic random source for the
|
||||
// provided ssh.Config. It is intended solely for use in test cases, as
|
||||
// deterministic randomness is insecure and should never be used in production
|
||||
// environments. A deterministic random source is required to enable consistent
|
||||
// testing against recorded session files.
|
||||
func setDeterministicRandomSource(config *ssh.Config) {
|
||||
config.Rand = sha3.NewShake128()
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args)
|
||||
|
||||
Reference in New Issue
Block a user