mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Don't use entropy for test
Use math/rand instead of crypto/rand, so entropy is not a blocker when running the tests.
This commit is contained in:
parent
e4c01f0595
commit
f38c91f906
2 changed files with 12 additions and 4 deletions
|
@ -1,9 +1,9 @@
|
||||||
package amp
|
package amp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package utls
|
package utls
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"crypto/x509/pkix"
|
"crypto/x509/pkix"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -26,7 +26,15 @@ func TestRoundTripper(t *testing.T) {
|
||||||
Convey("[Test]Set up http servers", t, func(c C) {
|
Convey("[Test]Set up http servers", t, func(c C) {
|
||||||
c.Convey("[Test]Generate Self-Signed Cert", func(c C) {
|
c.Convey("[Test]Generate Self-Signed Cert", func(c C) {
|
||||||
// Ported from https://gist.github.com/samuel/8b500ddd3f6118d052b5e6bc16bc4c09
|
// Ported from https://gist.github.com/samuel/8b500ddd3f6118d052b5e6bc16bc4c09
|
||||||
priv, err := rsa.GenerateKey(rand.Reader, 4096)
|
|
||||||
|
// note that we use the insecure math/rand here because some platforms
|
||||||
|
// fail the test suite at build time in Debian, due to entropy starvation.
|
||||||
|
// since that's not a problem at test time, we do *not* use a secure
|
||||||
|
// mechanism for key generation.
|
||||||
|
//
|
||||||
|
// DO NOT REUSE THIS CODE IN PRODUCTION, IT IS DANGEROUS
|
||||||
|
insecureRandReader := rand.New(rand.NewSource(1337))
|
||||||
|
priv, err := rsa.GenerateKey(insecureRandReader, 4096)
|
||||||
c.So(err, ShouldBeNil)
|
c.So(err, ShouldBeNil)
|
||||||
template := x509.Certificate{
|
template := x509.Certificate{
|
||||||
SerialNumber: big.NewInt(1),
|
SerialNumber: big.NewInt(1),
|
||||||
|
@ -40,7 +48,7 @@ func TestRoundTripper(t *testing.T) {
|
||||||
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
|
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
|
||||||
BasicConstraintsValid: true,
|
BasicConstraintsValid: true,
|
||||||
}
|
}
|
||||||
derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, priv.Public(), priv)
|
derBytes, err := x509.CreateCertificate(insecureRandReader, &template, &template, priv.Public(), priv)
|
||||||
c.So(err, ShouldBeNil)
|
c.So(err, ShouldBeNil)
|
||||||
selfSignedPrivateKey = priv
|
selfSignedPrivateKey = priv
|
||||||
selfSignedCert = derBytes
|
selfSignedCert = derBytes
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue