hyperledger / fabric

Hyperledger Fabric is an enterprise-grade permissioned distributed ledger framework for developing solutions and applications. Its modular and versatile design satisfies a broad range of industry use cases. It offers a unique approach to consensus that enables performance at scale while preserving privacy.
https://wiki.hyperledger.org/display/fabric
Apache License 2.0
15.77k stars 8.86k forks source link

Adding softhsm2 support for fabric peer #4172

Open chetagra opened 1 year ago

chetagra commented 1 year ago

I am trying to configure fabric peer with Softhsm2 support

I am getting following error on starting peer container

Screenshot from 2023-04-19 18-12-55

below is peer dockerfile I am using

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0

ARG GO_VER
ARG UBUNTU_VER

FROM ubuntu:${UBUNTU_VER} as peer-base
RUN apt update && apt install -y tzdata
# set up nsswitch.conf for Go's "netgo" implementation
# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
# - docker run --rm debian:stretch grep '^hosts:' /etc/nsswitch.conf
RUN echo 'hosts: files dns' > /etc/nsswitch.conf

FROM golang:${GO_VER} as golang
RUN apt update && apt install -y \
    bash \
    gcc \
    git \
    make \
    musl-dev
ADD . /home/chetan/fabric
WORKDIR /home/chetan/fabric

FROM golang as peer
ARG GO_TAGS
RUN make peer GO_TAGS=${GO_TAGS}

FROM peer-base
RUN apt update && apt install -y \
    build-essential \ 
    libltdl-dev \
    libssl-dev \  
    automake \
    autoconf \
    libtool \
    git \
    make \
    wget \
    opensc
RUN wget https://dist.opendnssec.org/source/softhsm-2.6.1.tar.gz
RUN tar -xzf softhsm-2.6.1.tar.gz
RUN cd softhsm-2.6.1
RUN ./softhsm-2.6.1/configure
RUN make
RUN make install
ENV SOFTHSM2_CONF /etc/softhsm2.conf
RUN softhsm2-util --init-token --slot 0 --label "fabric" --pin 1234 --so-pin 1234
RUN pkcs11-tool --module /usr/local/lib/softhsm/libsofthsm2.so --label fabric --pin 1234 --login --keypairgen --key-type EC:prime256v1
ENV FABRIC_CFG_PATH /etc/hyperledger/fabric
VOLUME /etc/hyperledger/fabric
VOLUME /var/hyperledger
COPY --from=peer /home/chetan/fabric/build/bin /usr/local/bin
COPY --from=peer /home/chetan/fabric/sampleconfig/msp ${FABRIC_CFG_PATH}/msp
COPY --from=peer /home/chetan/fabric/sampleconfig/core.yaml ${FABRIC_CFG_PATH}
EXPOSE 7051
CMD ["peer","node","start"]

below are the core.yaml file changes I have made

Screenshot from 2023-04-19 18-23-19

I am folllowing this documentation :- https://hyperledger-fabric.readthedocs.io/en/latest/hsm.html

bestbeforetoday commented 1 year ago

I wonder if this is related to #4146? Comments further down that issues suggested it was solved by changing the config file location.

chetagra commented 1 year ago

I tried these solution but doesn't seem to work I am using fabric v2.2.10