diff --git a/bccsp/sw/aes_test.go b/bccsp/sw/aes_test.go index de20497f175..37d442f2567 100644 --- a/bccsp/sw/aes_test.go +++ b/bccsp/sw/aes_test.go @@ -33,6 +33,7 @@ import ( // TestCBCPKCS7EncryptCBCPKCS7Decrypt encrypts using CBCPKCS7Encrypt and decrypts using CBCPKCS7Decrypt. func TestCBCPKCS7EncryptCBCPKCS7Decrypt(t *testing.T) { + t.Parallel() // Note: The purpose of this test is not to test AES-256 in CBC mode's strength // ... but rather to verify the code wrapping/unwrapping the cipher. @@ -55,11 +56,11 @@ func TestCBCPKCS7EncryptCBCPKCS7Decrypt(t *testing.T) { if string(ptext[:]) != string(decrypted[:]) { t.Fatal("Decrypt( Encrypt( ptext ) ) != ptext: Ciphertext decryption with the same key must result in the original plaintext!") } - } // TestPKCS7Padding verifies the PKCS#7 padding, using a human readable plaintext. func TestPKCS7Padding(t *testing.T) { + t.Parallel() // 0 byte/length ptext ptext := []byte("") @@ -109,7 +110,6 @@ func TestPKCS7Padding(t *testing.T) { if !bytes.Equal(result, expected) { t.Fatal("Padding error! Expected: '", expected, "', received: '", result, "'") } - } // aes.BlockSize length ptext @@ -126,11 +126,11 @@ func TestPKCS7Padding(t *testing.T) { if !bytes.Equal(expected, result) { t.Fatal("Padding error! Expected: '", expected, "', received: '", result, "'") } - } // TestPKCS7UnPadding verifies the PKCS#7 unpadding, using a human readable plaintext. func TestPKCS7UnPadding(t *testing.T) { + t.Parallel() // 0 byte/length ptext expected := []byte("") @@ -184,7 +184,6 @@ func TestPKCS7UnPadding(t *testing.T) { if !bytes.Equal(result, expected) { t.Fatal("UnPadding error! Expected: '", expected, "', received: '", result, "'") } - } // aes.BlockSize length ptext @@ -202,6 +201,7 @@ func TestPKCS7UnPadding(t *testing.T) { // TestCBCEncryptCBCPKCS7Decrypt_BlockSizeLengthPlaintext verifies that CBCPKCS7Decrypt returns an error // when attempting to decrypt ciphertext of an irreproducible length. func TestCBCEncryptCBCPKCS7Decrypt_BlockSizeLengthPlaintext(t *testing.T) { + t.Parallel() // One of the purposes of this test is to also document and clarify the expected behavior, i.e., that an extra // block is appended to the message at the padding stage, as per the spec of PKCS#7 v1.5 [see RFC-2315 p.21] @@ -225,6 +225,7 @@ func TestCBCEncryptCBCPKCS7Decrypt_BlockSizeLengthPlaintext(t *testing.T) { // TestCBCPKCS7EncryptCBCDecrypt_ExpectingCorruptMessage verifies that CBCDecrypt can decrypt the unpadded // version of the ciphertext, of a message of BlockSize length. func TestCBCPKCS7EncryptCBCDecrypt_ExpectingCorruptMessage(t *testing.T) { + t.Parallel() // One of the purposes of this test is to also document and clarify the expected behavior, i.e., that an extra // block is appended to the message at the padding stage, as per the spec of PKCS#7 v1.5 [see RFC-2315 p.21] @@ -253,11 +254,11 @@ func TestCBCPKCS7EncryptCBCDecrypt_ExpectingCorruptMessage(t *testing.T) { if !bytes.Equal(decrypted[aes.BlockSize:], bytes.Repeat([]byte{byte(aes.BlockSize)}, aes.BlockSize)) { t.Fatal("Expected extra block with padding in encrypted ptext", decrypted) } - } // TestCBCPKCS7Encrypt_EmptyPlaintext encrypts and pad an empty ptext. Verifying as well that the ciphertext length is as expected. func TestCBCPKCS7Encrypt_EmptyPlaintext(t *testing.T) { + t.Parallel() key := make([]byte, 32) rand.Reader.Read(key) @@ -285,6 +286,7 @@ func TestCBCPKCS7Encrypt_EmptyPlaintext(t *testing.T) { // TestCBCEncrypt_EmptyPlaintext encrypts an empty message. Verifying as well that the ciphertext length is as expected. func TestCBCEncrypt_EmptyPlaintext(t *testing.T) { + t.Parallel() key := make([]byte, 32) rand.Reader.Read(key) @@ -309,6 +311,7 @@ func TestCBCEncrypt_EmptyPlaintext(t *testing.T) { // TestCBCPKCS7Encrypt_VerifyRandomIVs encrypts twice with same key. The first 16 bytes should be different if IV is generated randomly. func TestCBCPKCS7Encrypt_VerifyRandomIVs(t *testing.T) { + t.Parallel() key := make([]byte, aes.BlockSize) rand.Reader.Read(key) @@ -341,6 +344,7 @@ func TestCBCPKCS7Encrypt_VerifyRandomIVs(t *testing.T) { // TestCBCPKCS7Encrypt_CorrectCiphertextLengthCheck verifies that the returned ciphertext lengths are as expected. func TestCBCPKCS7Encrypt_CorrectCiphertextLengthCheck(t *testing.T) { + t.Parallel() key := make([]byte, aes.BlockSize) rand.Reader.Read(key) @@ -365,6 +369,7 @@ func TestCBCPKCS7Encrypt_CorrectCiphertextLengthCheck(t *testing.T) { // TestCBCEncryptCBCDecrypt_KeyMismatch attempts to decrypt with a different key than the one used for encryption. func TestCBCEncryptCBCDecrypt_KeyMismatch(t *testing.T) { + t.Parallel() // Generate a random key key := make([]byte, aes.BlockSize) @@ -393,6 +398,7 @@ func TestCBCEncryptCBCDecrypt_KeyMismatch(t *testing.T) { // TestCBCEncryptCBCDecrypt encrypts with CBCEncrypt and decrypt with CBCDecrypt. func TestCBCEncryptCBCDecrypt(t *testing.T) { + t.Parallel() key := make([]byte, 32) rand.Reader.Read(key) @@ -417,6 +423,7 @@ func TestCBCEncryptCBCDecrypt(t *testing.T) { // TestCBCEncryptWithRandCBCDecrypt encrypts with CBCEncrypt using the passed prng and decrypt with CBCDecrypt. func TestCBCEncryptWithRandCBCDecrypt(t *testing.T) { + t.Parallel() key := make([]byte, 32) rand.Reader.Read(key) @@ -441,6 +448,7 @@ func TestCBCEncryptWithRandCBCDecrypt(t *testing.T) { // TestCBCEncryptWithIVCBCDecrypt encrypts with CBCEncrypt using the passed IV and decrypt with CBCDecrypt. func TestCBCEncryptWithIVCBCDecrypt(t *testing.T) { + t.Parallel() key := make([]byte, 32) rand.Reader.Read(key) @@ -469,6 +477,7 @@ func TestCBCEncryptWithIVCBCDecrypt(t *testing.T) { // TestAESRelatedUtilFunctions tests various functions commonly used in fabric wrt AES func TestAESRelatedUtilFunctions(t *testing.T) { + t.Parallel() key, err := GetRandomBytes(32) if err != nil { @@ -498,13 +507,13 @@ func TestAESRelatedUtilFunctions(t *testing.T) { if 0 != bytes.Compare(msg, msg2) { t.Fatalf("Wrong decryption output [%x][%x]", msg, msg2) } - } - } // TestVariousAESKeyEncoding tests some AES <-> PEM conversions func TestVariousAESKeyEncoding(t *testing.T) { + t.Parallel() + key, err := GetRandomBytes(32) if err != nil { t.Fatalf("Failed generating AES key [%s]", err) @@ -535,12 +544,16 @@ func TestVariousAESKeyEncoding(t *testing.T) { } func TestPkcs7UnPaddingInvalidInputs(t *testing.T) { + t.Parallel() + _, err := pkcs7UnPadding([]byte{1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}) assert.Error(t, err) assert.Equal(t, "Invalid pkcs7 padding (pad[i] != unpadding)", err.Error()) } func TestAESCBCEncryptInvalidInputs(t *testing.T) { + t.Parallel() + _, err := aesCBCEncrypt(nil, []byte{0, 1, 2, 3}) assert.Error(t, err) assert.Equal(t, "Invalid plaintext. It must be a multiple of the block size", err.Error()) @@ -550,6 +563,8 @@ func TestAESCBCEncryptInvalidInputs(t *testing.T) { } func TestAESCBCDecryptInvalidInputs(t *testing.T) { + t.Parallel() + _, err := aesCBCDecrypt([]byte{0}, []byte{1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}) assert.Error(t, err) @@ -564,6 +579,8 @@ func TestAESCBCDecryptInvalidInputs(t *testing.T) { // TestAESCBCPKCS7EncryptorDecrypt tests the integration of // aescbcpkcs7Encryptor and aescbcpkcs7Decryptor func TestAESCBCPKCS7EncryptorDecrypt(t *testing.T) { + t.Parallel() + raw, err := GetRandomBytes(32) assert.NoError(t, err) @@ -606,6 +623,8 @@ func TestAESCBCPKCS7EncryptorDecrypt(t *testing.T) { } func TestAESCBCPKCS7EncryptorWithIVSameCiphertext(t *testing.T) { + t.Parallel() + raw, err := GetRandomBytes(32) assert.NoError(t, err) @@ -630,6 +649,8 @@ func TestAESCBCPKCS7EncryptorWithIVSameCiphertext(t *testing.T) { } func TestAESCBCPKCS7EncryptorWithRandSameCiphertext(t *testing.T) { + t.Parallel() + raw, err := GetRandomBytes(32) assert.NoError(t, err) diff --git a/bccsp/sw/dummyks_test.go b/bccsp/sw/dummyks_test.go index a7a9c0f1156..4810a85b1d3 100644 --- a/bccsp/sw/dummyks_test.go +++ b/bccsp/sw/dummyks_test.go @@ -23,22 +23,30 @@ import ( ) func TestNewDummyKeyStore(t *testing.T) { + t.Parallel() + ks := NewDummyKeyStore() assert.NotNil(t, ks) } func TestDummyKeyStore_GetKey(t *testing.T) { + t.Parallel() + ks := NewDummyKeyStore() _, err := ks.GetKey([]byte{0, 1, 2, 3, 4}) assert.Error(t, err) } func TestDummyKeyStore_ReadOnly(t *testing.T) { + t.Parallel() + ks := NewDummyKeyStore() assert.True(t, ks.ReadOnly()) } func TestDummyKeyStore_StoreKey(t *testing.T) { + t.Parallel() + ks := NewDummyKeyStore() err := ks.StoreKey(&mocks.MockKey{}) assert.Error(t, err) diff --git a/bccsp/sw/ecdsa_test.go b/bccsp/sw/ecdsa_test.go index c2055e62657..2477f80558e 100644 --- a/bccsp/sw/ecdsa_test.go +++ b/bccsp/sw/ecdsa_test.go @@ -29,7 +29,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestSignECDSA(t *testing.T) { +func TestSignECDSABadParameter(t *testing.T) { // Generate a key lowLevelKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) assert.NoError(t, err) @@ -46,6 +46,8 @@ func TestSignECDSA(t *testing.T) { } func TestVerifyECDSA(t *testing.T) { + t.Parallel() + // Generate a key lowLevelKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) assert.NoError(t, err) @@ -77,6 +79,8 @@ func TestVerifyECDSA(t *testing.T) { } func TestEcdsaSignerSign(t *testing.T) { + t.Parallel() + signer := &ecdsaSigner{} verifierPrivateKey := &ecdsaPrivateKeyVerifier{} verifierPublicKey := &ecdsaPublicKeyKeyVerifier{} @@ -109,6 +113,8 @@ func TestEcdsaSignerSign(t *testing.T) { } func TestEcdsaPrivateKey(t *testing.T) { + t.Parallel() + lowLevelKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) assert.NoError(t, err) k := &ecdsaPrivateKey{lowLevelKey} @@ -141,6 +147,8 @@ func TestEcdsaPrivateKey(t *testing.T) { } func TestEcdsaPublicKey(t *testing.T) { + t.Parallel() + lowLevelKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) assert.NoError(t, err) k := &ecdsaPublicKey{&lowLevelKey.PublicKey} diff --git a/bccsp/sw/enc_test.go b/bccsp/sw/enc_test.go index 81ec70b6551..dc383df08de 100644 --- a/bccsp/sw/enc_test.go +++ b/bccsp/sw/enc_test.go @@ -27,6 +27,8 @@ import ( ) func TestEncrypt(t *testing.T) { + t.Parallel() + expectedKey := &mocks2.MockKey{} expectedPlaintext := []byte{1, 2, 3, 4} expectedOpts := &mocks2.EncrypterOpts{} diff --git a/bccsp/sw/fileks_test.go b/bccsp/sw/fileks_test.go index b91c6695291..7f9f6224af2 100644 --- a/bccsp/sw/fileks_test.go +++ b/bccsp/sw/fileks_test.go @@ -17,13 +17,22 @@ package sw import ( "fmt" + "io/ioutil" "os" "path/filepath" "testing" + + "github.com/stretchr/testify/assert" ) func TestInvalidStoreKey(t *testing.T) { - ks, err := NewFileBasedKeyStore(nil, filepath.Join(os.TempDir(), "bccspks"), false) + t.Parallel() + + tempDir, err := ioutil.TempDir("", "bccspks") + assert.NoError(t, err) + defer os.RemoveAll(tempDir) + + ks, err := NewFileBasedKeyStore(nil, filepath.Join(tempDir, "bccspks"), false) if err != nil { fmt.Printf("Failed initiliazing KeyStore [%s]", err) os.Exit(-1) diff --git a/bccsp/sw/hash_test.go b/bccsp/sw/hash_test.go index a3ffa9cb60a..984333614cb 100644 --- a/bccsp/sw/hash_test.go +++ b/bccsp/sw/hash_test.go @@ -28,6 +28,8 @@ import ( ) func TestHash(t *testing.T) { + t.Parallel() + expectetMsg := []byte{1, 2, 3, 4} expectedOpts := &mocks2.HashOpts{} expectetValue := []byte{1, 2, 3, 4, 5} @@ -59,6 +61,8 @@ func TestHash(t *testing.T) { } func TestGetHash(t *testing.T) { + t.Parallel() + expectedOpts := &mocks2.HashOpts{} expectetValue := sha256.New() expectedErr := errors.New("Expected Error") @@ -87,6 +91,8 @@ func TestGetHash(t *testing.T) { } func TestHasher(t *testing.T) { + t.Parallel() + hasher := &hasher{hash: sha256.New} msg := []byte("Hello World") diff --git a/bccsp/sw/impl_test.go b/bccsp/sw/impl_test.go index 58e4fde11ac..8192fa1f293 100644 --- a/bccsp/sw/impl_test.go +++ b/bccsp/sw/impl_test.go @@ -29,6 +29,7 @@ import ( "encoding/asn1" "fmt" "hash" + "io/ioutil" "math/big" "net" "os" @@ -38,13 +39,13 @@ import ( "github.com/hyperledger/fabric/bccsp" "github.com/hyperledger/fabric/bccsp/signer" "github.com/hyperledger/fabric/bccsp/utils" + "github.com/stretchr/testify/assert" "golang.org/x/crypto/sha3" ) var ( - currentKS bccsp.KeyStore - currentBCCSP bccsp.BCCSP currentTestConfig testConfig + tempDir string ) type testConfig struct { @@ -52,14 +53,17 @@ type testConfig struct { hashFamily string } -func TestMain(m *testing.M) { - ks, err := NewFileBasedKeyStore(nil, os.TempDir(), false) - if err != nil { - fmt.Printf("Failed initiliazing KeyStore [%s]", err) - os.Exit(-1) - } - currentKS = ks +func (tc testConfig) Provider(t *testing.T) (bccsp.BCCSP, bccsp.KeyStore, func()) { + td, err := ioutil.TempDir(tempDir, "test") + assert.NoError(t, err) + ks, err := NewFileBasedKeyStore(nil, td, false) + assert.NoError(t, err) + p, err := New(tc.securityLevel, tc.hashFamily, ks) + assert.NoError(t, err) + return p, ks, func() { os.RemoveAll(td) } +} +func TestMain(m *testing.M) { tests := []testConfig{ {256, "SHA2"}, {256, "SHA3"}, @@ -67,14 +71,16 @@ func TestMain(m *testing.M) { {384, "SHA3"}, } + var err error + tempDir, err = ioutil.TempDir("", "bccsp-sw") + if err != nil { + fmt.Printf("Failed to create temporary directory: %s\n\n", err) + os.Exit(-1) + } + defer os.RemoveAll(tempDir) + for _, config := range tests { - var err error currentTestConfig = config - currentBCCSP, err = New(config.securityLevel, config.hashFamily, currentKS) - if err != nil { - fmt.Printf("Failed initiliazing BCCSP at [%d, %s]: [%s]", config.securityLevel, config.hashFamily, err) - os.Exit(-1) - } ret := m.Run() if ret != 0 { fmt.Printf("Failed testing at [%d, %s]", config.securityLevel, config.hashFamily) @@ -85,7 +91,11 @@ func TestMain(m *testing.M) { } func TestInvalidNewParameter(t *testing.T) { - r, err := New(0, "SHA2", currentKS) + t.Parallel() + _, ks, cleanup := currentTestConfig.Provider(t) + defer cleanup() + + r, err := New(0, "SHA2", ks) if err == nil { t.Fatal("Error should be different from nil in this case") } @@ -93,7 +103,7 @@ func TestInvalidNewParameter(t *testing.T) { t.Fatal("Return value should be equal to nil in this case") } - r, err = New(256, "SHA8", currentKS) + r, err = New(256, "SHA8", ks) if err == nil { t.Fatal("Error should be different from nil in this case") } @@ -127,7 +137,11 @@ func TestInvalidNewParameter(t *testing.T) { } func TestInvalidSKI(t *testing.T) { - k, err := currentBCCSP.GetKey(nil) + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() + + k, err := provider.GetKey(nil) if err == nil { t.Fatal("Error should be different from nil in this case") } @@ -135,7 +149,7 @@ func TestInvalidSKI(t *testing.T) { t.Fatal("Return value should be equal to nil in this case") } - k, err = currentBCCSP.GetKey([]byte{0, 1, 2, 3, 4, 5, 6}) + k, err = provider.GetKey([]byte{0, 1, 2, 3, 4, 5, 6}) if err == nil { t.Fatal("Error should be different from nil in this case") } @@ -145,8 +159,12 @@ func TestInvalidSKI(t *testing.T) { } func TestKeyGenECDSAOpts(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() + // Curve P256 - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAP256KeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.ECDSAP256KeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA P256 key [%s]", err) } @@ -172,7 +190,7 @@ func TestKeyGenECDSAOpts(t *testing.T) { } // Curve P384 - k, err = currentBCCSP.KeyGen(&bccsp.ECDSAP384KeyGenOpts{Temporary: false}) + k, err = provider.KeyGen(&bccsp.ECDSAP384KeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA P384 key [%s]", err) } @@ -200,8 +218,12 @@ func TestKeyGenECDSAOpts(t *testing.T) { } func TestKeyGenRSAOpts(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() + // 1024 - k, err := currentBCCSP.KeyGen(&bccsp.RSA1024KeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.RSA1024KeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating RSA 1024 key [%s]", err) } @@ -227,7 +249,7 @@ func TestKeyGenRSAOpts(t *testing.T) { } // 2048 - k, err = currentBCCSP.KeyGen(&bccsp.RSA2048KeyGenOpts{Temporary: false}) + k, err = provider.KeyGen(&bccsp.RSA2048KeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating RSA 2048 key [%s]", err) } @@ -255,7 +277,7 @@ func TestKeyGenRSAOpts(t *testing.T) { /* // Skipping these tests because they take too much time to run. // 3072 - k, err = currentBCCSP.KeyGen(&bccsp.RSA3072KeyGenOpts{Temporary: false}) + k, err = provider.KeyGen(&bccsp.RSA3072KeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating RSA 3072 key [%s]", err) } @@ -281,7 +303,7 @@ func TestKeyGenRSAOpts(t *testing.T) { } // 4096 - k, err = currentBCCSP.KeyGen(&bccsp.RSA4096KeyGenOpts{Temporary: false}) + k, err = provider.KeyGen(&bccsp.RSA4096KeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating RSA 4096 key [%s]", err) } @@ -309,8 +331,12 @@ func TestKeyGenRSAOpts(t *testing.T) { } func TestKeyGenAESOpts(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() + // AES 128 - k, err := currentBCCSP.KeyGen(&bccsp.AES128KeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.AES128KeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating AES 128 key [%s]", err) } @@ -330,7 +356,7 @@ func TestKeyGenAESOpts(t *testing.T) { } // AES 192 - k, err = currentBCCSP.KeyGen(&bccsp.AES192KeyGenOpts{Temporary: false}) + k, err = provider.KeyGen(&bccsp.AES192KeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating AES 192 key [%s]", err) } @@ -350,7 +376,7 @@ func TestKeyGenAESOpts(t *testing.T) { } // AES 256 - k, err = currentBCCSP.KeyGen(&bccsp.AES256KeyGenOpts{Temporary: false}) + k, err = provider.KeyGen(&bccsp.AES256KeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating AES 256 key [%s]", err) } @@ -371,7 +397,11 @@ func TestKeyGenAESOpts(t *testing.T) { } func TestECDSAKeyGenEphemeral(t *testing.T) { - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: true}) + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() + + k, err := provider.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: true}) if err != nil { t.Fatalf("Failed generating ECDSA key [%s]", err) } @@ -401,8 +431,11 @@ func TestECDSAKeyGenEphemeral(t *testing.T) { } func TestECDSAPrivateKeySKI(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA key [%s]", err) } @@ -414,8 +447,11 @@ func TestECDSAPrivateKeySKI(t *testing.T) { } func TestECDSAKeyGenNonEphemeral(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA key [%s]", err) } @@ -431,13 +467,16 @@ func TestECDSAKeyGenNonEphemeral(t *testing.T) { } func TestECDSAGetKeyBySKI(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA key [%s]", err) } - k2, err := currentBCCSP.GetKey(k.SKI()) + k2, err := provider.GetKey(k.SKI()) if err != nil { t.Fatalf("Failed getting ECDSA key [%s]", err) } @@ -458,8 +497,11 @@ func TestECDSAGetKeyBySKI(t *testing.T) { } func TestECDSAPublicKeyFromPrivateKey(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA key [%s]", err) } @@ -480,8 +522,11 @@ func TestECDSAPublicKeyFromPrivateKey(t *testing.T) { } func TestECDSAPublicKeyBytes(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA key [%s]", err) } @@ -501,8 +546,11 @@ func TestECDSAPublicKeyBytes(t *testing.T) { } func TestECDSAPublicKeySKI(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA key [%s]", err) } @@ -519,8 +567,11 @@ func TestECDSAPublicKeySKI(t *testing.T) { } func TestECDSAKeyReRand(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA key [%s]", err) } @@ -528,7 +579,7 @@ func TestECDSAKeyReRand(t *testing.T) { t.Fatal("Failed re-randomizing ECDSA key. Re-randomized Key must be different from nil") } - reRandomizedKey, err := currentBCCSP.KeyDeriv(k, &bccsp.ECDSAReRandKeyOpts{Temporary: false, Expansion: []byte{1}}) + reRandomizedKey, err := provider.KeyDeriv(k, &bccsp.ECDSAReRandKeyOpts{Temporary: false, Expansion: []byte{1}}) if err != nil { t.Fatalf("Failed re-randomizing ECDSA key [%s]", err) } @@ -547,7 +598,7 @@ func TestECDSAKeyReRand(t *testing.T) { t.Fatal("Failed re-randomizing ECDSA key. Re-randomized Key must be different from nil") } - reRandomizedKey2, err := currentBCCSP.KeyDeriv(k2, &bccsp.ECDSAReRandKeyOpts{Temporary: false, Expansion: []byte{1}}) + reRandomizedKey2, err := provider.KeyDeriv(k2, &bccsp.ECDSAReRandKeyOpts{Temporary: false, Expansion: []byte{1}}) if err != nil { t.Fatalf("Failed re-randomizing ECDSA key [%s]", err) } @@ -565,20 +616,23 @@ func TestECDSAKeyReRand(t *testing.T) { } func TestECDSASign(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA key [%s]", err) } msg := []byte("Hello World") - digest, err := currentBCCSP.Hash(msg, &bccsp.SHAOpts{}) + digest, err := provider.Hash(msg, &bccsp.SHAOpts{}) if err != nil { t.Fatalf("Failed computing HASH [%s]", err) } - signature, err := currentBCCSP.Sign(k, digest, nil) + signature, err := provider.Sign(k, digest, nil) if err != nil { t.Fatalf("Failed generating ECDSA signature [%s]", err) } @@ -588,25 +642,28 @@ func TestECDSASign(t *testing.T) { } func TestECDSAVerify(t *testing.T) { + t.Parallel() + provider, ks, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA key [%s]", err) } msg := []byte("Hello World") - digest, err := currentBCCSP.Hash(msg, &bccsp.SHAOpts{}) + digest, err := provider.Hash(msg, &bccsp.SHAOpts{}) if err != nil { t.Fatalf("Failed computing HASH [%s]", err) } - signature, err := currentBCCSP.Sign(k, digest, nil) + signature, err := provider.Sign(k, digest, nil) if err != nil { t.Fatalf("Failed generating ECDSA signature [%s]", err) } - valid, err := currentBCCSP.Verify(k, signature, digest, nil) + valid, err := provider.Verify(k, signature, digest, nil) if err != nil { t.Fatalf("Failed verifying ECDSA signature [%s]", err) } @@ -619,7 +676,7 @@ func TestECDSAVerify(t *testing.T) { t.Fatalf("Failed getting corresponding public key [%s]", err) } - valid, err = currentBCCSP.Verify(pk, signature, digest, nil) + valid, err = provider.Verify(pk, signature, digest, nil) if err != nil { t.Fatalf("Failed verifying ECDSA signature [%s]", err) } @@ -628,17 +685,17 @@ func TestECDSAVerify(t *testing.T) { } // Store public key - err = currentKS.StoreKey(pk) + err = ks.StoreKey(pk) if err != nil { t.Fatalf("Failed storing corresponding public key [%s]", err) } - pk2, err := currentKS.GetKey(pk.SKI()) + pk2, err := ks.GetKey(pk.SKI()) if err != nil { t.Fatalf("Failed retrieving corresponding public key [%s]", err) } - valid, err = currentBCCSP.Verify(pk2, signature, digest, nil) + valid, err = provider.Verify(pk2, signature, digest, nil) if err != nil { t.Fatalf("Failed verifying ECDSA signature [%s]", err) } @@ -648,30 +705,33 @@ func TestECDSAVerify(t *testing.T) { } func TestECDSAKeyDeriv(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA key [%s]", err) } - reRandomizedKey, err := currentBCCSP.KeyDeriv(k, &bccsp.ECDSAReRandKeyOpts{Temporary: false, Expansion: []byte{1}}) + reRandomizedKey, err := provider.KeyDeriv(k, &bccsp.ECDSAReRandKeyOpts{Temporary: false, Expansion: []byte{1}}) if err != nil { t.Fatalf("Failed re-randomizing ECDSA key [%s]", err) } msg := []byte("Hello World") - digest, err := currentBCCSP.Hash(msg, &bccsp.SHAOpts{}) + digest, err := provider.Hash(msg, &bccsp.SHAOpts{}) if err != nil { t.Fatalf("Failed computing HASH [%s]", err) } - signature, err := currentBCCSP.Sign(reRandomizedKey, digest, nil) + signature, err := provider.Sign(reRandomizedKey, digest, nil) if err != nil { t.Fatalf("Failed generating ECDSA signature [%s]", err) } - valid, err := currentBCCSP.Verify(reRandomizedKey, signature, digest, nil) + valid, err := provider.Verify(reRandomizedKey, signature, digest, nil) if err != nil { t.Fatalf("Failed verifying ECDSA signature [%s]", err) } @@ -681,9 +741,12 @@ func TestECDSAKeyDeriv(t *testing.T) { } func TestECDSAKeyImportFromExportedKey(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() // Generate an ECDSA key - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA key [%s]", err) } @@ -700,7 +763,7 @@ func TestECDSAKeyImportFromExportedKey(t *testing.T) { } // Import the exported public key - pk2, err := currentBCCSP.KeyImport(pkRaw, &bccsp.ECDSAPKIXPublicKeyImportOpts{Temporary: false}) + pk2, err := provider.KeyImport(pkRaw, &bccsp.ECDSAPKIXPublicKeyImportOpts{Temporary: false}) if err != nil { t.Fatalf("Failed importing ECDSA public key [%s]", err) } @@ -711,17 +774,17 @@ func TestECDSAKeyImportFromExportedKey(t *testing.T) { // Sign and verify with the imported public key msg := []byte("Hello World") - digest, err := currentBCCSP.Hash(msg, &bccsp.SHAOpts{}) + digest, err := provider.Hash(msg, &bccsp.SHAOpts{}) if err != nil { t.Fatalf("Failed computing HASH [%s]", err) } - signature, err := currentBCCSP.Sign(k, digest, nil) + signature, err := provider.Sign(k, digest, nil) if err != nil { t.Fatalf("Failed generating ECDSA signature [%s]", err) } - valid, err := currentBCCSP.Verify(pk2, signature, digest, nil) + valid, err := provider.Verify(pk2, signature, digest, nil) if err != nil { t.Fatalf("Failed verifying ECDSA signature [%s]", err) } @@ -731,9 +794,12 @@ func TestECDSAKeyImportFromExportedKey(t *testing.T) { } func TestECDSAKeyImportFromECDSAPublicKey(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() // Generate an ECDSA key - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA key [%s]", err) } @@ -755,7 +821,7 @@ func TestECDSAKeyImportFromECDSAPublicKey(t *testing.T) { } // Import the ecdsa.PublicKey - pk2, err := currentBCCSP.KeyImport(pub, &bccsp.ECDSAGoPublicKeyImportOpts{Temporary: false}) + pk2, err := provider.KeyImport(pub, &bccsp.ECDSAGoPublicKeyImportOpts{Temporary: false}) if err != nil { t.Fatalf("Failed importing ECDSA public key [%s]", err) } @@ -766,17 +832,17 @@ func TestECDSAKeyImportFromECDSAPublicKey(t *testing.T) { // Sign and verify with the imported public key msg := []byte("Hello World") - digest, err := currentBCCSP.Hash(msg, &bccsp.SHAOpts{}) + digest, err := provider.Hash(msg, &bccsp.SHAOpts{}) if err != nil { t.Fatalf("Failed computing HASH [%s]", err) } - signature, err := currentBCCSP.Sign(k, digest, nil) + signature, err := provider.Sign(k, digest, nil) if err != nil { t.Fatalf("Failed generating ECDSA signature [%s]", err) } - valid, err := currentBCCSP.Verify(pk2, signature, digest, nil) + valid, err := provider.Verify(pk2, signature, digest, nil) if err != nil { t.Fatalf("Failed verifying ECDSA signature [%s]", err) } @@ -786,6 +852,9 @@ func TestECDSAKeyImportFromECDSAPublicKey(t *testing.T) { } func TestECDSAKeyImportFromECDSAPrivateKey(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() // Generate an ECDSA key, default is P256 key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) @@ -799,7 +868,7 @@ func TestECDSAKeyImportFromECDSAPrivateKey(t *testing.T) { t.Fatalf("Failed converting raw to ecdsa.PrivateKey [%s]", err) } - sk, err := currentBCCSP.KeyImport(priv, &bccsp.ECDSAPrivateKeyImportOpts{Temporary: false}) + sk, err := provider.KeyImport(priv, &bccsp.ECDSAPrivateKeyImportOpts{Temporary: false}) if err != nil { t.Fatalf("Failed importing ECDSA private key [%s]", err) } @@ -813,7 +882,7 @@ func TestECDSAKeyImportFromECDSAPrivateKey(t *testing.T) { t.Fatalf("Failed converting raw to ecdsa.PublicKey [%s]", err) } - pk, err := currentBCCSP.KeyImport(pub, &bccsp.ECDSAPKIXPublicKeyImportOpts{Temporary: false}) + pk, err := provider.KeyImport(pub, &bccsp.ECDSAPKIXPublicKeyImportOpts{Temporary: false}) if err != nil { t.Fatalf("Failed importing ECDSA public key [%s]", err) @@ -825,17 +894,17 @@ func TestECDSAKeyImportFromECDSAPrivateKey(t *testing.T) { // Sign and verify with the imported public key msg := []byte("Hello World") - digest, err := currentBCCSP.Hash(msg, &bccsp.SHAOpts{}) + digest, err := provider.Hash(msg, &bccsp.SHAOpts{}) if err != nil { t.Fatalf("Failed computing HASH [%s]", err) } - signature, err := currentBCCSP.Sign(sk, digest, nil) + signature, err := provider.Sign(sk, digest, nil) if err != nil { t.Fatalf("Failed generating ECDSA signature [%s]", err) } - valid, err := currentBCCSP.Verify(pk, signature, digest, nil) + valid, err := provider.Verify(pk, signature, digest, nil) if err != nil { t.Fatalf("Failed verifying ECDSA signature [%s]", err) } @@ -845,9 +914,12 @@ func TestECDSAKeyImportFromECDSAPrivateKey(t *testing.T) { } func TestKeyImportFromX509ECDSAPublicKey(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() // Generate an ECDSA key - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA key [%s]", err) } @@ -909,7 +981,7 @@ func TestKeyImportFromX509ECDSAPublicKey(t *testing.T) { }, } - cryptoSigner, err := signer.New(currentBCCSP, k) + cryptoSigner, err := signer.New(provider, k) if err != nil { t.Fatalf("Failed initializing CyrptoSigner [%s]", err) } @@ -941,7 +1013,7 @@ func TestKeyImportFromX509ECDSAPublicKey(t *testing.T) { } // Import the certificate's public key - pk2, err := currentBCCSP.KeyImport(cert, &bccsp.X509PublicKeyImportOpts{Temporary: false}) + pk2, err := provider.KeyImport(cert, &bccsp.X509PublicKeyImportOpts{Temporary: false}) if err != nil { t.Fatalf("Failed importing ECDSA public key [%s]", err) @@ -953,17 +1025,17 @@ func TestKeyImportFromX509ECDSAPublicKey(t *testing.T) { // Sign and verify with the imported public key msg := []byte("Hello World") - digest, err := currentBCCSP.Hash(msg, &bccsp.SHAOpts{}) + digest, err := provider.Hash(msg, &bccsp.SHAOpts{}) if err != nil { t.Fatalf("Failed computing HASH [%s]", err) } - signature, err := currentBCCSP.Sign(k, digest, nil) + signature, err := provider.Sign(k, digest, nil) if err != nil { t.Fatalf("Failed generating ECDSA signature [%s]", err) } - valid, err := currentBCCSP.Verify(pk2, signature, digest, nil) + valid, err := provider.Verify(pk2, signature, digest, nil) if err != nil { t.Fatalf("Failed verifying ECDSA signature [%s]", err) } @@ -973,6 +1045,8 @@ func TestKeyImportFromX509ECDSAPublicKey(t *testing.T) { } func TestECDSASignatureEncoding(t *testing.T) { + t.Parallel() + v := []byte{0x30, 0x07, 0x02, 0x01, 0x8F, 0x02, 0x02, 0xff, 0xf1} _, err := asn1.Unmarshal(v, &utils.ECDSASignature{}) if err == nil { @@ -1011,20 +1085,24 @@ func TestECDSASignatureEncoding(t *testing.T) { } func TestECDSALowS(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() + // Ensure that signature with low-S are generated - k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating ECDSA key [%s]", err) } msg := []byte("Hello World") - digest, err := currentBCCSP.Hash(msg, &bccsp.SHAOpts{}) + digest, err := provider.Hash(msg, &bccsp.SHAOpts{}) if err != nil { t.Fatalf("Failed computing HASH [%s]", err) } - signature, err := currentBCCSP.Sign(k, digest, nil) + signature, err := provider.Sign(k, digest, nil) if err != nil { t.Fatalf("Failed generating ECDSA signature [%s]", err) } @@ -1038,7 +1116,7 @@ func TestECDSALowS(t *testing.T) { t.Fatal("Invalid signature. It must have low-S") } - valid, err := currentBCCSP.Verify(k, signature, digest, nil) + valid, err := provider.Verify(k, signature, digest, nil) if err != nil { t.Fatalf("Failed verifying ECDSA signature [%s]", err) } @@ -1064,7 +1142,7 @@ func TestECDSALowS(t *testing.T) { t.Fatalf("Failing unmarshalling signature [%s]", err) } - valid, err = currentBCCSP.Verify(k, sig, digest, nil) + valid, err = provider.Verify(k, sig, digest, nil) if err == nil { t.Fatal("Failed verifying ECDSA signature. It must fail for a signature with high-S") } @@ -1074,8 +1152,11 @@ func TestECDSALowS(t *testing.T) { } func TestAESKeyGen(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating AES_256 key [%s]", err) } @@ -1099,13 +1180,16 @@ func TestAESKeyGen(t *testing.T) { } func TestAESEncrypt(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating AES_256 key [%s]", err) } - ct, err := currentBCCSP.Encrypt(k, []byte("Hello World"), &bccsp.AESCBCPKCS7ModeOpts{}) + ct, err := provider.Encrypt(k, []byte("Hello World"), &bccsp.AESCBCPKCS7ModeOpts{}) if err != nil { t.Fatalf("Failed encrypting [%s]", err) } @@ -1115,20 +1199,23 @@ func TestAESEncrypt(t *testing.T) { } func TestAESDecrypt(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating AES_256 key [%s]", err) } msg := []byte("Hello World") - ct, err := currentBCCSP.Encrypt(k, msg, &bccsp.AESCBCPKCS7ModeOpts{}) + ct, err := provider.Encrypt(k, msg, &bccsp.AESCBCPKCS7ModeOpts{}) if err != nil { t.Fatalf("Failed encrypting [%s]", err) } - pt, err := currentBCCSP.Decrypt(k, ct, bccsp.AESCBCPKCS7ModeOpts{}) + pt, err := provider.Decrypt(k, ct, bccsp.AESCBCPKCS7ModeOpts{}) if err != nil { t.Fatalf("Failed decrypting [%s]", err) } @@ -1142,13 +1229,16 @@ func TestAESDecrypt(t *testing.T) { } func TestHMACTruncated256KeyDerivOverAES256Key(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating AES_256 key [%s]", err) } - hmcaedKey, err := currentBCCSP.KeyDeriv(k, &bccsp.HMACTruncated256AESDeriveKeyOpts{Temporary: false, Arg: []byte{1}}) + hmcaedKey, err := provider.KeyDeriv(k, &bccsp.HMACTruncated256AESDeriveKeyOpts{Temporary: false, Arg: []byte{1}}) if err != nil { t.Fatalf("Failed HMACing AES_256 key [%s]", err) } @@ -1171,12 +1261,12 @@ func TestHMACTruncated256KeyDerivOverAES256Key(t *testing.T) { msg := []byte("Hello World") - ct, err := currentBCCSP.Encrypt(hmcaedKey, msg, &bccsp.AESCBCPKCS7ModeOpts{}) + ct, err := provider.Encrypt(hmcaedKey, msg, &bccsp.AESCBCPKCS7ModeOpts{}) if err != nil { t.Fatalf("Failed encrypting [%s]", err) } - pt, err := currentBCCSP.Decrypt(hmcaedKey, ct, bccsp.AESCBCPKCS7ModeOpts{}) + pt, err := provider.Decrypt(hmcaedKey, ct, bccsp.AESCBCPKCS7ModeOpts{}) if err != nil { t.Fatalf("Failed decrypting [%s]", err) } @@ -1187,17 +1277,19 @@ func TestHMACTruncated256KeyDerivOverAES256Key(t *testing.T) { if !bytes.Equal(msg, pt) { t.Fatalf("Failed decrypting. Decrypted plaintext is different from the original. [%x][%x]", msg, pt) } - } func TestHMACKeyDerivOverAES256Key(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating AES_256 key [%s]", err) } - hmcaedKey, err := currentBCCSP.KeyDeriv(k, &bccsp.HMACDeriveKeyOpts{Temporary: false, Arg: []byte{1}}) + hmcaedKey, err := provider.KeyDeriv(k, &bccsp.HMACDeriveKeyOpts{Temporary: false, Arg: []byte{1}}) if err != nil { t.Fatalf("Failed HMACing AES_256 key [%s]", err) @@ -1221,13 +1313,16 @@ func TestHMACKeyDerivOverAES256Key(t *testing.T) { } func TestAES256KeyImport(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() raw, err := GetRandomBytes(32) if err != nil { t.Fatalf("Failed generating AES key [%s]", err) } - k, err := currentBCCSP.KeyImport(raw, &bccsp.AES256ImportKeyOpts{Temporary: false}) + k, err := provider.KeyImport(raw, &bccsp.AES256ImportKeyOpts{Temporary: false}) if err != nil { t.Fatalf("Failed importing AES_256 key [%s]", err) } @@ -1250,12 +1345,12 @@ func TestAES256KeyImport(t *testing.T) { msg := []byte("Hello World") - ct, err := currentBCCSP.Encrypt(k, msg, &bccsp.AESCBCPKCS7ModeOpts{}) + ct, err := provider.Encrypt(k, msg, &bccsp.AESCBCPKCS7ModeOpts{}) if err != nil { t.Fatalf("Failed encrypting [%s]", err) } - pt, err := currentBCCSP.Decrypt(k, ct, bccsp.AESCBCPKCS7ModeOpts{}) + pt, err := provider.Decrypt(k, ct, bccsp.AESCBCPKCS7ModeOpts{}) if err != nil { t.Fatalf("Failed decrypting [%s]", err) } @@ -1269,26 +1364,32 @@ func TestAES256KeyImport(t *testing.T) { } func TestAES256KeyImportBadPaths(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - _, err := currentBCCSP.KeyImport(nil, &bccsp.AES256ImportKeyOpts{Temporary: false}) + _, err := provider.KeyImport(nil, &bccsp.AES256ImportKeyOpts{Temporary: false}) if err == nil { t.Fatal("Failed importing key. Must fail on importing nil key") } - _, err = currentBCCSP.KeyImport([]byte{1}, &bccsp.AES256ImportKeyOpts{Temporary: false}) + _, err = provider.KeyImport([]byte{1}, &bccsp.AES256ImportKeyOpts{Temporary: false}) if err == nil { t.Fatal("Failed importing key. Must fail on importing a key with an invalid length") } } func TestAES256KeyGenSKI(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating AES_256 key [%s]", err) } - k2, err := currentBCCSP.GetKey(k.SKI()) + k2, err := provider.GetKey(k.SKI()) if err != nil { t.Fatalf("Failed getting AES_256 key [%s]", err) } @@ -1306,10 +1407,12 @@ func TestAES256KeyGenSKI(t *testing.T) { if !bytes.Equal(k.SKI(), k2.SKI()) { t.Fatalf("SKIs are different [%x]!=[%x]", k.SKI(), k2.SKI()) } - } func TestSHA(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() for i := 0; i < 100; i++ { b, err := GetRandomBytes(i) @@ -1317,7 +1420,7 @@ func TestSHA(t *testing.T) { t.Fatalf("Failed getting random bytes [%s]", err) } - h1, err := currentBCCSP.Hash(b, &bccsp.SHAOpts{}) + h1, err := provider.Hash(b, &bccsp.SHAOpts{}) if err != nil { t.Fatalf("Failed computing SHA [%s]", err) } @@ -1355,7 +1458,11 @@ func TestSHA(t *testing.T) { } func TestRSAKeyGenEphemeral(t *testing.T) { - k, err := currentBCCSP.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: true}) + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() + + k, err := provider.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: true}) if err != nil { t.Fatalf("Failed generating RSA key [%s]", err) } @@ -1384,10 +1491,11 @@ func TestRSAKeyGenEphemeral(t *testing.T) { if len(b) != 0 { t.Fatal("Secret keys cannot be exported. It must be nil") } - } func TestRSAPublicKeyInvalidBytes(t *testing.T) { + t.Parallel() + rsaKey := &rsaPublicKey{nil} b, err := rsaKey.Bytes() if err == nil { @@ -1399,8 +1507,11 @@ func TestRSAPublicKeyInvalidBytes(t *testing.T) { } func TestRSAPrivateKeySKI(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating RSA key [%s]", err) } @@ -1412,8 +1523,11 @@ func TestRSAPrivateKeySKI(t *testing.T) { } func TestRSAKeyGenNonEphemeral(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating RSA key [%s]", err) } @@ -1429,13 +1543,16 @@ func TestRSAKeyGenNonEphemeral(t *testing.T) { } func TestRSAGetKeyBySKI(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating RSA key [%s]", err) } - k2, err := currentBCCSP.GetKey(k.SKI()) + k2, err := provider.GetKey(k.SKI()) if err != nil { t.Fatalf("Failed getting RSA key [%s]", err) } @@ -1456,8 +1573,11 @@ func TestRSAGetKeyBySKI(t *testing.T) { } func TestRSAPublicKeyFromPrivateKey(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating RSA key [%s]", err) } @@ -1478,8 +1598,11 @@ func TestRSAPublicKeyFromPrivateKey(t *testing.T) { } func TestRSAPublicKeyBytes(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating RSA key [%s]", err) } @@ -1499,8 +1622,11 @@ func TestRSAPublicKeyBytes(t *testing.T) { } func TestRSAPublicKeySKI(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating RSA key [%s]", err) } @@ -1517,20 +1643,23 @@ func TestRSAPublicKeySKI(t *testing.T) { } func TestRSASign(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating RSA key [%s]", err) } msg := []byte("Hello World") - digest, err := currentBCCSP.Hash(msg, &bccsp.SHAOpts{}) + digest, err := provider.Hash(msg, &bccsp.SHAOpts{}) if err != nil { t.Fatalf("Failed computing HASH [%s]", err) } - signature, err := currentBCCSP.Sign(k, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) + signature, err := provider.Sign(k, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) if err != nil { t.Fatalf("Failed generating RSA signature [%s]", err) } @@ -1540,25 +1669,28 @@ func TestRSASign(t *testing.T) { } func TestRSAVerify(t *testing.T) { + t.Parallel() + provider, ks, cleanup := currentTestConfig.Provider(t) + defer cleanup() - k, err := currentBCCSP.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating RSA key [%s]", err) } msg := []byte("Hello World") - digest, err := currentBCCSP.Hash(msg, &bccsp.SHAOpts{}) + digest, err := provider.Hash(msg, &bccsp.SHAOpts{}) if err != nil { t.Fatalf("Failed computing HASH [%s]", err) } - signature, err := currentBCCSP.Sign(k, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) + signature, err := provider.Sign(k, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) if err != nil { t.Fatalf("Failed generating RSA signature [%s]", err) } - valid, err := currentBCCSP.Verify(k, signature, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) + valid, err := provider.Verify(k, signature, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) if err != nil { t.Fatalf("Failed verifying RSA signature [%s]", err) } @@ -1571,7 +1703,7 @@ func TestRSAVerify(t *testing.T) { t.Fatalf("Failed getting corresponding public key [%s]", err) } - valid, err = currentBCCSP.Verify(pk, signature, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) + valid, err = provider.Verify(pk, signature, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) if err != nil { t.Fatalf("Failed verifying RSA signature [%s]", err) } @@ -1580,17 +1712,17 @@ func TestRSAVerify(t *testing.T) { } // Store public key - err = currentKS.StoreKey(pk) + err = ks.StoreKey(pk) if err != nil { t.Fatalf("Failed storing corresponding public key [%s]", err) } - pk2, err := currentKS.GetKey(pk.SKI()) + pk2, err := ks.GetKey(pk.SKI()) if err != nil { t.Fatalf("Failed retrieving corresponding public key [%s]", err) } - valid, err = currentBCCSP.Verify(pk2, signature, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) + valid, err = provider.Verify(pk2, signature, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) if err != nil { t.Fatalf("Failed verifying RSA signature [%s]", err) } @@ -1601,9 +1733,12 @@ func TestRSAVerify(t *testing.T) { } func TestRSAKeyImportFromRSAPublicKey(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() // Generate an RSA key - k, err := currentBCCSP.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating RSA key [%s]", err) } @@ -1625,7 +1760,7 @@ func TestRSAKeyImportFromRSAPublicKey(t *testing.T) { } // Import the RSA.PublicKey - pk2, err := currentBCCSP.KeyImport(pub, &bccsp.RSAGoPublicKeyImportOpts{Temporary: false}) + pk2, err := provider.KeyImport(pub, &bccsp.RSAGoPublicKeyImportOpts{Temporary: false}) if err != nil { t.Fatalf("Failed importing RSA public key [%s]", err) } @@ -1636,17 +1771,17 @@ func TestRSAKeyImportFromRSAPublicKey(t *testing.T) { // Sign and verify with the imported public key msg := []byte("Hello World") - digest, err := currentBCCSP.Hash(msg, &bccsp.SHAOpts{}) + digest, err := provider.Hash(msg, &bccsp.SHAOpts{}) if err != nil { t.Fatalf("Failed computing HASH [%s]", err) } - signature, err := currentBCCSP.Sign(k, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) + signature, err := provider.Sign(k, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) if err != nil { t.Fatalf("Failed generating RSA signature [%s]", err) } - valid, err := currentBCCSP.Verify(pk2, signature, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) + valid, err := provider.Verify(pk2, signature, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) if err != nil { t.Fatalf("Failed verifying RSA signature [%s]", err) } @@ -1656,9 +1791,12 @@ func TestRSAKeyImportFromRSAPublicKey(t *testing.T) { } func TestKeyImportFromX509RSAPublicKey(t *testing.T) { + t.Parallel() + provider, _, cleanup := currentTestConfig.Provider(t) + defer cleanup() // Generate an RSA key - k, err := currentBCCSP.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) + k, err := provider.KeyGen(&bccsp.RSAKeyGenOpts{Temporary: false}) if err != nil { t.Fatalf("Failed generating RSA key [%s]", err) } @@ -1720,7 +1858,7 @@ func TestKeyImportFromX509RSAPublicKey(t *testing.T) { }, } - cryptoSigner, err := signer.New(currentBCCSP, k) + cryptoSigner, err := signer.New(provider, k) if err != nil { t.Fatalf("Failed initializing CyrptoSigner [%s]", err) } @@ -1752,7 +1890,7 @@ func TestKeyImportFromX509RSAPublicKey(t *testing.T) { } // Import the certificate's public key - pk2, err := currentBCCSP.KeyImport(cert, &bccsp.X509PublicKeyImportOpts{Temporary: false}) + pk2, err := provider.KeyImport(cert, &bccsp.X509PublicKeyImportOpts{Temporary: false}) if err != nil { t.Fatalf("Failed importing RSA public key [%s]", err) @@ -1764,17 +1902,17 @@ func TestKeyImportFromX509RSAPublicKey(t *testing.T) { // Sign and verify with the imported public key msg := []byte("Hello World") - digest, err := currentBCCSP.Hash(msg, &bccsp.SHAOpts{}) + digest, err := provider.Hash(msg, &bccsp.SHAOpts{}) if err != nil { t.Fatalf("Failed computing HASH [%s]", err) } - signature, err := currentBCCSP.Sign(k, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) + signature, err := provider.Sign(k, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) if err != nil { t.Fatalf("Failed generating RSA signature [%s]", err) } - valid, err := currentBCCSP.Verify(pk2, signature, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) + valid, err := provider.Verify(pk2, signature, digest, &rsa.PSSOptions{SaltLength: 32, Hash: getCryptoHashIndex(t)}) if err != nil { t.Fatalf("Failed verifying RSA signature [%s]", err) } diff --git a/bccsp/sw/keyderiv_test.go b/bccsp/sw/keyderiv_test.go index a9d6b9de93b..388187c2241 100644 --- a/bccsp/sw/keyderiv_test.go +++ b/bccsp/sw/keyderiv_test.go @@ -27,6 +27,8 @@ import ( ) func TestKeyDeriv(t *testing.T) { + t.Parallel() + expectedKey := &mocks2.MockKey{BytesValue: []byte{1, 2, 3}} expectedOpts := &mocks2.KeyDerivOpts{EphemeralValue: true} expectetValue := &mocks2.MockKey{BytesValue: []byte{1, 2, 3, 4, 5}} @@ -58,6 +60,8 @@ func TestKeyDeriv(t *testing.T) { } func TestECDSAPublicKeyKeyDeriver(t *testing.T) { + t.Parallel() + kd := ecdsaPublicKeyKeyDeriver{} _, err := kd.KeyDeriv(&mocks2.MockKey{}, nil) @@ -70,6 +74,8 @@ func TestECDSAPublicKeyKeyDeriver(t *testing.T) { } func TestECDSAPrivateKeyKeyDeriver(t *testing.T) { + t.Parallel() + kd := ecdsaPrivateKeyKeyDeriver{} _, err := kd.KeyDeriv(&mocks2.MockKey{}, nil) @@ -82,6 +88,8 @@ func TestECDSAPrivateKeyKeyDeriver(t *testing.T) { } func TestAESPrivateKeyKeyDeriver(t *testing.T) { + t.Parallel() + kd := aesPrivateKeyKeyDeriver{} _, err := kd.KeyDeriv(&mocks2.MockKey{}, nil) diff --git a/bccsp/sw/keygen_test.go b/bccsp/sw/keygen_test.go index b69becd8123..a1adf43bf1e 100644 --- a/bccsp/sw/keygen_test.go +++ b/bccsp/sw/keygen_test.go @@ -28,6 +28,8 @@ import ( ) func TestKeyGen(t *testing.T) { + t.Parallel() + expectedOpts := &mocks2.KeyGenOpts{EphemeralValue: true} expectetValue := &mocks2.MockKey{} expectedErr := errors.New("Expected Error") @@ -56,6 +58,8 @@ func TestKeyGen(t *testing.T) { } func TestECDSAKeyGenerator(t *testing.T) { + t.Parallel() + kg := &ecdsaKeyGenerator{curve: elliptic.P256()} k, err := kg.KeyGen(nil) @@ -68,6 +72,8 @@ func TestECDSAKeyGenerator(t *testing.T) { } func TestRSAKeyGenerator(t *testing.T) { + t.Parallel() + kg := &rsaKeyGenerator{length: 512} k, err := kg.KeyGen(nil) @@ -80,6 +86,8 @@ func TestRSAKeyGenerator(t *testing.T) { } func TestAESKeyGenerator(t *testing.T) { + t.Parallel() + kg := &aesKeyGenerator{length: 32} k, err := kg.KeyGen(nil) @@ -92,6 +100,8 @@ func TestAESKeyGenerator(t *testing.T) { } func TestAESKeyGeneratorInvalidInputs(t *testing.T) { + t.Parallel() + kg := &aesKeyGenerator{length: -1} _, err := kg.KeyGen(nil) @@ -100,6 +110,8 @@ func TestAESKeyGeneratorInvalidInputs(t *testing.T) { } func TestRSAKeyGeneratorInvalidInputs(t *testing.T) { + t.Parallel() + kg := &rsaKeyGenerator{length: -1} _, err := kg.KeyGen(nil) diff --git a/bccsp/sw/keyimport_test.go b/bccsp/sw/keyimport_test.go index 61ccfbed8fa..28f49ae5285 100644 --- a/bccsp/sw/keyimport_test.go +++ b/bccsp/sw/keyimport_test.go @@ -31,6 +31,8 @@ import ( ) func TestKeyImport(t *testing.T) { + t.Parallel() + expectedRaw := []byte{1, 2, 3} expectedOpts := &mocks2.KeyDerivOpts{EphemeralValue: true} expectetValue := &mocks2.MockKey{BytesValue: []byte{1, 2, 3, 4, 5}} @@ -62,6 +64,8 @@ func TestKeyImport(t *testing.T) { } func TestAES256ImportKeyOptsKeyImporter(t *testing.T) { + t.Parallel() + ki := aes256ImportKeyOptsKeyImporter{} _, err := ki.KeyImport("Hello World", &mocks2.KeyImportOpts{}) @@ -82,6 +86,8 @@ func TestAES256ImportKeyOptsKeyImporter(t *testing.T) { } func TestHMACImportKeyOptsKeyImporter(t *testing.T) { + t.Parallel() + ki := hmacImportKeyOptsKeyImporter{} _, err := ki.KeyImport("Hello World", &mocks2.KeyImportOpts{}) @@ -98,6 +104,8 @@ func TestHMACImportKeyOptsKeyImporter(t *testing.T) { } func TestECDSAPKIXPublicKeyImportOptsKeyImporter(t *testing.T) { + t.Parallel() + ki := ecdsaPKIXPublicKeyImportOptsKeyImporter{} _, err := ki.KeyImport("Hello World", &mocks2.KeyImportOpts{}) @@ -126,6 +134,8 @@ func TestECDSAPKIXPublicKeyImportOptsKeyImporter(t *testing.T) { } func TestECDSAPrivateKeyImportOptsKeyImporter(t *testing.T) { + t.Parallel() + ki := ecdsaPrivateKeyImportOptsKeyImporter{} _, err := ki.KeyImport("Hello World", &mocks2.KeyImportOpts{}) @@ -153,6 +163,8 @@ func TestECDSAPrivateKeyImportOptsKeyImporter(t *testing.T) { } func TestECDSAGoPublicKeyImportOptsKeyImporter(t *testing.T) { + t.Parallel() + ki := ecdsaGoPublicKeyImportOptsKeyImporter{} _, err := ki.KeyImport("Hello World", &mocks2.KeyImportOpts{}) @@ -165,6 +177,8 @@ func TestECDSAGoPublicKeyImportOptsKeyImporter(t *testing.T) { } func TestRSAGoPublicKeyImportOptsKeyImporter(t *testing.T) { + t.Parallel() + ki := rsaGoPublicKeyImportOptsKeyImporter{} _, err := ki.KeyImport("Hello World", &mocks2.KeyImportOpts{}) @@ -177,6 +191,8 @@ func TestRSAGoPublicKeyImportOptsKeyImporter(t *testing.T) { } func TestX509PublicKeyImportOptsKeyImporter(t *testing.T) { + t.Parallel() + ki := x509PublicKeyImportOptsKeyImporter{} _, err := ki.KeyImport("Hello World", &mocks2.KeyImportOpts{}) diff --git a/bccsp/sw/rsa_test.go b/bccsp/sw/rsa_test.go index 1e666506736..65fbd06653b 100644 --- a/bccsp/sw/rsa_test.go +++ b/bccsp/sw/rsa_test.go @@ -31,6 +31,8 @@ import ( ) func TestRSAPrivateKey(t *testing.T) { + t.Parallel() + lowLevelKey, err := rsa.GenerateKey(rand.Reader, 512) assert.NoError(t, err) k := &rsaPrivateKey{lowLevelKey} @@ -63,6 +65,8 @@ func TestRSAPrivateKey(t *testing.T) { } func TestRSAPublicKey(t *testing.T) { + t.Parallel() + lowLevelKey, err := rsa.GenerateKey(rand.Reader, 512) assert.NoError(t, err) k := &rsaPublicKey{&lowLevelKey.PublicKey} @@ -93,6 +97,8 @@ func TestRSAPublicKey(t *testing.T) { } func TestRSASignerSign(t *testing.T) { + t.Parallel() + signer := &rsaSigner{} verifierPrivateKey := &rsaPrivateKeyVerifier{} verifierPublicKey := &rsaPublicKeyKeyVerifier{} @@ -148,6 +154,8 @@ func TestRSASignerSign(t *testing.T) { } func TestRSAVerifiersInvalidInputs(t *testing.T) { + t.Parallel() + verifierPrivate := &rsaPrivateKeyVerifier{} _, err := verifierPrivate.Verify(nil, nil, nil, nil) assert.Error(t, err) diff --git a/bccsp/sw/sign_test.go b/bccsp/sw/sign_test.go index f077fdd5dd6..8cfff5a18ac 100644 --- a/bccsp/sw/sign_test.go +++ b/bccsp/sw/sign_test.go @@ -27,6 +27,8 @@ import ( ) func TestSign(t *testing.T) { + t.Parallel() + expectedKey := &mocks2.MockKey{} expectetDigest := []byte{1, 2, 3, 4} expectedOpts := &mocks2.SignerOpts{} diff --git a/bccsp/sw/verify_test.go b/bccsp/sw/verify_test.go index 8f62203877c..29bded1b0bc 100644 --- a/bccsp/sw/verify_test.go +++ b/bccsp/sw/verify_test.go @@ -27,6 +27,8 @@ import ( ) func TestVerify(t *testing.T) { + t.Parallel() + expectedKey := &mocks2.MockKey{} expectetSignature := []byte{1, 2, 3, 4, 5} expectetDigest := []byte{1, 2, 3, 4}