2018-10-10 17:18:00 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
source env.sh
|
|
|
|
|
|
|
|
#TODO: check param number is 2
|
|
|
|
|
2018-10-12 21:31:06 +08:00
|
|
|
if [ "$#" -ne 2 ]; then
|
|
|
|
echo "Illegal number of parameters"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-10-10 17:18:00 +08:00
|
|
|
ORG_NAME=$1 # org1.example.com
|
|
|
|
TYPE=$2 # ca | tlsca
|
|
|
|
|
|
|
|
ORG_PATH=/etc/hyperledger/fabric-ca-server
|
|
|
|
CA_PATH=${ORG_PATH}/${TYPE} # e.g., /etc/hyperledger/fabric-ca-server/ca
|
|
|
|
|
|
|
|
echo $(hostname)
|
|
|
|
|
2018-10-12 21:31:06 +08:00
|
|
|
# do not recreate the credentials if existed
|
|
|
|
if [ ! -d ${CA_PATH} ]; then
|
|
|
|
mkdir -p ${CA_PATH}
|
|
|
|
cd ${CA_PATH}
|
|
|
|
echo "Generate the credentials for ${TYPE}.${ORG_NAME}"
|
2018-10-10 17:18:00 +08:00
|
|
|
|
2018-10-12 21:31:06 +08:00
|
|
|
# generate fabric-ca-server-config.yaml
|
|
|
|
#fabric-ca-server init \
|
|
|
|
# -H ${CA_PATH} \
|
|
|
|
# -b ${DEFAULT_USER}:${DEFAULT_PASS}
|
|
|
|
#rm -rf msp/* ca-cert.pem # these credentials are wrong
|
2018-10-10 17:18:00 +08:00
|
|
|
|
2018-10-12 21:31:06 +08:00
|
|
|
echo "${CA_SERVER_DEFAULT_CONFIG}" >> fabric-ca-server-config.yaml
|
2018-10-10 17:18:00 +08:00
|
|
|
|
2018-10-12 21:31:06 +08:00
|
|
|
# Update config
|
|
|
|
echo "Update fabric-ca-server-config.yaml"
|
|
|
|
yq w -i fabric-ca-server-config.yaml ca.name "${TYPE}.${ORG_NAME}"
|
|
|
|
yq w -i fabric-ca-server-config.yaml ca.certfile "${TYPE}.${ORG_NAME}-cert.pem"
|
|
|
|
yq w -i fabric-ca-server-config.yaml ca.keyfile "${TYPE}.${ORG_NAME}_sk"
|
2018-10-10 17:18:00 +08:00
|
|
|
|
2018-10-12 21:31:06 +08:00
|
|
|
yq w -i fabric-ca-server-config.yaml csr.cn "${TYPE}.${ORG_NAME}"
|
|
|
|
yq w -i fabric-ca-server-config.yaml csr.names[0].O "${ORG_NAME}"
|
|
|
|
yq w -i fabric-ca-server-config.yaml csr.names[0].OU "${TYPE}"
|
2018-10-10 17:18:00 +08:00
|
|
|
|
2018-10-12 21:31:06 +08:00
|
|
|
yq w -i fabric-ca-server-config.yaml tls.enabled false
|
|
|
|
#yq w -i fabric-ca-server-config.yaml tls.certfile "${ORG_PATH}/tlsca/tlsca.${ORG_NAME}-cert.pem"
|
|
|
|
#yq w -i fabric-ca-server-config.yaml tls.keyfile "${ORG_PATH}/tlsca/tlsca.${ORG_NAME}_sk"
|
2018-10-10 17:18:00 +08:00
|
|
|
|
2018-10-12 21:31:06 +08:00
|
|
|
# Generate new certs based on updated config
|
|
|
|
echo "Generate certificates for ${TYPE}.${ORG_NAME} under ${CA_PATH}"
|
|
|
|
fabric-ca-server init -H ${CA_PATH}
|
2018-10-10 17:18:00 +08:00
|
|
|
|
2018-10-12 21:31:06 +08:00
|
|
|
cp msp/keystore/*_sk ${TYPE}.${ORG_NAME}_sk
|
|
|
|
fi
|
2018-10-10 17:18:00 +08:00
|
|
|
|
|
|
|
echo "Start ${TYPE}.${ORG_NAME}..."
|
|
|
|
fabric-ca-server start -H ${CA_PATH}
|