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

Kevin X

Thanks for your response. This will get client's certificate (the entity calling chaincode), not the peer's cert.

There isn a method to get peer msp id (ChaincodeStub.getMspID() - returns string), but l do not see a method to get the cert.

Is there a way to get the cert from msp id of peer or is there any other way?

On Mon, Jan 25, 2021, 2:14 AM Artem Barger1 <BARTEM@...> wrote:
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@...
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 to automatically receive all group messages.