Re: How to get peer x509 certifi ate in chaincode? #fabric #fabric-chaincode


Artem Barger <bartem@...>
 

Following should do the work:

 
        serializedID, _ := stub.GetCreator()
        sId := &msp.SerializedIdentity{}
        err := proto.Unmarshal(serializedID, sId)
        if err != nil {
                return shim.Error(fmt.Sprintf("Could not deserialize a SerializedIdentity, err %s", err))
        }
        bl, _ := pem.Decode(sId.IdBytes)
        if bl == nil {
                return shim.Error(fmt.Sprintf("Could not decode the PEM structure"))
        }
        cert, err := x509.ParseCertificate(bl.Bytes)
        if err != nil {
                return shim.Error(fmt.Sprintf("ParseCertificate failed %s", err))
        }
Best regards,
                      Artem Barger

----- Original message -----
From: "Kevin X" <kevinx8888@...>
Sent by: fabric@...
To: fabric@...
Cc:
Subject: [EXTERNAL] [Hyperledger Fabric] How to get peer x509 certifi ate in chaincode? #fabric #fabric-chaincode
Date: Mon, Jan 25, 2021 6:28 AM
 
How can I get peer's x509 certificate in chaincode? I need to access attributes from peer certificate in the chaincode.

I can get perer's MSP ID using ChaincodeStub.getMspID() method. What is the recommended way to get peer certificate from within chaincode
 

Join fabric@lists.hyperledger.org to automatically receive all group messages.