Blockchain network hyperledger fabric - client application cannot connect to peer

54 views Asked by At

I use application client nodejs to connect peer in blockchain network hyperledger fabric, but not action. Please help me

Connect file json:

{
    "name": "test-network",
    "version": "1.0.0",
    "client": {
        "tlsEnable": true,
        "enableAuthentication": true,
        "organization": "MyOrg",
        "connection": {
            "timeout": {
                "peer": {
                    "endorser": "300"
                },
                "orderer": "300"
            }
        }
    },
    "channels": {
        "mychannel": {
            "peers": {
                "peer-dev.peer.hc.org": {}
            }
        }
    },
    "organizations": {
        "MyOrg": {
            "mspid": "MyOrg",
            "adminPrivateKey": {
                "path": "/path/to/fabric_config/users/adminMsp/keystore/1_sk"
            },
            "peers": [
                "peer-dev.peer.hc.org"
            ],
            "signedCert": {
                "path": "/path/to/fabric_config/users/adminMsp/signcerts/cert.pem"
            }
        }
    },
    "peers": {
        "peer-dev.peer.hc.org": {
            "tlsCACerts": {
                "path": "/path/to/fabric_config/tls/ca.crt"
            },
            "url": "grpcs://peer-dev.peer.hc.org:7051"
        }
    }
}

Code client connect

const ccpPath = path.resolve('path/to/connect.json');
const contents = fs.readFileSync(ccpPath, 'utf8');
const ccp = JSON.parse(contents);
const gateway = new Gateway();

const gatewayOpts = {
  identity: {
    credentials: {
      certificate: wallet.certificate,
      privateKey: wallet.privateKey
    },
    mspId: "MyOrg",
    type: "X.509",
    version: 1
  },
  discovery: {
    enabled: true,
    asLocalhost: false
  },
};

try {
  await gateway.connect(ccp, gatewayOpts);
  const network = await gateway.getNetwork('mynetwork'); // -> ERROR HERE
  const contract = network.getContract('mycontract');
} finally {
  gateway.disconnect();
}

Version:

peer: 2.2.1
nodejs: "fabric-network": "2.2.18"

Log application client:

ERROR [ExceptionsHandler] 13 INTERNAL: Received RST_STREAM with code 2 triggered by internal client error: 00888B6DBB7F0000:error:0A000412:SSL routines:ssl3_read_bytes:sslv3 alert bad certificate:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1586:SSL alert number 42

Error: 13 INTERNAL: Received RST_STREAM with code 2 triggered by internal client error: 00888B6DBB7F0000:error:0A000412:SSL routines:ssl3_read_bytes:sslv3 alert bad certificate:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1586:SSL alert number 42

    at callErrorFromStatus (app/api/node_modules/@grpc/grpc-js/src/call.ts:82:17)
    at Object.onReceiveStatus (app/api/node_modules/@grpc/grpc-js/src/client.ts:360:55)
    at Object.onReceiveStatus (app/api/node_modules/@grpc/grpc-js/src/client-interceptors.ts:458:34)
    at Object.onReceiveStatus (app/api/node_modules/@grpc/grpc-js/src/client-interceptors.ts:419:48)
    at app/api/node_modules/@grpc/grpc-js/src/resolving-call.ts:132:24
    at processTicksAndRejections (node:internal/process/task_queues:77:11)
for call at
    at ServiceClientImpl.makeUnaryRequest (app/api/node_modules/@grpc/grpc-js/src/client.ts:325:42)
    at ServiceClientImpl.<anonymous> (app/api/node_modules/@grpc/grpc-js/src/make-client.ts:189:15)
    at app/api/node_modules/fabric-common/lib/Discoverer.js:73:17
    at new Promise (<anonymous>)
    at Discoverer.sendDiscovery (app/api/node_modules/fabric-common/lib/Discoverer.js:54:10)
    at DiscoveryService.send (app/api/node_modules/fabric-common/lib/DiscoveryService.js:318:30)
    at NetworkImpl._initializeInternalChannel (app/api/node_modules/fabric-network/src/network.ts:340:4)
    at NetworkImpl._initialize (app/api/node_modules/fabric-network/src/network.ts:283:3)
    at Gateway.getNetwork (app/api/node_modules/fabric-network/src/gateway.ts:400:3)

Log peer

[core.comm] ServerHandshake -> ERRO 1d4a4 TLS handshake failed with error tls: failed to verify client certificate: x509: certificate signed by unknown authority server=PeerServer remoteaddress=1.1.1.1:11111

0

There are 0 answers