Skip to content

Commit 53efa19

Browse files
author
Jason Yellick
committed
[FAB-4443] Do not sign configtx with Noop MSP
Because it has no crypto identity, configtxgen uses the noop signer as the parameter to the channel creation helpers which require it. Unfortunately, this creates an unreadable garbage signature in the output of the channel creation transaction. This behavior does not prevent channel creation from occurring, because of the multi-sig nature of the messages, but, it does cause nasty error messages to appear in the log. This CR removes the use of the noop MSP and instead fixes the method which depended on having a non-nil signer passed in to accept a nil signer and omit signatures instead. Change-Id: I634ab2756a31aaa12a39b5b820bb68516d217a41 Signed-off-by: Jason Yellick <[email protected]>
1 parent 52853f8 commit 53efa19

File tree

3 files changed

+71
-23
lines changed

3 files changed

+71
-23
lines changed

common/configtx/template.go

+24-16
Original file line numberDiff line numberDiff line change
@@ -244,36 +244,44 @@ func (cct *channelCreationTemplate) Envelope(channelID string) (*cb.ConfigUpdate
244244

245245
// MakeChainCreationTransaction is a handy utility function for creating new chain transactions using the underlying Template framework
246246
func MakeChainCreationTransaction(channelID string, consortium string, signer msp.SigningIdentity, orgs ...string) (*cb.Envelope, error) {
247-
sSigner, err := signer.Serialize()
248-
if err != nil {
249-
return nil, fmt.Errorf("Serialization of identity failed, err %s", err)
250-
}
251-
252247
newChainTemplate := NewChainCreationTemplate(consortium, orgs)
253248
newConfigUpdateEnv, err := newChainTemplate.Envelope(channelID)
254249
if err != nil {
255250
return nil, err
256251
}
257-
newConfigUpdateEnv.Signatures = []*cb.ConfigSignature{&cb.ConfigSignature{
258-
SignatureHeader: utils.MarshalOrPanic(utils.MakeSignatureHeader(sSigner, utils.CreateNonceOrPanic())),
259-
}}
260252

261-
newConfigUpdateEnv.Signatures[0].Signature, err = signer.Sign(util.ConcatenateBytes(newConfigUpdateEnv.Signatures[0].SignatureHeader, newConfigUpdateEnv.ConfigUpdate))
262-
if err != nil {
263-
return nil, err
253+
payloadSignatureHeader := &cb.SignatureHeader{}
254+
if signer != nil {
255+
sSigner, err := signer.Serialize()
256+
if err != nil {
257+
return nil, fmt.Errorf("Serialization of identity failed, err %s", err)
258+
}
259+
260+
newConfigUpdateEnv.Signatures = []*cb.ConfigSignature{&cb.ConfigSignature{
261+
SignatureHeader: utils.MarshalOrPanic(utils.MakeSignatureHeader(sSigner, utils.CreateNonceOrPanic())),
262+
}}
263+
264+
newConfigUpdateEnv.Signatures[0].Signature, err = signer.Sign(util.ConcatenateBytes(newConfigUpdateEnv.Signatures[0].SignatureHeader, newConfigUpdateEnv.ConfigUpdate))
265+
if err != nil {
266+
return nil, err
267+
}
268+
269+
payloadSignatureHeader = utils.MakeSignatureHeader(sSigner, utils.CreateNonceOrPanic())
264270
}
265271

266272
payloadChannelHeader := utils.MakeChannelHeader(cb.HeaderType_CONFIG_UPDATE, msgVersion, channelID, epoch)
267-
payloadSignatureHeader := utils.MakeSignatureHeader(sSigner, utils.CreateNonceOrPanic())
268273
utils.SetTxID(payloadChannelHeader, payloadSignatureHeader)
269274
payloadHeader := utils.MakePayloadHeader(payloadChannelHeader, payloadSignatureHeader)
270275
payload := &cb.Payload{Header: payloadHeader, Data: utils.MarshalOrPanic(newConfigUpdateEnv)}
271276
paylBytes := utils.MarshalOrPanic(payload)
272277

273-
// sign the payload
274-
sig, err := signer.Sign(paylBytes)
275-
if err != nil {
276-
return nil, err
278+
var sig []byte
279+
if signer != nil {
280+
// sign the payload
281+
sig, err = signer.Sign(paylBytes)
282+
if err != nil {
283+
return nil, err
284+
}
277285
}
278286

279287
return &cb.Envelope{Payload: paylBytes, Signature: sig}, nil

common/configtx/template_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import (
2121
"testing"
2222

2323
"github.com/hyperledger/fabric/common/config"
24+
mmsp "github.com/hyperledger/fabric/common/mocks/msp"
2425
cb "github.com/hyperledger/fabric/protos/common"
26+
"github.com/hyperledger/fabric/protos/utils"
2527

2628
"github.com/golang/protobuf/proto"
2729
"github.com/stretchr/testify/assert"
@@ -146,3 +148,47 @@ func TestNewChainTemplate(t *testing.T) {
146148
assert.True(t, ok, "Expected to find %s but did not", org)
147149
}
148150
}
151+
152+
func TestMakeChainCreationTransactionWithSigner(t *testing.T) {
153+
channelID := "foo"
154+
155+
signer, err := mmsp.NewNoopMsp().GetDefaultSigningIdentity()
156+
assert.NoError(t, err, "Creating noop MSP")
157+
158+
cct, err := MakeChainCreationTransaction(channelID, "test", signer)
159+
assert.NoError(t, err, "Making chain creation tx")
160+
161+
assert.NotEmpty(t, cct.Signature, "Should have signature")
162+
163+
payload, err := utils.UnmarshalPayload(cct.Payload)
164+
assert.NoError(t, err, "Unmarshaling payload")
165+
166+
configUpdateEnv, err := UnmarshalConfigUpdateEnvelope(payload.Data)
167+
assert.NoError(t, err, "Unmarshaling ConfigUpdateEnvelope")
168+
169+
assert.NotEmpty(t, configUpdateEnv.Signatures, "Should have config env sigs")
170+
171+
sigHeader, err := utils.GetSignatureHeader(payload.Header.SignatureHeader)
172+
assert.NoError(t, err, "Unmarshaling SignatureHeader")
173+
assert.NotEmpty(t, sigHeader.Creator, "Creator specified")
174+
}
175+
176+
func TestMakeChainCreationTransactionNoSigner(t *testing.T) {
177+
channelID := "foo"
178+
cct, err := MakeChainCreationTransaction(channelID, "test", nil)
179+
assert.NoError(t, err, "Making chain creation tx")
180+
181+
assert.Empty(t, cct.Signature, "Should have empty signature")
182+
183+
payload, err := utils.UnmarshalPayload(cct.Payload)
184+
assert.NoError(t, err, "Unmarshaling payload")
185+
186+
configUpdateEnv, err := UnmarshalConfigUpdateEnvelope(payload.Data)
187+
assert.NoError(t, err, "Unmarshaling ConfigUpdateEnvelope")
188+
189+
assert.Empty(t, configUpdateEnv.Signatures, "Should have no config env sigs")
190+
191+
sigHeader, err := utils.GetSignatureHeader(payload.Header.SignatureHeader)
192+
assert.NoError(t, err, "Unmarshaling SignatureHeader")
193+
assert.Empty(t, sigHeader.Creator, "No creator specified")
194+
}

common/configtx/tool/configtxgen/main.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
"github.com/hyperledger/fabric/protos/utils"
3636

3737
"github.com/golang/protobuf/proto"
38-
mmsp "github.com/hyperledger/fabric/common/mocks/msp"
3938
logging "github.com/op/go-logging"
4039
)
4140

@@ -61,11 +60,6 @@ func doOutputBlock(config *genesisconfig.Profile, channelID string, outputBlock
6160

6261
func doOutputChannelCreateTx(conf *genesisconfig.Profile, channelID string, outputChannelCreateTx string) error {
6362
logger.Info("Generating new channel configtx")
64-
// TODO, use actual MSP eventually
65-
signer, err := mmsp.NewNoopMsp().GetDefaultSigningIdentity()
66-
if err != nil {
67-
return fmt.Errorf("Error getting signing identity: %s", err)
68-
}
6963

7064
if conf.Application == nil {
7165
return fmt.Errorf("Cannot define a new channel with no Application section")
@@ -82,7 +76,7 @@ func doOutputChannelCreateTx(conf *genesisconfig.Profile, channelID string, outp
8276
for _, org := range conf.Application.Organizations {
8377
orgNames = append(orgNames, org.Name)
8478
}
85-
configtx, err := configtx.MakeChainCreationTransaction(channelID, conf.Consortium, signer, orgNames...)
79+
configtx, err := configtx.MakeChainCreationTransaction(channelID, conf.Consortium, nil, orgNames...)
8680
if err != nil {
8781
return fmt.Errorf("Error generating configtx: %s", err)
8882
}

0 commit comments

Comments
 (0)