fabric -ca certificate creation on common storage instead of local machine - hyperledger-fabric

It would be grateful if someone helps me out with this. I do wanted to access the certificates and keys from the common storage . if i give the path it is creating a folder near msp and creating the certificates.
I tired by changing the path in docker-compose.yml file. The path changed but it is creating near the msp folder.
I wanted to know , where the default path must be changed.

fabric-ca-client allows you to specify the directory in which keys/certificates will be stored created by using the -M option:
fabric-ca-client enroll -u http://enrollid:enrollsecret#myca:7054 -M /path/to/myfolder
If you are using Docker to run the fabric-ca-client and want to make the key/certs available outside the Docker container, you will need to mount an external volume.
So let's say you want to store the key/certs in the /var/mycerts directory on your host system. You can do:
docker run --rm -v /var/mycerts:/var/mycerts hyperledger/fabric-ca fabric-ca-client enroll -u http://enrollid:enrollsecret#myca:7054 -M /var/mycerts

Related

Unable to enroll Fabric client as admin - Amazon Managed Blockchain

I'm following the AWS supply chain workshop. I created an EC2 instance and set up a VPC just like the workshop said. Now I'm connected to the EC2 instance using SSH and I've already downloaded the required packages, setup Docker, downloaded fabric-ca-client. My problem is configuring the fabric-ca client.
When I run the command fabric-ca-client enroll with the required params/flags, it retuns the following error: Error: Failed to create default configuration file: Failed to parse URL 'https://$USER:=9_phK63?#$CA_ENDPOINT': parse https://user:password#ca_endpoint: invalid port ":=9_phK63?" after host
Here's the complete command I'm trying to run: fabric-ca-client enroll -u https://$USER\:$PASSWORD#$CA_ENDPOINT --tls.certfiles ~/managedblockchain-tls-chain.pem -M admin-msp -H $HOME
I'm wondering if the ? in the password is causing the problem. If so, where can I change it?
Workshop link for reference: https://catalog.us-east-1.prod.workshops.aws/workshops/ce1e960e-a811-475f-a221-2afcf57e386a/en-US/02-set-up-a-fabric-client/05-configure-client/06-create-fabric-admin
my name is Forrest and I am a Blockchain Specialist Solutions Architect at AWS. I'd be happy to help you with this.
When using passwords with special characters, these need to be URL-encoded. For example, $ equates to %24. As OP mentioned in comments below, there is a Javascript method encodeURIComponent() that can serve this function. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
Please make sure your environment variables are all still correctly set as well:
echo $USER
echo $PASSWORD
echo $CA_ENDPOINT
Your CA endpoint should resolve to something like:
ca.m-XXXXXXXXXXXXX.n-XXXXXXXXXXXXXX.managedblockchain.<AWS_REGION>.amazonaws.com:30002

Cannot update fabric channel config using new admin identity

Background
We have a production fabric cluster setup and has been been running for a year. Now most of the certs expire and the cluster crash, including both tls and identity certs.
I tried to fix by completely removing old certs and private keys, generate and enroll new identities for peer, peer admin, orderer, orderer admin.
Everything works again, but I cannot instantiate/upgrade chaincode in existing channel because the channel was configured with old admin certs.
Problem
So now look like I'm stuck in a deadlock. In order to update channel config with new cert, I need to sign the update with matching old cert, which is already expired and blocked by orderer.
I find out that we can disable expired cert check in orderer using ORDERER_GENERAL_AUTHENTICATION_NOEXPIRATIONCHECKS=true. But now I don't have the old admin private key so I still cannot update the channel config.
Questions
I already replaced old private keys with new one so there is no way to use the old cert again.
Can I do something to resolve this channel issue?
Suggestions are greatly appreciated.
[!] What I'm suggesting is an idea. I haven't tested it.
[!] It seems to be feasible enough, but side-effect is not considered.
[!] It's just a trick, it's correct that it should never be done.
The conclusion is that the orderer and peer's binary can be artificially manipulated and updated.
For fabric, refer to $GOROOT/src/crypto when building binary.
Build in the fabric repository after artificially modifying all ecdsa verify functions in crypto to return true immediately.
cd $GOROOT/src/crypto
vi ecdsa/ecdsa.go # modify `Verify` function
cd $GOPATH/src/github.com/hyperledger/fabric
make peer
make orderer
Back up the binaries of the currently running docker container, and rerun after planting the newly built binaries in the container.
docker cp <peer_container_name>:/usr/local/bin/peer ./
docker cp $GOPATH/src/github.com/hyperledger/fabric/build/bin/peer <peer_container_name>:/usr/local/bin/peer
docker cp <orderer_container_name>:/usr/local/bin/orderer ./
docker cp $GOPATH/src/github.com/hyperledger/fabric/build/bin/orderer <orderer_container_name>:/usr/local/bin/orderer
docker-compose -f <your_docker_compose_file_path> restart
Now all verify is valid unconditionally. so, update all recent status.
Afterwards, the backed up binary is replanted into the container to solve this problem.
docker cp ./peer <peer_container_name>:/usr/local/bin/peer
docker cp ./orderer <orderer_container_name>:/usr/local/bin/orderer
docker-compose -f <your_docker_compose_file_path> restart

