File tree 4 files changed +53
-3
lines changed 4 files changed +53
-3
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,16 @@ import (
7
7
"testing"
8
8
9
9
gc "gopkg.in/check.v1"
10
+
11
+ "github.com/juju/juju/pki"
12
+ pki_test "github.com/juju/juju/pki/test"
10
13
)
11
14
12
- func TestSuite (t * testing.T ) { gc .TestingT (t ) }
15
+ func TestSuite (t * testing.T ) {
16
+ if pki_test .OriginalDefaultKeyProfile == nil {
17
+ panic ("pki_test.OriginalDefaultKeyProfile not set" )
18
+ }
19
+ // Restore the correct key profile.
20
+ pki .DefaultKeyProfile = pki_test .OriginalDefaultKeyProfile
21
+ gc .TestingT (t )
22
+ }
Original file line number Diff line number Diff line change @@ -39,12 +39,12 @@ func ECDSAP384() (crypto.Signer, error) {
39
39
return ecdsa .GenerateKey (elliptic .P384 (), rand .Reader )
40
40
}
41
41
42
- // ECDSA384 returns a RSA 2048 private key
42
+ // RSA2048 returns a RSA 2048 private key
43
43
func RSA2048 () (crypto.Signer , error ) {
44
44
return rsa .GenerateKey (rand .Reader , 2048 )
45
45
}
46
46
47
- // ECDSA384 returns a RSA 3072 private key
47
+ // RSA3072 returns a RSA 3072 private key
48
48
func RSA3072 () (crypto.Signer , error ) {
49
49
return rsa .GenerateKey (rand .Reader , 3072 )
50
50
}
Original file line number Diff line number Diff line change
1
+ // Copyright 2020 Canonical Ltd.
2
+ // Licensed under the AGPLv3, see LICENCE file for details.
3
+
4
+ package test
5
+
6
+ import (
7
+ "crypto"
8
+ "crypto/rsa"
9
+ "flag"
10
+ "math/rand"
11
+
12
+ "github.com/juju/juju/pki"
13
+ )
14
+
15
+ var insecureRand = rand .New (rand .NewSource (0 ))
16
+
17
+ // InsecureKeyProfile for tests. Will panic if used outside tests.
18
+ func InsecureKeyProfile () (crypto.Signer , error ) {
19
+ if flag .Lookup ("test.v" ) == nil {
20
+ panic ("InsecureKeyProfile cannot be used outside tests" )
21
+ }
22
+ return rsa .GenerateKey (insecureRand , 512 )
23
+ }
24
+
25
+ // OriginalDefaultKeyProfile is the pre-patched pki.DefaultKeyProfile
26
+ // value.
27
+ var OriginalDefaultKeyProfile = pki .DefaultKeyProfile
28
+
29
+ func init () {
30
+ pki .DefaultKeyProfile = InsecureKeyProfile
31
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2020 Canonical Ltd.
2
+ // Licensed under the AGPLv3, see LICENCE file for details.
3
+
4
+ package testing
5
+
6
+ import (
7
+ // Force inclusion of pki/test for fast test keyprofiles.
8
+ _ "github.com/juju/juju/pki/test"
9
+ )
You can’t perform that action at this time.
0 commit comments