Skip to content

Commit

Permalink
Remove redundant identity unmarshaling
Browse files Browse the repository at this point in the history
Within core/endorser/msgvalidation.go:170 there is a code

```go
 sId, err := protoutil.UnmarshalSerializedIdentity(up.SignatureHeader.Creator)
 if err != nil {
    return errors.Errorf("access denied: channel
            [%s] creator org unknown, creator is malformed",
                        up.ChannelID())
}
```

which is later on repeated with

```go
creator, err := idDeserializer.DeserializeIdentity(up.SignatureHeader.Creator)

```

this commit removes first block due to its redundancy.

Signed-off-by: Artem Barger <bartem@il.ibm.com>
  • Loading branch information
C0rWin committed Dec 30, 2020
1 parent a953bbe commit 33711c1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 26 deletions.
8 changes: 4 additions & 4 deletions core/endorser/endorser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ var _ = Describe("Endorser", func() {

It("wraps and returns an error and responds to the client", func() {
proposalResponse, err := e.ProcessProposal(context.Background(), signedProposal)
Expect(err).To(MatchError("error validating proposal: access denied: channel [channel-id] creator org [msp-id]"))
Expect(err).To(MatchError("error validating proposal: access denied: channel [channel-id] creator org unknown, creator is malformed"))
Expect(proposalResponse).To(Equal(&pb.ProposalResponse{
Response: &pb.Response{
Status: 500,
Message: "error validating proposal: access denied: channel [channel-id] creator org [msp-id]",
Message: "error validating proposal: access denied: channel [channel-id] creator org unknown, creator is malformed",
},
}))
})
Expand Down Expand Up @@ -618,11 +618,11 @@ var _ = Describe("Endorser", func() {

It("wraps and returns an error and responds to the client", func() {
proposalResponse, err := e.ProcessProposal(context.Background(), signedProposal)
Expect(err).To(MatchError("error validating proposal: access denied: channel [] creator org [msp-id]"))
Expect(err).To(MatchError("error validating proposal: access denied: channel [] creator org unknown, creator is malformed"))
Expect(proposalResponse).To(Equal(&pb.ProposalResponse{
Response: &pb.Response{
Status: 500,
Message: "error validating proposal: access denied: channel [] creator org [msp-id]",
Message: "error validating proposal: access denied: channel [] creator org unknown, creator is malformed",
},
}))
})
Expand Down
10 changes: 2 additions & 8 deletions core/endorser/msgvalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,14 @@ func (up *UnpackedProposal) Validate(idDeserializer msp.IdentityDeserializer) er
return errors.Errorf("empty signature bytes")
}

sId, err := protoutil.UnmarshalSerializedIdentity(up.SignatureHeader.Creator)
if err != nil {
return errors.Errorf("access denied: channel [%s] creator org unknown, creator is malformed", up.ChannelID())
}

genericAuthError := errors.Errorf("access denied: channel [%s] creator org [%s]", up.ChannelID(), sId.Mspid)

// get the identity of the creator
creator, err := idDeserializer.DeserializeIdentity(up.SignatureHeader.Creator)
if err != nil {
logger.Warningf("access denied: channel %s", err)
return genericAuthError
return errors.Errorf("access denied: channel [%s] creator org unknown, creator is malformed", up.ChannelID())
}

genericAuthError := errors.Errorf("access denied: channel [%s] creator org [%s]", up.ChannelID(), creator.GetMSPIdentifier())
// ensure that creator is a valid certificate
err = creator.Validate()
if err != nil {
Expand Down
16 changes: 3 additions & 13 deletions core/endorser/msgvalidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,31 +446,20 @@ var _ = Describe("Validate", func() {
})
})

Context("when the identity is actually not a validly serialized proto", func() {
BeforeEach(func() {
up.SignatureHeader.Creator = []byte("garbage")
up.ChannelHeader.TxId = "8f9de857052f103caee0fef35f66766562b4b4c2a14af34e9626351de52edfc4"
})

It("returns an auth error", func() {
err := up.Validate(fakeIdentityDeserializer)
Expect(err).To(MatchError("access denied: channel [channel-id] creator org unknown, creator is malformed"))
})
})

Context("when the identity cannot be deserialized", func() {
BeforeEach(func() {
fakeIdentityDeserializer.DeserializeIdentityReturns(nil, fmt.Errorf("fake-deserializing-error"))
})

It("returns a generic auth error", func() {
err := up.Validate(fakeIdentityDeserializer)
Expect(err).To(MatchError("access denied: channel [channel-id] creator org [mspid]"))
Expect(err).To(MatchError("access denied: channel [channel-id] creator org unknown, creator is malformed"))
})
})

Context("when the identity is not valid", func() {
BeforeEach(func() {
fakeIdentity.GetMSPIdentifierReturns("mspid")
fakeIdentity.ValidateReturns(fmt.Errorf("fake-validate-error"))
})

Expand All @@ -482,6 +471,7 @@ var _ = Describe("Validate", func() {

Context("when the identity signature is not valid", func() {
BeforeEach(func() {
fakeIdentity.GetMSPIdentifierReturns("mspid")
fakeIdentity.VerifyReturns(fmt.Errorf("fake-verify-error"))
})

Expand Down
2 changes: 1 addition & 1 deletion integration/e2e/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ var _ = Describe("EndToEndACL", func() {
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit())
Expect(sess.Err).To(gbytes.Say(`access denied: channel \[\] creator org \[Org2MSP\]`))
Expect(sess.Err).To(gbytes.Say(`access denied: channel \[\] creator org unknown, creator is malformed`))

By("installing the chaincode to an org1 peer as a non-admin org1 identity")
sess, err = network.PeerUserSession(org1Peer0, "User1", commands.ChaincodeInstall{
Expand Down

0 comments on commit 33711c1

Please sign in to comment.