fabric-ca-client enroll with error Failed to read response of request: POST http://localhost:7054

I checkout project fabric-samples and run file startFabric.sh to start Fabric blockchain network. After that, I run node enrollAdmin.js to enroll the new admin
Now, I want to use the command line of fabric-ca-client to add a new user to org1. I execute the commands below:
Access to ca_peerOrg1 docker
docker exec -it ca_peerOrg1 bash
I check the value of
$FABRIC_CA_CLIENT_HOME is unset
$FABRIC_CA_HOME is /etc/hyperledger/fabric-ca-server
Go to /etc/hyperledger/fabric-ca-server directory and check command
fabric-ca-client
And run this command
fabric-ca-client enroll -u http://admin:adminpw#localhost:7054
But it occurs error below:
Anyone could help? Thanks for reading
I just encountered the same problem. For anyone who is interested, this error indicates fabric-ca-server is running with TLS enabled.
To get rid of this error, you need to make the following changes to the fabric-ca-client command:
use https instead of http in the url
use ca host name instead of localhost in the url
provide the TLS cert file for the server's listening port via --tls.certfile
e.g. fabric-ca-client enroll -u https://admin:adminpw#ca.org0.example.com:7054 --tls.certfiles /certs/ca/ca.org0.example.com-cert.pem
The TLS cert file was generated by fabric-ca-server at startup. The default file location is $FABRIC_CA_SERVER_HOME/tls-cert.pem. Otherwise, the location is specified by $FABRIC_CA_SERVER_TLS_CERTFILE or fabric-ca-server-config.yaml

cannot find Signcert hyperledger fabric

i am trying to run the fabric network and getting the following error.
peer1.org2.example.com | 2019-08-09 19:37:30.561 UTC [main] InitCmd ->
ERRO 001 Cannot run peer because error when setting up MSP of type bccsp
from directory /etc/hyperledger/fabric/msp: could not load a valid signer certificate
from directory /etc/hyperledger/fabric/msp/signcerts: stat /etc/hyperledger/fabric/msp/signcerts:
no such file or directory
I also tried to find the directory in the crypto-config folder and don't see signcerts folder there as well. I am not sure if
cryptogen generate --config=./crypto-config.yaml
generates this folder or not.
I am using docker-compose to run the fabric network. and I have following two mounts
../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp
../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
Please suggest.
cryptogen generates the crypto-config directory but to avoid your error. you should run following commands by making changes according to your system path.
docker exec -it cli bash
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
CORE_PEER_LOCALMSPID="Org1MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
So the issue was, the folder it generates is inside the
crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/signcert
and i was looking in the
crypto-config/peerOrganizations/org1.example.com/msp
also one mount was wrong. Another things with orderer was relative mapping ./ instead of ../
Thanks for your help #adarshJha

Hyperledger Fabric: Enrollment check failed: Idemix enrollment information does not exist

we get this error whenever we try to run fabric-ca-client. Example below:
# fabric-ca-client register --url https://ica-org:7054 --id.name user-org --id.affiliation=org
2019/03/19 20:18:07 [INFO] Configuration file location: /home/fabric-ca-client-config.yaml
2019/03/19 20:18:07 [INFO] TLS Enabled
2019/03/19 20:18:07 [ERROR] Enrollment check failed: Idemix enrollment information does not exist
Error: Enrollment information does not exist. Please execute enroll command first. Example: fabric-ca-client enroll -u http://user:userpw#serverAddr:serverPort
How can we fix this?
This happens when fabric-ca-client cannot find any X509 or Idemix identity. fabric-ca-client needs to be initialized with an identity (except when its being used to enroll a user). It first tries to load an X509 identity from the mspdir location specified in the fabric-ca-client-config.yaml file or the -M command line argument which takes precedence over mspdir in config file. And if its not able to find X509 identity it will look for an idemix identity. If this fails as well it displays the error in question.
For X509 identity:
its public cert needs to be in signcerts
and private key needs to be in keystore
and the public cert of the authority who issued the public/private keypair needs to be in cacerts folder (if an intermediate ca was used then its cert needs to be in intermediatecerts)
all the folders above are under the mspdir
Solution 1
A potential cause if the folder indicated by FABRIC_CA_CLIENT_HOME is not created you'll get that error. You have to check if FABRIC_CA_CLIENT_HOME points to an existing folder. This happens too when indicating a wrong MSP path
exp
fabric-ca-client gencrl -M ~/wrong_path
Solution2:
Resolution to issue fabric-ca-client identity list command is as follows:
start the network with the CA option
./network.sh up -ca
after the network is up, navigate to (assumes you are already in the test-network directory):
cd organizations/peerOrganizations/org1.example.com
export cert path using this command:
export FABRIC_CA_CLIENT_TLS_CERTFILES=$PWD/ca/ca.org1.example.com-cert.pem
export fabric-ca-client home using this command:
export FABRIC_CA_CLIENT_HOME=$PWD
issue the following command:
fabric-ca-client identity list
Since you use TLS, you should be using the --tls.certfiles flag or set the FABRIC_CA_CLIENT_TLS_CERTFILES environment variable when using the fabric-ca-client command. This should hold the full path to your organisation's TLS certificate.

Resources