From f6a06340fcc2a9152dfc13cb4ec283b3748afcb1 Mon Sep 17 00:00:00 2001 From: "S m, Aruna" Date: Sun, 18 Apr 2021 14:31:40 +0530 Subject: [PATCH] Enable chaincode to work without TLS as well 1. Root certificate is an optional parameter supplied for chaincode to verify the peer's connection in response. 2. If TLS is enabled, then specify the key and cert parameters. Do not expect it otherwise. Signed-off-by: S m, Aruna --- .../chaincode-external/assetTransfer.go | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/asset-transfer-basic/chaincode-external/assetTransfer.go b/asset-transfer-basic/chaincode-external/assetTransfer.go index d9d75179..ab2b8ecd 100644 --- a/asset-transfer-basic/chaincode-external/assetTransfer.go +++ b/asset-transfer-basic/chaincode-external/assetTransfer.go @@ -243,19 +243,27 @@ func getTLSProperties() shim.TLSProperties { // convert tlsDisabledStr to boolean tlsDisabled := getBoolOrDefault(tlsDisabledStr, false) + var keyBytes, certBytes, clientCACertBytes []byte + var err error - keyBytes, err := ioutil.ReadFile(key) - if err != nil { - log.Panicf("error while reading the crypto file: %s", err) + if !tlsDisabled { + keyBytes, err = ioutil.ReadFile(key) + if err != nil { + log.Panicf("error while reading the crypto file: %s", err) + } + certBytes, err = ioutil.ReadFile(cert) + if err != nil { + log.Panicf("error while reading the crypto file: %s", err) + } } - certBytes, err := ioutil.ReadFile(cert) - if err != nil { - log.Panicf("error while reading the crypto file: %s", err) - } - clientCACertBytes, err := ioutil.ReadFile(clientCACert) - if err != nil { - log.Panicf("error while reading the crypto file: %s", err) + // Did not request for the peer cert verification + if clientCACert != "" { + clientCACertBytes, err = ioutil.ReadFile(clientCACert) + if err != nil { + log.Panicf("error while reading the crypto file: %s", err) + } } + return shim.TLSProperties{ Disabled: tlsDisabled, Key: keyBytes,