Skip to content

Commit 2bdd187

Browse files
committed
[FAB-12476] Remove bccsp dependency
core/comm has a transirtive dependency on the bccsp pkg which seemed unnecessary given it was only for a sha256 function. Use crypto/sha256 directly instead. Change-Id: I4e43c986382d3edaaa815a60a771944d4aa753cc Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
1 parent 2fe8427 commit 2bdd187

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

core/comm/util.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ package comm
99
import (
1010
"bytes"
1111
"context"
12+
"crypto/sha256"
1213
"crypto/x509"
1314
"encoding/pem"
1415

1516
"github.com/golang/protobuf/proto"
16-
"github.com/hyperledger/fabric/common/util"
1717
"github.com/pkg/errors"
1818
"google.golang.org/grpc/credentials"
1919
"google.golang.org/grpc/peer"
@@ -119,7 +119,9 @@ func ExtractCertificateHashFromContext(ctx context.Context) []byte {
119119
if len(rawCert) == 0 {
120120
return nil
121121
}
122-
return util.ComputeSHA256(rawCert)
122+
h := sha256.New()
123+
h.Write(rawCert)
124+
return h.Sum(nil)
123125
}
124126

125127
// ExtractCertificateFromContext returns the TLS certificate (if applicable)

core/comm/util_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package comm_test
88

99
import (
1010
"context"
11+
"crypto/sha256"
1112
"crypto/tls"
1213
"crypto/x509"
1314
"net"
@@ -16,7 +17,6 @@ import (
1617
"time"
1718

1819
"github.com/golang/protobuf/proto"
19-
"github.com/hyperledger/fabric/common/util"
2020
"github.com/hyperledger/fabric/core/comm"
2121
grpc_testdata "github.com/hyperledger/fabric/core/comm/testdata/grpc"
2222
"github.com/hyperledger/fabric/protos/common"
@@ -51,7 +51,9 @@ func TestExtractCertificateHashFromContext(t *testing.T) {
5151
},
5252
}
5353
ctx = peer.NewContext(context.Background(), p)
54-
assert.Equal(t, util.ComputeSHA256([]byte{1, 2, 3}), comm.ExtractCertificateHashFromContext(ctx))
54+
h := sha256.New()
55+
h.Write([]byte{1, 2, 3})
56+
assert.Equal(t, h.Sum(nil), comm.ExtractCertificateHashFromContext(ctx))
5557
}
5658

5759
type nonTLSConnection struct {
@@ -124,7 +126,9 @@ func TestBindingInspector(t *testing.T) {
124126

125127
// Scenario IV: Client sends its TLS cert hash as needed, but doesn't use mutual TLS
126128
cert, _ := tls.X509KeyPair([]byte(selfSignedCertPEM), []byte(selfSignedKeyPEM))
127-
chanHdr.TlsCertHash = util.ComputeSHA256([]byte(cert.Certificate[0]))
129+
h := sha256.New()
130+
h.Write([]byte(cert.Certificate[0]))
131+
chanHdr.TlsCertHash = h.Sum(nil)
128132
ch, _ = proto.Marshal(chanHdr)
129133
err = srv.newInspection(t).inspectBinding(envelopeWithChannelHeader(ch))
130134
assert.Error(t, err)

0 commit comments

Comments
 (0)