From af5e9f0192be0013e0202c463328e13b9886a7e0 Mon Sep 17 00:00:00 2001 From: Krishna Harsha Voora Date: Tue, 27 Nov 2018 10:08:42 -0500 Subject: [PATCH] [FAB-12670] Fix pkcs11 UT Failures This patch allows to initialize softhsm2 token as non-root user, by merely setting SOFTHSM2_CONF, CI Envrionment should be updated to leverage SOFTHSM2_CONF. Change-Id: I9fdc9c837859a78619d9edc9e2e3fbe8733f04af Signed-off-by: Krishna Harsha Voora --- Makefile | 6 +++++- devenv/setupRHELonZ.sh | 4 ++++ devenv/setupUbuntuOnPPC64le.sh | 2 +- docs/source/dev-setup/devenv.rst | 8 ++++++++ scripts/config_softhsm2.sh | 16 ++++++++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) create mode 100755 scripts/config_softhsm2.sh diff --git a/Makefile b/Makefile index 9b03ef429f3..92a9847c2ce 100755 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ # - orderer - builds a native fabric orderer binary # - release - builds release packages for the host platform # - release-all - builds release packages for all target platforms +# - softhsm2_initialization - generates softhsm2 tokens used in pkcs11 test # - unit-test - runs the go-test based unit tests # - verify - runs unit tests for only the changed package tree # - profile - runs unit tests for all packages in coverprofile mode (slow) @@ -183,7 +184,10 @@ ccenv: $(BUILD_DIR)/image/ccenv/$(DUMMY) integration-test: gotool.ginkgo ccenv docker-thirdparty ./scripts/run-integration-tests.sh -unit-test: unit-test-clean peer-docker docker-thirdparty ccenv +softhsm2_initialization: + ./scripts/config_softhsm2.sh + +unit-test: unit-test-clean peer-docker softhsm2_initialization docker-thirdparty ccenv unit-test/run.sh unit-tests: unit-test diff --git a/devenv/setupRHELonZ.sh b/devenv/setupRHELonZ.sh index fe1491aa9e3..f9a1543ad83 100644 --- a/devenv/setupRHELonZ.sh +++ b/devenv/setupRHELonZ.sh @@ -36,6 +36,10 @@ fi iptables -I INPUT 1 -j ACCEPT sysctl vm.overcommit_memory=1 +################## +# Install softhsm2 +yum install softhsm -y + ################## # Install Docker cd /tmp diff --git a/devenv/setupUbuntuOnPPC64le.sh b/devenv/setupUbuntuOnPPC64le.sh index 46598378093..b0ca4955db6 100755 --- a/devenv/setupUbuntuOnPPC64le.sh +++ b/devenv/setupUbuntuOnPPC64le.sh @@ -39,7 +39,7 @@ fi # Install pre-requisite OS packages # ##################################### apt-get update -apt-get -y install software-properties-common curl git sudo wget "build-essential" zlib1g-dev libbz2-dev +apt-get -y install software-properties-common curl git sudo wget "build-essential" zlib1g-dev libbz2-dev softhsm2 ##################################### # Install and setup Docker services # diff --git a/docs/source/dev-setup/devenv.rst b/docs/source/dev-setup/devenv.rst index 95355ee1335..d5165397da1 100644 --- a/docs/source/dev-setup/devenv.rst +++ b/docs/source/dev-setup/devenv.rst @@ -55,6 +55,14 @@ Prerequisites - Note: The BIOS Enabled Virtualization may be within the CPU or Security settings of the BIOS +- (macOS) `Install softhsm on Mac OSX `__.You can + use Homebrew to install it as follows: + +:: + + brew install softhsm + + ``pip`` ~~~~~~ diff --git a/scripts/config_softhsm2.sh b/scripts/config_softhsm2.sh new file mode 100755 index 00000000000..08072c5189f --- /dev/null +++ b/scripts/config_softhsm2.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +cd $HOME +mkdir -p $HOME/lib/softhsm/tokens +cd $HOME/lib/softhsm/ +echo "directories.tokendir = $PWD/tokens" > softhsm2.conf +echo "Update SOFTHSM2_CONF via export SOFTHSM2_CONF=$HOME/lib/softhsm/softhsm2.conf" + +export SOFTHSM2_CONF=$HOME/lib/softhsm/softhsm2.conf + +softhsm2-util --init-token --slot 0 --label "ForFabric" --so-pin 1234 --pin 98765432