Skip to content

Commit f86e9de

Browse files
authored
Improve softhsm test guidance (hyperledger#4848)
Update docs for softhsm integration tests. Add log message when softhsm tests don't execute. Signed-off-by: David Enyeart <[email protected]>
1 parent 0807f0b commit f86e9de

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

ci/scripts/setup_hsm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ sudo mkdir -p /var/lib/softhsm/tokens
99
sudo softhsm2-util --init-token --slot 0 --label "ForFabric" --so-pin 1234 --pin 98765432
1010
sudo chmod -R 777 /var/lib/softhsm
1111
mkdir -p ~/.config/softhsm2
12-
cp /usr/share/softhsm/softhsm2.conf ~/.config/softhsm2
12+
cp /usr/share/softhsm/softhsm2.conf ~/.config/softhsm2

docs/source/dev-setup/devenv.rst

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ Setting up the development environment
44
Prerequisites
55
~~~~~~~~~~~~~
66

7-
In addition to the standard :doc:`../prereqs` for Fabric, the following prerequisites are also required:
7+
In addition to the standard :doc:`../prereqs` for Fabric, the following prerequisites are also required to run the Fabric tests:
88

99
- (macOS) `Xcode Command Line Tools <https://developer.apple.com/downloads/>`__
10-
- (All platforms) `SoftHSM <https://github.com/opendnssec/SoftHSMv2>`__ use version 2.5 as 2.6 is not operable in this environment
1110
- (All platforms) `jq <https://stedolan.github.io/jq/download/>`__
11+
- (All platforms) `SoftHSM <https://github.com/opendnssec/SoftHSMv2>`__ use version 2.5 as 2.6 is not operable in this environment
1212

1313
For Linux platforms, including WSL2 on Windows, also required are various build tools such as gnu-make and
1414
C compiler. On ubuntu and it's derivatives you can install the required toolset by using the command
@@ -20,9 +20,11 @@ Steps
2020

2121
Installing SoftHSM
2222
^^^^^^^^^^^^^^^^^^
23+
SoftHSM is only required if you would like to run the SoftHSM integration tests (integration/pkcs11 directory).
24+
If you don't install and configure SoftHSM, the integration tests will automatically be skipped.
2325
Ensure you install ``2.5`` of softhsm, if you are using a distribution package manager such as ``apt`` on ubuntu
2426
or Homebrew on Mac OS, make sure that it offers this version otherwise you will need to install from source. Version 2.6
25-
of SoftHSM is known to have problems. Older versions than 2.5 may work however.
27+
of SoftHSM is known to have problems (but there is evidence integration tests pass on 2.6.1).
2628

2729
When installing SoftHSM, you should note the path where the shared library ``libsofthsm2.so`` is installed
2830
you may need to have to provide this later in an environment variable to get the PKCS11 tests to pass.
@@ -41,7 +43,12 @@ Once Homebrew is ready, installing the necessary prerequisites is very easy, for
4143
brew install git jq
4244
brew install --cask docker
4345

44-
Go and SoftHSM are also available from Homebrew, but make sure you install the appropriate versions
46+
Go and SoftHSM are also available from Homebrew, but make sure you install the appropriate versions:
47+
48+
::
49+
50+
brew install [email protected]
51+
brew install softhsm
4552

4653
Docker Desktop must be launched to complete the installation, so be sure to open
4754
the application after installing it:
@@ -72,7 +79,7 @@ the repository.
7279
Configure SoftHSM
7380
^^^^^^^^^^^^^^^^^
7481

75-
A PKCS #11 cryptographic token implementation is required to run the unit
82+
A PKCS #11 cryptographic token implementation is required to run the integration
7683
tests. The PKCS #11 API is used by the bccsp component of Fabric to interact
7784
with hardware security modules (HSMs) that store cryptographic information and
7885
perform cryptographic computations. For test environments, SoftHSM can be used
@@ -89,23 +96,30 @@ to an appropriate location. Please see the man page for ``softhsm2.conf`` for
8996
details.
9097

9198
After SoftHSM has been configured, the following command can be used to
92-
initialize the token required by the unit tests:
99+
initialize the token required by the integration tests:
93100

94101
::
95102

96103
softhsm2-util --init-token --slot 0 --label ForFabric --so-pin 1234 --pin 98765432
97104

98105
If tests are unable to locate the libsofthsm2.so library in your environment,
99106
specify the library path, the PIN, and the label of your token in the
100-
appropriate environment variables. For example, on macOS, depending on where the
101-
library has been installed:
107+
appropriate environment variables. For example, if installed using Homebrew on macOS (Intel):
102108

103109
::
104110

105111
export PKCS11_LIB="/usr/local/Cellar/softhsm/2.6.1/lib/softhsm/libsofthsm2.so"
106112
export PKCS11_PIN=98765432
107113
export PKCS11_LABEL="ForFabric"
108114

115+
And for macOS on Apple silicon:
116+
117+
::
118+
119+
export PKCS11_LIB=/opt/homebrew/Cellar/softhsm/2.6.1/lib/softhsm/libsofthsm2.so
120+
export PKCS11_PIN=98765432
121+
export PKCS11_LABEL="ForFabric"
122+
109123
If you installed SoftHSM on ubuntu from source then the environment variables may look like
110124

111125
::

integration/pkcs11/pkcs11_suite_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package pkcs11
88

99
import (
1010
"encoding/json"
11+
"fmt"
1112
"testing"
1213

1314
bpkcs11 "github.com/hyperledger/fabric-lib-go/bccsp/pkcs11"
@@ -24,7 +25,8 @@ func TestPKCS11(t *testing.T) {
2425
RegisterFailHandler(Fail)
2526
lib, pin, label := bpkcs11.FindPKCS11Lib()
2627
if lib == "" || pin == "" || label == "" {
27-
t.Skip("Skipping PKCS11 Suite: Required ENV variables not set")
28+
fmt.Fprintf(GinkgoWriter, "Skipping PKCS11 Suite: Set the PKCS11_LIB environment variable to run the PKCS11 tests\n")
29+
t.Skip("Skipping PKCS11 Suite: Set the PKCS11_LIB environment variable to run the PKCS11 tests")
2830
}
2931
RunSpecs(t, "PKCS11 Suite")
3032
}

0 commit comments

Comments
 (0)