Hsmod Service: Hyperledger Fabric (Blockchain) Integration Guide
Hsmod Service: Hyperledger Fabric (Blockchain) Integration Guide
Revision History
Disclaimer
All information herein is either public information or is the property of and owned solely by Gemalto and/or its
subsidiaries who shall have and keep the sole right to file patent applications or any other kind of intellectual
property protection in connection with such information.
Nothing herein shall be construed as implying or granting to you any rights, by license, grant or otherwise,
under any intellectual and/or industrial property rights of or concerning any of Gemalto’s information.
This document can be used for informational, non-commercial, internal, and personal use only provided that:
> The copyright notice, the confidentiality and proprietary legend and this full warning notice appear in all
copies.
> This document shall not be posted on any publicly accessible network computer or broadcast in any media,
and no modification of any part of this document shall be made.
Use for any other purpose is expressly prohibited and may result in severe civil and criminal liabilities.
Contents
Overview 5
Third Party Application Details 5
Supported Platforms 5
Overview
This guide demonstrates using an HSM on Demand Service's PKCS#11 API to securely store a Hyperledger
Admin Certificate Authority (CA), Peer, and Orderer private keys. The guide then provides examples of the
e2e_cli end-to-end execution for creating channels and querying the chaincode.
This integration guide features sample material to demonstrate the process of integrating your HSM on
Demand Service with Blockchain HyperLedger Fabric.
Using an HSM on Demand Service to generate the ECDSA signing keys for Blockchain Identities provides the
following benefits:
> Secure generation, storage, and protection of Identity signing keys on a FIPS 140-2 level 3 validated HSM*.
> Full life cycle management of the keys.
> Performance improvements resulting from off-loading cryptographic operations from application servers to
the HSM on Demand Service.
This document contains the following sections:
> "Preparing for the Integration" on page 6
> "Integrating Hyperledger Fabric (Blockchain) with an HSM on Demand Service" on page 9
*Validation in progress
Supported Platforms
The following platforms are tested with HSMoD Service:
NOTE In a production configuration the passwords should be set to coincide with your
organization's security policy.
NOTE We recommend using separate HSMoD Service's for the Peer, Orderer, and
Users roles.
Constraints on HSMoD Services
Please take the following limitations into consideration when integrating your application software with an HSM
on Demand Service.
Set up Golang
Hyperledger Frabric uses the Go programming language. Download the golang binaries from
https://golang.org/dl/. Follow the instructions at https://golang.org/doc/install and install the golang binaries.
Ensure that the GO program is in the PATH variable.
# export PATH=/usr/local/go/bin:$PATH
If the GOPATH is not set, set it. The value will be a directory of the development workspace.
# export GOPATH=/opt/gopath
# mkdir –p $GOPATH/src/github.com/hyperledger
# cd $GOPATH/src/github.com/hyperledger
Set up Docker
Docker and Docker-compose need to be installed on the host system. Follow the instructions at
https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/ to install the Docker-CE.
Execute sudo pip install docker-compose==1.8.0 to install the docker-compose.
You can configure Docker so that it does not require sudo. Execute:
# sudo gpasswd –a $USER docker
# newgrp docker
After
RUN mkdir -p /var/hyperledger/production $FABRIC_CFG_PATH
After
RUN mkdir -p /var/hyperledger/production $FABRIC_CFG_PATH
4. Clone the fabric-ca project and build the fabric-ca client binary.
# cd $GOPATH/src/github.com/hyperledger
# git clone https://gerrit.hyperledger.org/r/fabric-ca
# cd fabric-ca
# git checkout -b v1.1.0 v1.1.0
NOTE This integration guide was developed using the v1.1.0 tag. We recommend you
use this version, as the instructions may not be compatible with the latest versions
available in the master branch of Hyperledger Fabric project.
# make fabric-ca-client
2. Add a keyrequest setting to the csr section to specify the key size.
Add:
KeyRequest:
A: ecdsa
S: 256
# export CORE_PEER_BCCSP_DEFAULT=PKCS11
# export CORE_PEER_BCCSP_PKCS11_LABEL=<HSMoD_service_label>
# export CORE_PEER_BCCSP_PKCS11_PIN=<HSMoD_SO_password>
# export CORE_PEER_BCCSP_PKCS11_LIBRARY=<PKCS11_library>
2. Ensure that the HSM on Demand Service client directory is available to the peer, and is using the correct
HSM on Demand Service for the peer. The ChrystokiConfigurationPath must point to the HSM on
Demand Service client directory, where the Crystoki.conf is stored.
# export ChrystokiConfigurationPath=<path_to_Chrystoki.conf>
# export ORDERER_GENERAL_BCCSP_PKCS11_LIBRARY=<PKCS11_library>
2. Ensure that the HSM on Demand Service client directory is available to the peer, and is using the correct
HSM on Demand Service for the peer. The ChrystokiConfigurationPath must point to the HSM on
Demand Service client directory, where the Crystoki.conf is stored.
# export ChrystokiConfigurationPath=<path_to_Chrystoki.conf>
Generating a CSR
You must generate a CSR for each role node in the configuration. You need to adjust the options and variables
for the requirements of the particular CSR.
The command to generate a CSR utilizes the following syntax:
# ./fabric-ca-client gencsr --csr.cn <value> --mspdir <value> --csr.names <value>
Argument Description
--csr.cn <value> The common name field of the certificate signing request.
NOTE When generating CSR requests ensure that you specify the correct CN, MSP
directory, and CSR names. The OU value should equate to peer, orderer or client,
depending on the CSR.
2. Submit the CSR to your CA to obtain the signed certificate for the role, and place the signed certificate in the
respective msp/signcerts directory.
NOTE The script works in conjunction with the cryptogen tool. The script generates all
of the Peer, Orderer, and Admin user MSPs using the fabric-ca-client gencsr
command. Certificate are generated using openssl.
-----------------------------------------------------------------------------------------------
------------------------------------------------
#!/bin/bash
###########################################################################
# This script generates certificates and keys to work with the cryptogen util
# to be used with the e2e_cli hyperledger fabric example.
# This allows the keys for the certificate to be generated with the
# PKCS11 BCCSP which in turn allows keys to be generated in an HSM.
##########################################################################
CA_CLIENT=./fabric-ca-client
CRYPTO_CONFIG=$PWD/crypto-config
ROOT=$PWD
BCCSP_DEFAULT=PKCS11
PIN=userpin
check_error() {
if [ $? -ne 0 ]; then
echo "ERROR: Something went wrong!"
exit 1
fi
}
signcsr() {
MSP=$1
CN=$2
CA_DIR=$3
CA_NAME=$4
CA_CERT=$(find $CA_DIR -name "*.pem")
CA_KEY=$(find $CA_DIR -name "*_sk")
CSR=$MSP/signcerts/$CN.csr
CERT=$MSP/signcerts/$CN-cert.pem
openssl x509 -req -sha256 -days 3650 -in $CSR -CA $CA_CERT -CAkey $CA_KEY -CAcreateserial -out
$CERT
check_error
}
genmsp() {
ORG_DIR=$1
ORG_NAME=$2
NODE_DIR=$3
NODE_NAME=$4
NODE_OU=$6
CN=${NODE_NAME}${ORG_NAME}
CA_PATH=$CRYPTO_CONFIG/$ORG_DIR/$ORG_NAME
NODE_PATH=$CA_PATH/$NODE_DIR/$CN
MSP=$NODE_PATH/msp
TLS=$NODE_PATH/tls
LABEL=$5
rm -rf $MSP/keystore/*
rm -rf $MSP/signcerts/*
echo $LABEL
export FABRIC_CA_CLIENT_BCCSP_DEFAULT=$BCCSP_DEFAULT
export FABRIC_CA_CLIENT_BCCSP_PKCS11_LABEL=$LABEL
export FABRIC_CA_CLIENT_BCCSP_PKCS11_PIN=$PIN
export ChrystokiConfigurationPath=/etc/hyperledger/fabric/dpod/$LABEL
export FABRIC_CA_CLIENT_BCCSP_PKCS11_
LIBRARY=/etc/hyperledger/fabric/dpod/$LABEL/libs/64/libCryptoki2.so
$CA_CLIENT gencsr --csr.cn $CN --mspdir $MSP --csr.names "C=US,ST=California,L=San
Francisco,OU=$NODE_OU"
check_error
copy_admin_cert_node() {
ORG_DIR=$1
ORG_NAME=$2
NODE_DIR=$3
NODE_NAME=$4
CN=$NODE_NAME.$ORG_NAME
CA_PATH=$CRYPTO_CONFIG/$ORG_DIR/$ORG_NAME
NODE_PATH=$CA_PATH/$NODE_DIR/$CN
MSP=$NODE_PATH/msp
ADMIN_CN=Admin@$ORG_NAME
ADMIN_CERT=$CA_PATH/users/$ADMIN_CN/msp/signcerts/$ADMIN_CN-cert.pem
cp $ADMIN_CERT $NODE_PATH/msp/admincerts
check_error
}
copy_admin_cert_ca() {
ORG_DIR=$1
ORG_NAME=$2
CA_PATH=$CRYPTO_CONFIG/$ORG_DIR/$ORG_NAME
ADMIN_CN=Admin@$ORG_NAME
ADMIN_CERT=$CA_PATH/users/$ADMIN_CN/msp/signcerts/$ADMIN_CN-cert.pem
cp $ADMIN_CERT $CA_PATH/msp/admincerts
check_error
cp $ADMIN_CERT $CA_PATH/users/$ADMIN_CN/msp/admincerts
check_error
}
for org in 1 2; do
for peer in 0 1; do
genmsp peerOrganizations org${org}.example.com peers peer${peer}. org${org}.example.com
peer
done
genmsp peerOrganizations org${org}.example.com users Admin@ org${org}.example.com client
for peer in 0 1; do
copy_admin_cert_node peerOrganizations org${org}.example.com peers peer${peer}
done
done
-------------------------------------------------------------------------------
b. Add a Volumes section with the following entries to the base of the Services section:
volumes:
- ../core.yaml:/etc/hyperledger/fabric/core.yaml
b. Add the following lines to the end of the peer.0.org1.example.com and peer1.org1.example.com
sections:
environment:
- CORE_PEER_BCCSP_PKCS11_LABEL=org1.example.com
- CORE_PEER_BCCSP_PKCS11_LIBRARY=
/etc/hyperledger/fabric/dpod/org1.example.com/libs/64/libCryptoki2.so
- ChrystokiConfigurationPath=/etc/hyperledger/fabric/dpod/org1.example.com
volumes:
- /etc/hyperledger/fabric/dpod/org1.example.com:
/etc/hyperledger/fabric/dpod/org1.example.com
c. Add the following lines to the end of the peer0.org2.example.com and peer1.org2.example.com
sections:
environment:
- CORE_PEER_BCCSP_PKCS11_LABEL=org2.example.com
- CORE_PEER_BCCSP_PKCS11_LIBRARY=
/etc/hyperledger/fabric/dpod/org2.example.com/libs/64/libCryptoki2.so
- ChrystokiConfigurationPath=/etc/hyperledger/fabric/dpod/org2.example.com
volumes:
- /etc/hyperledger/fabric/dpod/org2.example.com:
/etc/hyperledger/fabric/dpod/org2.example.com
9. Open the generateArtifacts.sh file in a text editor. Edit the bottom section of the file to use gencerts.sh to
create key material. Modify the file so it appears as the following:
generateCerts
replacePrivateKey
./gencerts.sh
generateChannelArtifacts
10.Open the network_setup.sh file in a text editor. Comment the networkDown function so that artifacts are
not deleted. Change:
rm -rf channel-artifacts/*.block channel-artifacts/*.tx crypto-config
to
# rm -rf channel-artifacts/*.block channel-artifacts/*.tx crypto-config
./generateArtifacts.sh
./network_setup.sh up