Skip to content

Commit d03614c

Browse files
authored
remove MetaNamespaceVerificationKey (#74)
#### Type of change - Improvement (improvement to code, performance, etc) #### Description As we are planning to use LifecycleEndorsementPolicy instead of MetaNamespaceVerificationKey, we can remove it from the config block. #### Related issues - resolves #58 Signed-off-by: Senthilnathan <cendhu@gmail.com>
1 parent d7dc119 commit d03614c

File tree

9 files changed

+13
-132
lines changed

9 files changed

+13
-132
lines changed

common/channelconfig/application.go

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

99
import (
1010
cb "github.com/hyperledger/fabric-protos-go-apiv2/common"
11-
"github.com/hyperledger/fabric-protos-go-apiv2/msp"
1211
pb "github.com/hyperledger/fabric-protos-go-apiv2/peer"
1312
"github.com/pkg/errors"
1413

@@ -21,15 +20,12 @@ const (
2120

2221
// ACLsKey is the name of the ACLs config
2322
ACLsKey = "ACLs"
24-
25-
MetaNamespaceVerificationKey = "MetaNamespaceVerificationKey"
2623
)
2724

2825
// ApplicationProtos is used as the source of the ApplicationConfig
2926
type ApplicationProtos struct {
30-
ACLs *pb.ACLs
31-
Capabilities *cb.Capabilities
32-
MetaNamespaceVerificationKey *msp.KeyInfo
27+
ACLs *pb.ACLs
28+
Capabilities *cb.Capabilities
3329
}
3430

3531
// ApplicationConfig implements the Application interface
@@ -82,8 +78,3 @@ func (ac *ApplicationConfig) APIPolicyMapper() PolicyMapper {
8278

8379
return pm
8480
}
85-
86-
// MetaNamespaceVerificationKey returns the meta-namespace verification key
87-
func (ac *ApplicationConfig) MetaNamespaceVerificationKey() *msp.KeyInfo {
88-
return ac.protos.MetaNamespaceVerificationKey
89-
}

common/channelconfig/util.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
77
package channelconfig
88

99
import (
10-
"crypto/x509"
1110
"fmt"
1211
"math"
1312
"os"
@@ -185,16 +184,6 @@ func CapabilitiesValue(capabilities map[string]bool) *StandardConfigValue {
185184
}
186185
}
187186

188-
func MetaNamespaceVerificationKeyValue(key []byte) *StandardConfigValue {
189-
return &StandardConfigValue{
190-
key: MetaNamespaceVerificationKey,
191-
// We use existing proto here to avoid introducing new once.
192-
// So we encode the key schema as the identifier.
193-
// This will be replaced in the future with a generic policy mechanism.
194-
value: &mspprotos.KeyInfo{KeyIdentifier: x509.ECDSA.String(), KeyMaterial: key},
195-
}
196-
}
197-
198187
func OrderersValue(consenters []*cb.Consenter) *StandardConfigValue {
199188
o := &cb.Orderers{
200189
ConsenterMapping: consenters,

protolator/protoext/peerext/configuration.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ func (ccv *DynamicApplicationConfigValue) StaticallyOpaqueFieldProto(name string
105105
return &common.Capabilities{}, nil
106106
case "ACLs":
107107
return &peer.ACLs{}, nil
108-
case "MetaNamespaceVerificationKey":
109-
return &msp.KeyInfo{}, nil
110108
default:
111109
return nil, fmt.Errorf("Unknown Application ConfigValue name: %s", ccv.name)
112110
}

sampleconfig/configtx.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,6 @@ Profiles:
807807

808808
Application: &FabricXApplicationDefaults
809809
<<: *ApplicationDefaults
810-
# This certificate is used to validate meta-namespace transactions.
811-
# This is a temporary solution (fabric-x). It will be removed once the committer will support MSP policies.
812-
# The matching private key can be found under crypto/SampleOrg/msp/keystore/key.pem
813-
MetaNamespaceVerificationKeyPath: crypto/SampleOrg/msp/admincerts/admincert.pem
814810
Organizations:
815811
- <<: *SampleOrg
816812

tools/configtxgen/config.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,10 @@ type Consortium struct {
118118
// Application encodes the application-level configuration needed in config
119119
// transactions.
120120
type Application struct {
121-
Organizations []*Organization `yaml:"Organizations"`
122-
Capabilities map[string]bool `yaml:"Capabilities"`
123-
Policies map[string]*Policy `yaml:"Policies"`
124-
ACLs map[string]string `yaml:"ACLs"`
125-
MetaNamespaceVerificationKeyPath string `yaml:"MetaNamespaceVerificationKeyPath"`
121+
Organizations []*Organization `yaml:"Organizations"`
122+
Capabilities map[string]bool `yaml:"Capabilities"`
123+
Policies map[string]*Policy `yaml:"Policies"`
124+
ACLs map[string]string `yaml:"ACLs"`
126125
}
127126

128127
// Organization encodes the organization-level configuration needed in
@@ -306,9 +305,6 @@ func (p *Profile) CompleteInitialization(configDir string) {
306305
for _, org := range p.Application.Organizations {
307306
org.completeInitialization(configDir)
308307
}
309-
if p.Application.MetaNamespaceVerificationKeyPath != "" {
310-
cf.TranslatePathInPlace(configDir, &p.Application.MetaNamespaceVerificationKeyPath)
311-
}
312308
}
313309

314310
if p.Consortiums != nil {

tools/configtxgen/encoder.go

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ SPDX-License-Identifier: Apache-2.0
77
package configtxgen
88

99
import (
10-
"crypto/ecdsa"
11-
"crypto/x509"
12-
"encoding/pem"
1310
"fmt"
1411
"os"
1512

@@ -383,15 +380,6 @@ func NewApplicationGroup(conf *Application) (*cb.ConfigGroup, error) {
383380
addValue(applicationGroup, channelconfig.CapabilitiesValue(conf.Capabilities), channelconfig.AdminsPolicyKey)
384381
}
385382

386-
if len(conf.MetaNamespaceVerificationKeyPath) > 0 {
387-
key, err := getPubKeyFromPem(conf.MetaNamespaceVerificationKeyPath)
388-
if err != nil {
389-
return nil, errors.Wrapf(err, "error reading metanamespace verification key")
390-
}
391-
addValue(applicationGroup,
392-
channelconfig.MetaNamespaceVerificationKeyValue(key), channelconfig.AdminsPolicyKey)
393-
}
394-
395383
for _, org := range conf.Organizations {
396384
var err error
397385
applicationGroup.Groups[org.Name], err = NewApplicationOrgGroup(org)
@@ -404,68 +392,6 @@ func NewApplicationGroup(conf *Application) (*cb.ConfigGroup, error) {
404392
return applicationGroup, nil
405393
}
406394

407-
// getPubKeyFromPem looks for ECDSA public key in PEM file, and returns pem content only with the public key.
408-
func getPubKeyFromPem(file string) ([]byte, error) {
409-
pemContent, err := os.ReadFile(file)
410-
if err != nil {
411-
return nil, errors.Wrapf(err, "reading from file %s failed", file)
412-
}
413-
414-
for {
415-
block, rest := pem.Decode(pemContent)
416-
if block == nil {
417-
break
418-
}
419-
pemContent = rest
420-
421-
logger.Infof("Reading block [%s] from file: %s", block.Type, file)
422-
423-
key, err := ParseCertificateOrPublicKey(block.Bytes)
424-
if err != nil {
425-
continue
426-
}
427-
return pem.EncodeToMemory(&pem.Block{
428-
Type: "PUBLIC KEY",
429-
Bytes: key,
430-
}), nil
431-
432-
}
433-
434-
return nil, errors.New("no ECDSA public key in pem file")
435-
}
436-
437-
func ParseCertificateOrPublicKey(blockBytes []byte) ([]byte, error) {
438-
// Try reading certificate
439-
cert, err := x509.ParseCertificate(blockBytes)
440-
var publicKey any
441-
if err == nil {
442-
if cert.PublicKey != nil && cert.PublicKeyAlgorithm == x509.ECDSA {
443-
logger.Info("Found certificate with ECDSA public key in block")
444-
publicKey = cert.PublicKey
445-
}
446-
} else {
447-
// If fails, try reading public key
448-
anyPublicKey, err := x509.ParsePKIXPublicKey(blockBytes)
449-
if err == nil && anyPublicKey != nil {
450-
var isECDSA bool
451-
publicKey, isECDSA = anyPublicKey.(*ecdsa.PublicKey)
452-
if isECDSA {
453-
logger.Info("Found ECDSA public key in block")
454-
}
455-
}
456-
}
457-
458-
if publicKey == nil {
459-
return nil, errors.New("no ECDSA public key in block")
460-
}
461-
462-
key, err := x509.MarshalPKIXPublicKey(publicKey)
463-
if err != nil {
464-
return nil, errors.Wrapf(err, "marshalling public key from failed")
465-
}
466-
return key, nil
467-
}
468-
469395
// NewApplicationOrgGroup returns an application org component of the channel configuration. It defines the crypto material for the organization
470396
// (its MSP) as well as its anchor peers for use by the gossip network. It sets the mod_policy of all elements to "Admins".
471397
func NewApplicationOrgGroup(conf *Organization) (*cb.ConfigGroup, error) {

tools/configtxgen/tools_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ func TestBftOrdererTypeWithV3CapabilitiesShouldNotRaiseAnError(t *testing.T) {
170170
func TestFabricXGenesisBlock(t *testing.T) {
171171
t.Parallel()
172172

173-
keyPath := filepath.Join(configtest.GetDevConfigDir(), "crypto", "SampleOrg", "msp", "signcerts", "peer.pem")
174173
allAPI := []string{types.Broadcast, types.Deliver}
175174

176175
for _, tc := range []struct {
@@ -199,7 +198,6 @@ func TestFabricXGenesisBlock(t *testing.T) {
199198
t.Parallel()
200199
blockDest := filepath.Join(t.TempDir(), "block")
201200
config := Load(tc.sample, configtest.GetDevConfigDir())
202-
config.Application.MetaNamespaceVerificationKeyPath = keyPath
203201
armaPath := filepath.Join(configtest.GetDevConfigDir(), "arma_shared_config.pbbin")
204202
config.Orderer.Arma.Path = armaPath
205203
require.NoError(t, DoOutputBlock(config, "foo", blockDest))

tools/cryptogen/config_block.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ import (
2424

2525
// ConfigBlockParameters represents the configuration of the config block.
2626
type ConfigBlockParameters struct {
27-
TargetPath string
28-
BaseProfile string
29-
ChannelID string
30-
Organizations []OrganizationParameters
31-
MetaNamespaceVerificationKey []byte
32-
ArmaMetaBytes []byte
27+
TargetPath string
28+
BaseProfile string
29+
ChannelID string
30+
Organizations []OrganizationParameters
31+
ArmaMetaBytes []byte
3332
}
3433

3534
// OrganizationParameters represents the properties of an organization.
@@ -60,7 +59,6 @@ type OrdererEndpoint struct {
6059
// file names.
6160
const (
6261
ConfigBlockFileName = "config-block.pb.bin"
63-
metaNamespaceFile = "meta-namespace-cert.pem"
6462
armaDataFile = "arma.pb.bin"
6563
)
6664

@@ -137,11 +135,6 @@ func CreateDefaultConfigBlockWithCrypto(conf ConfigBlockParameters) (*common.Blo
137135
}
138136
}
139137

140-
err = os.WriteFile(path.Join(conf.TargetPath, metaNamespaceFile), conf.MetaNamespaceVerificationKey, 0o644)
141-
if err != nil {
142-
return nil, errors.Wrap(err, "failed to write meta namespace file")
143-
}
144-
profile.Application.MetaNamespaceVerificationKeyPath = metaNamespaceFile
145138
err = os.WriteFile(path.Join(conf.TargetPath, armaDataFile), conf.ArmaMetaBytes, 0o644)
146139
if err != nil {
147140
return nil, errors.Wrap(err, "failed to write ARMA data file")

tools/cryptogen/config_block_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package cryptogen
99
import (
1010
"crypto/tls"
1111
"crypto/x509"
12-
"encoding/pem"
1312
"net"
1413
"os"
1514
"path"
@@ -347,11 +346,6 @@ func defaultConfigBlock(t *testing.T) (
347346
target = t.TempDir()
348347
armaData = []byte("fake-arma-data")
349348

350-
key, err := generatePrivateKey(target, ECDSA)
351-
require.NoError(t, err)
352-
certBytes, err := x509.MarshalPKIXPublicKey(getPublicKey(key))
353-
require.NoError(t, err)
354-
metaKeyBytes := pem.EncodeToMemory(&pem.Block{Type: CertType, Bytes: certBytes})
355349
p := ConfigBlockParameters{
356350
TargetPath: target,
357351
ChannelID: "my-chan",
@@ -413,10 +407,10 @@ func defaultConfigBlock(t *testing.T) (
413407
},
414408
},
415409
},
416-
ArmaMetaBytes: armaData,
417-
MetaNamespaceVerificationKey: metaKeyBytes,
410+
ArmaMetaBytes: armaData,
418411
}
419412

413+
var err error
420414
block, err = CreateDefaultConfigBlockWithCrypto(p)
421415
require.NoError(t, err)
422416
require.NotNil(t, block)

0 commit comments

Comments
 (0)