Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FAB-16165] Change pkcs11 test keystore directory
PKCS11 tests currently use the system temp directory
as the location for the keystore. The PKCS11 package looks for
the keystore by looping over files in the directory specified,
reading them, and then attempting to convert them to PEM files.
If a file with no EOF marker, or an open pipe exists in the
directory, attempting to read it deadlocks the read operation
in the BCCSP library.

Instead we create a sub-directory in the temp directory
and create the keystore there

Signed-off-by: Brett Logan <Brett.T.Logan@ibm.com>
Change-Id: I007a7aad6efa921cf9dd6c44c9ae921c68a29db9
(cherry picked from commit e841ebe)
  • Loading branch information
lindluni committed Sep 20, 2019
1 parent e09c726 commit fcfd12e
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions bccsp/pkcs11/impl_test.go
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/asn1"
"fmt"
"hash"
"io/ioutil"
"math/big"
"net"
"os"
Expand Down Expand Up @@ -49,12 +50,23 @@ type testConfig struct {
}

func TestMain(m *testing.M) {
ks, err := sw.NewFileBasedKeyStore(nil, os.TempDir(), false)
os.Exit(testMain(m))
}

func testMain(m *testing.M) int {
tmpDir, err := ioutil.TempDir("", "pkcs11_ks")
if err != nil {
fmt.Printf("Failed to create keystore directory [%s]\n", err)
return -1
}
defer os.RemoveAll(tmpDir)

keyStore, err := sw.NewFileBasedKeyStore(nil, tmpDir, false)
if err != nil {
fmt.Printf("Failed initiliazing KeyStore [%s]", err)
os.Exit(-1)
fmt.Printf("Failed initiliazing KeyStore [%s]\n", err)
return -1
}
currentKS = ks
currentKS = keyStore

lib, pin, label := FindPKCS11Lib()
tests := []testConfig{
Expand All @@ -77,28 +89,28 @@ func TestMain(m *testing.M) {
Label: label,
Pin: pin,
}

for _, config := range tests {
var err error
currentTestConfig = config

opts.HashFamily = config.hashFamily
opts.SecLevel = config.securityLevel
opts.SoftVerify = config.softVerify
opts.Immutable = config.immutable
fmt.Printf("Immutable = [%v]", opts.Immutable)
currentBCCSP, err = New(opts, currentKS)
fmt.Printf("Immutable = [%v]\n", opts.Immutable)
currentBCCSP, err = New(opts, keyStore)
if err != nil {
fmt.Printf("Failed initiliazing BCCSP at [%+v]: [%s]", opts, err)
os.Exit(-1)
fmt.Printf("Failed initiliazing BCCSP at [%+v] \n%s\n", opts, err)
return -1
}

ret := m.Run()
if ret != 0 {
fmt.Printf("Failed testing at [%+v]", opts)
os.Exit(-1)
fmt.Printf("Failed testing at [%+v]\n", opts)
return -1
}
}
os.Exit(0)
return 0
}

func TestNew(t *testing.T) {
Expand Down

0 comments on commit fcfd12e

Please sign in to comment.