Skip to content

Commit

Permalink
[FAB-10568] identity config refactoring
Browse files Browse the repository at this point in the history
- identity config functions to return only
required information.
- separate structs for unmarshalling and for entity returns


Change-Id: I18a2c8cf5c95b65101137d81559ba2d2c7d80c45
Signed-off-by: Sudesh Shetty <sudesh.shetty@securekey.com>
  • Loading branch information
sudeshrshetty committed Jun 7, 2018
1 parent 1957fe7 commit 6599f55
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 124 deletions.
2 changes: 1 addition & 1 deletion pkg/client/msp/client_test.go
Expand Up @@ -38,7 +38,7 @@ const (
var caServerURL string

type nwConfig struct {
CertificateAuthorities map[string]msp.CAConfig
CertificateAuthorities map[string]mspImpl.CAConfig
}

// TestMSP is a unit test for Client enrollment and re-enrollment scenarios
Expand Down
14 changes: 8 additions & 6 deletions pkg/common/providers/msp/provider.go
Expand Up @@ -8,7 +8,6 @@ package msp

import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/endpoint"
logApi "github.com/hyperledger/fabric-sdk-go/pkg/core/logging/api"
)

Expand Down Expand Up @@ -39,7 +38,8 @@ type ClientConfig struct {
Organization string
Logging logApi.LoggingType
CryptoConfig CCType
TLSCerts endpoint.MutualTLSConfig
TLSKey []byte
TLSCert []byte
CredentialStore CredentialStoreType
}

Expand All @@ -64,10 +64,12 @@ type EnrollCredentials struct {

// CAConfig defines a CA configuration
type CAConfig struct {
URL string
TLSCACerts endpoint.MutualTLSConfig
Registrar EnrollCredentials
CAName string
URL string
Registrar EnrollCredentials
CAName string
TLSCAServerCerts [][]byte
TLSCAClientCert []byte
TLSCAClientKey []byte
}

// Providers represents a provider of MSP service.
Expand Down
17 changes: 13 additions & 4 deletions pkg/fab/endpointconfig.go
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/logging"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
commtls "github.com/hyperledger/fabric-sdk-go/pkg/core/config/comm/tls"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/cryptoutil"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/endpoint"
Expand Down Expand Up @@ -111,7 +110,18 @@ type entityMatchers struct {

//endpointConfigEntity contains endpoint config elements needed by endpointconfig
type endpointConfigEntity struct {
Client msp.ClientConfig
Client clientConfig
}

// ClientConfig provides the definition of the client configuration
type clientConfig struct {
Organization string
TLSCerts clientTLSConfig
}

type clientTLSConfig struct {
//Client TLS information
Client endpoint.TLSKeyPair
}

// Timeout reads timeouts for the given timeout type, if type is not found in the config
Expand Down Expand Up @@ -309,7 +319,7 @@ func (c *EndpointConfig) TLSClientCerts() []tls.Certificate {
return c.tlsClientCerts
}

func (c *EndpointConfig) loadPrivateKeyFromConfig(clientConfig *msp.ClientConfig, clientCerts tls.Certificate, cb []byte) ([]tls.Certificate, error) {
func (c *EndpointConfig) loadPrivateKeyFromConfig(clientConfig *clientConfig, clientCerts tls.Certificate, cb []byte) ([]tls.Certificate, error) {

kb := clientConfig.TLSCerts.Client.Key.Bytes()

Expand Down Expand Up @@ -556,7 +566,6 @@ func (c *EndpointConfig) loadClientTLSConfig(configEntity *endpointConfigEntity)
//Clients Config
//resolve paths and org name
configEntity.Client.Organization = strings.ToLower(configEntity.Client.Organization)
configEntity.Client.TLSCerts.Path = pathvar.Subst(configEntity.Client.TLSCerts.Path)
configEntity.Client.TLSCerts.Client.Key.Path = pathvar.Subst(configEntity.Client.TLSCerts.Client.Key.Path)
configEntity.Client.TLSCerts.Client.Cert.Path = pathvar.Subst(configEntity.Client.TLSCerts.Client.Cert.Path)

Expand Down
27 changes: 14 additions & 13 deletions pkg/fab/mocks/mockconfig.go
Expand Up @@ -70,20 +70,21 @@ func (c *MockConfig) Client() *msp.ClientConfig {
}

if c.mutualTLSEnabled {
mutualTLSCerts := endpoint.MutualTLSConfig{

Client: endpoint.TLSKeyPair{
Key: endpoint.TLSConfig{
Path: "../../../test/fixtures/config/mutual_tls/client_sdk_go-key.pem",
Pem: "",
},
Cert: endpoint.TLSConfig{
Path: "../../../test/fixtures/config/mutual_tls/client_sdk_go.pem",
Pem: "",
},
},
key := endpoint.TLSConfig{Path: "../../../test/fixtures/config/mutual_tls/client_sdk_go-key.pem"}
cert := endpoint.TLSConfig{Path: "../../../test/fixtures/config/mutual_tls/client_sdk_go.pem"}

err := key.LoadBytes()
if err != nil {
panic(err)
}

err = cert.LoadBytes()
if err != nil {
panic(err)
}
clientConfig.TLSCerts = mutualTLSCerts

clientConfig.TLSKey = key.Bytes()
clientConfig.TLSCert = cert.Bytes()
}

return &clientConfig
Expand Down
26 changes: 19 additions & 7 deletions pkg/fabsdk/fabsdk_chconfig_test.go
Expand Up @@ -13,13 +13,14 @@ import (

"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
mspImpl "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/endpoint"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/lookup"
mockCore "github.com/hyperledger/fabric-sdk-go/pkg/core/mocks"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/provider/chpvdr"
"github.com/hyperledger/fabric-sdk-go/pkg/msp"
"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -151,19 +152,30 @@ func getCustomBackend() ([]core.ConfigBackend, error) {
}

//read existing client config from config
clientConfig := &mspImpl.ClientConfig{}
configLookup := lookup.New(backend...)
err = configLookup.UnmarshalKey("client", clientConfig)
if err != nil {
return nil, err
res, ok := configLookup.Lookup("client")
if !ok {
return nil, errors.New("failed to created custom backend for test")
}
resMap := res.(map[string]interface{})
//update it
clientConfig.Organization = "org2"
resMap["organization"] = "org2"

//set it to backend map
backendMap := make(map[string]interface{})
backendMap["client"] = clientConfig
backendMap["client"] = resMap

backends := append([]core.ConfigBackend{}, &mockCore.MockConfigBackend{KeyValueMap: backendMap})
return append(backends, backend...), nil
}

// ClientConfig provides the definition of the client configuration
type customClientConfig struct {
Organization string
TLSCerts clientTLSConfig
}

type clientTLSConfig struct {
//Client TLS information
Client endpoint.TLSKeyPair
}

0 comments on commit 6599f55

Please sign in to comment.