Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 7f4bc34

Browse files
author
Baha Shaaban
committed
[FAB-6275] Removed tls:enabled from SDK GO config file
Change-Id: I3921722f2e2b73a5b289be332cbf134dd825fd00 Signed-off-by: Baha Shaaban <baha.shaaban@securekey.com>
1 parent 9c02025 commit 7f4bc34

File tree

18 files changed

+142
-114
lines changed

18 files changed

+142
-114
lines changed

api/apiconfig/configprovider.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ type Config interface {
3030
NetworkConfig() (*NetworkConfig, error)
3131
ChannelConfig(name string) (*ChannelConfig, error)
3232
ChannelPeers(name string) ([]ChannelPeer, error)
33-
IsTLSEnabled() bool
3433
SetTLSCACertPool(*x509.CertPool)
3534
TLSCACertPool(tlsCertificate string) (*x509.CertPool, error)
3635
IsSecurityEnabled() bool

api/apiconfig/mocks/mockconfig.gen.go

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/config.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/hyperledger/fabric-sdk-go/api/apiconfig"
2424

25+
"github.com/hyperledger/fabric-sdk-go/pkg/config/urlutil"
2526
"github.com/hyperledger/fabric-sdk-go/pkg/errors"
2627
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
2728
bccspFactory "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp/factory"
@@ -375,7 +376,7 @@ func (c *Config) PeersConfig(org string) ([]apiconfig.PeerConfig, error) {
375376

376377
for _, peerName := range peersConfig {
377378
p := config.Peers[strings.ToLower(peerName)]
378-
if err = verifyPeerConfig(p, peerName, c.IsTLSEnabled()); err != nil {
379+
if err = verifyPeerConfig(p, peerName, urlutil.IsTLSEnabled(p.URL)); err != nil {
379380
return nil, err
380381
}
381382
if p.TLSCACerts.Path != "" {
@@ -464,7 +465,7 @@ func (c *Config) ChannelPeers(name string) ([]apiconfig.ChannelPeer, error) {
464465
return nil, errors.Errorf("peer config not found for %s", peerName)
465466
}
466467

467-
if err = verifyPeerConfig(p, peerName, c.IsTLSEnabled()); err != nil {
468+
if err = verifyPeerConfig(p, peerName, urlutil.IsTLSEnabled(p.URL)); err != nil {
468469
return nil, err
469470
}
470471

@@ -507,11 +508,6 @@ func verifyPeerConfig(p apiconfig.PeerConfig, peerName string, tlsEnabled bool)
507508
return nil
508509
}
509510

510-
// IsTLSEnabled is TLS enabled?
511-
func (c *Config) IsTLSEnabled() bool {
512-
return myViper.GetBool("client.tls.enabled")
513-
}
514-
515511
// SetTLSCACertPool allows a user to set a global cert pool with a set of
516512
// root TLS CAs that will be used for all outgoing connections
517513
func (c *Config) SetTLSCACertPool(certPool *x509.CertPool) {

pkg/config/config.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ client:
6363
cryptoconfig:
6464
path: path/to/cryptoconfig
6565

66-
# enable/disable tls for the client
67-
tls:
68-
enabled: true
69-
7066
# Some SDKs support pluggable KV stores, the properties under "credentialStore"
7167
# are implementation specific
7268
credentialStore:
@@ -185,7 +181,7 @@ organizations:
185181
#
186182
orderers:
187183
# orderer.example.com:
188-
# url: orderer.example.com:7050
184+
# url: grpcs://orderer.example.com:7050
189185

190186
# these are standard properties defined by the gRPC library
191187
# they will be passed in as-is to gRPC client constructor
@@ -204,10 +200,10 @@ orderers:
204200
peers:
205201
# peer0.org1.example.com:
206202
# this URL is used to send endorsement and query requests
207-
# url: peer0.org1.example.com:7051
203+
# url: grpcs://peer0.org1.example.com:7051
208204

209205
# this URL is used to connect the EventHub and registering event listeners
210-
# eventUrl: peer0.org1.example.com:7053
206+
# eventUrl: grpcs://peer0.org1.example.com:7053
211207

212208
# grpcOptions:
213209
# ssl-target-name-override: peer0.org1.example.com

pkg/config/urlutil/urlutils.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright SecureKey Technologies Inc. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package urlutil
8+
9+
import (
10+
"strings"
11+
12+
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
13+
)
14+
15+
var logger = logging.NewLogger("fabric_sdk_go")
16+
17+
// IsTLSEnabled is a generic function that expects a URL and verifies if it has
18+
// a prefix HTTPS or GRPCS to return true for TLS Enabled URLs or false otherwise
19+
func IsTLSEnabled(url string) bool {
20+
tlsURL := strings.ToLower(url)
21+
if strings.HasPrefix(tlsURL, "https://") || strings.HasPrefix(tlsURL, "grpcs://") {
22+
return true
23+
}
24+
return false
25+
}
26+
27+
// ToAddress is a utility function to trim the GRPC protocol prefix as it is not needed by GO
28+
// if the GRPC protocol is not found, the url is returned unchanged
29+
func ToAddress(url string) string {
30+
if strings.HasPrefix(url, "grpc://") {
31+
return strings.TrimPrefix(url, "grpc://")
32+
}
33+
if strings.HasPrefix(url, "grpcs://") {
34+
return strings.TrimPrefix(url, "grpcs://")
35+
}
36+
if !strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://") {
37+
logger.Warnf("URL '%s' has no prefix. Please enter a prefix as it will be mandatory in a future release", url)
38+
}
39+
return url
40+
}

pkg/fabric-ca-client/fabricca.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
sdkApi "github.com/hyperledger/fabric-sdk-go/api/apifabca"
1414
api "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/api"
1515
fabric_ca "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib"
16+
"github.com/hyperledger/fabric-sdk-go/pkg/config/urlutil"
1617
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
1718
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp"
1819
)
@@ -44,10 +45,14 @@ func NewFabricCAClient(config config.Config, org string) (*FabricCA, error) {
4445
return nil, err
4546
}
4647

48+
if conf == nil {
49+
return nil, errors.Errorf("Orgnization %s have no corresponding CA in the configs", org)
50+
}
51+
4752
//set server CAName
4853
c.Config.CAName = conf.CAName
4954
//set server URL
50-
c.Config.URL = conf.URL
55+
c.Config.URL = urlutil.ToAddress(conf.URL)
5156
//certs file list
5257
c.Config.TLS.CertFiles, err = config.CAServerCertFiles(org)
5358
if err != nil {
@@ -72,7 +77,7 @@ func NewFabricCAClient(config config.Config, org string) (*FabricCA, error) {
7277
}
7378

7479
//TLS flag enabled/disabled
75-
c.Config.TLS.Enabled = config.IsTLSEnabled()
80+
c.Config.TLS.Enabled = urlutil.IsTLSEnabled(conf.URL)
7681
c.Config.MSPDir = config.CAKeyStorePath()
7782
c.Config.CSP = config.CSPConfig()
7883

0 commit comments

Comments
 (0)