Skip to content

Commit

Permalink
[FAB-2695] (PA) mv msp_principal.proto protos/msp
Browse files Browse the repository at this point in the history
This is intended for (PA) post-alpha.

https://jira.hyperledger.org/browse/FAB-2695

Before the proto compilation was fixed to handle importing protos across
directories, the msp_principal.proto was put into protos/common/.  It
does not make sense here, as it is only MSP related, and it belongs in
protos/msp/.

Note, that is an API change only, no ABI is modified, so this should not
impact existing clients until the regenerate the protobufs.

Change-Id: I72f52354d76e25237ad4831e8e25d6c9772196f6
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Mar 22, 2017
1 parent 07320ea commit a4e80cd
Show file tree
Hide file tree
Showing 21 changed files with 198 additions and 194 deletions.
3 changes: 2 additions & 1 deletion common/cauthdsl/cauthdsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import (

"github.com/hyperledger/fabric/msp"
cb "github.com/hyperledger/fabric/protos/common"
mb "github.com/hyperledger/fabric/protos/msp"
"github.com/op/go-logging"
)

var cauthdslLogger = logging.MustGetLogger("cauthdsl")

// compile recursively builds a go evaluatable function corresponding to the policy specified
func compile(policy *cb.SignaturePolicy, identities []*cb.MSPPrincipal, deserializer msp.IdentityDeserializer) (func([]*cb.SignedData, []bool) bool, error) {
func compile(policy *cb.SignaturePolicy, identities []*mb.MSPPrincipal, deserializer msp.IdentityDeserializer) (func([]*cb.SignedData, []bool) bool, error) {
switch t := policy.Type.(type) {
case *cb.SignaturePolicy_NOutOf_:
policies := make([]func([]*cb.SignedData, []bool) bool, len(t.NOutOf.Policies))
Expand Down
21 changes: 11 additions & 10 deletions common/cauthdsl/cauthdsl_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cauthdsl

import (
cb "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/msp"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/protos/utils"
Expand Down Expand Up @@ -53,9 +54,9 @@ func init() {

// Envelope builds an envelope message embedding a SignaturePolicy
func Envelope(policy *cb.SignaturePolicy, identities [][]byte) *cb.SignaturePolicyEnvelope {
ids := make([]*cb.MSPPrincipal, len(identities))
ids := make([]*msp.MSPPrincipal, len(identities))
for i, _ := range ids {
ids[i] = &cb.MSPPrincipal{PrincipalClassification: cb.MSPPrincipal_IDENTITY, Principal: identities[i]}
ids[i] = &msp.MSPPrincipal{PrincipalClassification: msp.MSPPrincipal_IDENTITY, Principal: identities[i]}
}

return &cb.SignaturePolicyEnvelope{
Expand All @@ -78,15 +79,15 @@ func SignedBy(index int32) *cb.SignaturePolicy {
// requiring 1 signature from any member of the specified MSP
func SignedByMspMember(mspId string) *cb.SignaturePolicyEnvelope {
// specify the principal: it's a member of the msp we just found
principal := &cb.MSPPrincipal{
PrincipalClassification: cb.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&cb.MSPRole{Role: cb.MSPRole_MEMBER, MspIdentifier: mspId})}
principal := &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: mspId})}

// create the policy: it requires exactly 1 signature from the first (and only) principal
p := &cb.SignaturePolicyEnvelope{
Version: 0,
Policy: NOutOf(1, []*cb.SignaturePolicy{SignedBy(0)}),
Identities: []*cb.MSPPrincipal{principal},
Identities: []*msp.MSPPrincipal{principal},
}

return p
Expand All @@ -96,15 +97,15 @@ func SignedByMspMember(mspId string) *cb.SignaturePolicyEnvelope {
// requiring 1 signature from any admin of the specified MSP
func SignedByMspAdmin(mspId string) *cb.SignaturePolicyEnvelope {
// specify the principal: it's a member of the msp we just found
principal := &cb.MSPPrincipal{
PrincipalClassification: cb.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&cb.MSPRole{Role: cb.MSPRole_ADMIN, MspIdentifier: mspId})}
principal := &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_ADMIN, MspIdentifier: mspId})}

// create the policy: it requires exactly 1 signature from the first (and only) principal
p := &cb.SignaturePolicyEnvelope{
Version: 0,
Policy: NOutOf(1, []*cb.SignaturePolicy{SignedBy(0)}),
Identities: []*cb.MSPPrincipal{principal},
Identities: []*msp.MSPPrincipal{principal},
}

return p
Expand Down
3 changes: 2 additions & 1 deletion common/cauthdsl/cauthdsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/golang/protobuf/proto"
cb "github.com/hyperledger/fabric/protos/common"
mb "github.com/hyperledger/fabric/protos/msp"
)

var invalidSignature = []byte("badsigned")
Expand All @@ -33,7 +34,7 @@ type mockIdentity struct {
idBytes []byte
}

func (id *mockIdentity) SatisfiesPrincipal(p *cb.MSPPrincipal) error {
func (id *mockIdentity) SatisfiesPrincipal(p *mb.MSPPrincipal) error {
if bytes.Compare(id.idBytes, p.Principal) == 0 {
return nil
} else {
Expand Down
17 changes: 9 additions & 8 deletions common/cauthdsl/policyparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/Knetic/govaluate"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/msp"
"github.com/hyperledger/fabric/protos/utils"
)

Expand Down Expand Up @@ -138,17 +139,17 @@ func secondPass(args ...interface{}) (interface{}, error) {
}

/* get the right role */
var r common.MSPRole_MSPRoleType
var r msp.MSPRole_MSPRoleType
if subm[0][3] == "member" {
r = common.MSPRole_MEMBER
r = msp.MSPRole_MEMBER
} else {
r = common.MSPRole_ADMIN
r = msp.MSPRole_ADMIN
}

/* build the principal we've been told */
p := &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{MspIdentifier: subm[0][1], Role: r})}
p := &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{MspIdentifier: subm[0][1], Role: r})}
ctx.principals = append(ctx.principals, p)

/* create a SignaturePolicy that requires a signature from
Expand Down Expand Up @@ -177,11 +178,11 @@ func secondPass(args ...interface{}) (interface{}, error) {

type context struct {
IDNum int
principals []*common.MSPPrincipal
principals []*msp.MSPPrincipal
}

func newContext() *context {
return &context{IDNum: 0, principals: make([]*common.MSPPrincipal, 0)}
return &context{IDNum: 0, principals: make([]*msp.MSPPrincipal, 0)}
}

// FromString takes a string representation of the policy,
Expand Down
75 changes: 38 additions & 37 deletions common/cauthdsl/policyparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"testing"

"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/msp"
"github.com/hyperledger/fabric/protos/utils"
"github.com/stretchr/testify/assert"
)
Expand All @@ -29,15 +30,15 @@ func TestAnd(t *testing.T) {
p1, err := FromString("AND('A.member', 'B.member')")
assert.NoError(t, err)

principals := make([]*common.MSPPrincipal, 0)
principals := make([]*msp.MSPPrincipal, 0)

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "A"})})
principals = append(principals, &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "A"})})

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "B"})})
principals = append(principals, &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "B"})})

p2 := &common.SignaturePolicyEnvelope{
Version: 0,
Expand All @@ -52,15 +53,15 @@ func TestOr(t *testing.T) {
p1, err := FromString("OR('A.member', 'B.member')")
assert.NoError(t, err)

principals := make([]*common.MSPPrincipal, 0)
principals := make([]*msp.MSPPrincipal, 0)

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "A"})})
principals = append(principals, &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "A"})})

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "B"})})
principals = append(principals, &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "B"})})

p2 := &common.SignaturePolicyEnvelope{
Version: 0,
Expand All @@ -75,19 +76,19 @@ func TestComplex1(t *testing.T) {
p1, err := FromString("OR('A.member', AND('B.member', 'C.member'))")
assert.NoError(t, err)

principals := make([]*common.MSPPrincipal, 0)
principals := make([]*msp.MSPPrincipal, 0)

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "B"})})
principals = append(principals, &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "B"})})

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "C"})})
principals = append(principals, &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "C"})})

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "A"})})
principals = append(principals, &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "A"})})

p2 := &common.SignaturePolicyEnvelope{
Version: 0,
Expand All @@ -102,23 +103,23 @@ func TestComplex2(t *testing.T) {
p1, err := FromString("OR(AND('A.member', 'B.member'), OR('C.admin', 'D.member'))")
assert.NoError(t, err)

principals := make([]*common.MSPPrincipal, 0)
principals := make([]*msp.MSPPrincipal, 0)

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "A"})})
principals = append(principals, &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "A"})})

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "B"})})
principals = append(principals, &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "B"})})

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_ADMIN, MspIdentifier: "C"})})
principals = append(principals, &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_ADMIN, MspIdentifier: "C"})})

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "D"})})
principals = append(principals, &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "D"})})

p2 := &common.SignaturePolicyEnvelope{
Version: 0,
Expand Down
7 changes: 4 additions & 3 deletions core/policy/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/protos/common"
mspproto "github.com/hyperledger/fabric/protos/msp"
)

type mockChannelPolicyManagerGetter struct {
Expand Down Expand Up @@ -91,7 +92,7 @@ type mockIdentity struct {
msg []byte
}

func (id *mockIdentity) SatisfiesPrincipal(p *common.MSPPrincipal) error {
func (id *mockIdentity) SatisfiesPrincipal(p *mspproto.MSPPrincipal) error {
if !bytes.Equal(id.identity, p.Principal) {
return fmt.Errorf("Different identities [% x]!=[% x]", id.identity, p.Principal)
}
Expand Down Expand Up @@ -141,6 +142,6 @@ type mockMSPPrincipalGetter struct {
Principal []byte
}

func (m *mockMSPPrincipalGetter) Get(role string) (*common.MSPPrincipal, error) {
return &common.MSPPrincipal{Principal: m.Principal}, nil
func (m *mockMSPPrincipalGetter) Get(role string) (*mspproto.MSPPrincipal, error) {
return &mspproto.MSPPrincipal{Principal: m.Principal}, nil
}
9 changes: 5 additions & 4 deletions core/scc/lccc/lccc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/hyperledger/fabric/core/common/sysccprovider"
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/protos/common"
mspprotos "github.com/hyperledger/fabric/protos/msp"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"
"github.com/op/go-logging"
Expand Down Expand Up @@ -481,12 +482,12 @@ func (lccc *LifeCycleSysCC) getDefaultEndorsementPolicy(chain string) []byte {
// per application MSP defined on this chain
ids := peer.GetMSPIDs(chain)
sort.Strings(ids)
principals := make([]*common.MSPPrincipal, len(ids))
principals := make([]*mspprotos.MSPPrincipal, len(ids))
sigspolicy := make([]*common.SignaturePolicy, len(ids))
for i, id := range ids {
principals[i] = &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: id})}
principals[i] = &mspprotos.MSPPrincipal{
PrincipalClassification: mspprotos.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&mspprotos.MSPRole{Role: mspprotos.MSPRole_MEMBER, MspIdentifier: id})}
sigspolicy[i] = cauthdsl.SignedBy(int32(i))
}

Expand Down
3 changes: 1 addition & 2 deletions msp/identities.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric/bccsp/signer"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/msp"
"github.com/op/go-logging"
)
Expand All @@ -52,7 +51,7 @@ func newIdentity(id *IdentityIdentifier, cert *x509.Certificate, pk bccsp.Key, m
}

// SatisfiesPrincipal returns null if this instance matches the supplied principal or an error otherwise
func (id *identity) SatisfiesPrincipal(principal *common.MSPPrincipal) error {
func (id *identity) SatisfiesPrincipal(principal *msp.MSPPrincipal) error {
return id.msp.SatisfiesPrincipal(id, principal)
}

Expand Down
18 changes: 9 additions & 9 deletions msp/mgmt/principal.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"fmt"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/msp"
)

type MSPPrincipalGetter interface {
// Get returns an MSP principal for the given role
Get(role string) (*common.MSPPrincipal, error)
Get(role string) (*msp.MSPPrincipal, error)
}

func NewLocalMSPPrincipalGetter() MSPPrincipalGetter {
Expand All @@ -34,7 +34,7 @@ func NewLocalMSPPrincipalGetter() MSPPrincipalGetter {

type localMSPPrincipalGetter struct{}

func (m *localMSPPrincipalGetter) Get(role string) (*common.MSPPrincipal, error) {
func (m *localMSPPrincipalGetter) Get(role string) (*msp.MSPPrincipal, error) {
mspid, err := GetLocalMSP().GetIdentifier()
if err != nil {
return nil, fmt.Errorf("Could not extract local msp identifier [%s]", err)
Expand All @@ -43,22 +43,22 @@ func (m *localMSPPrincipalGetter) Get(role string) (*common.MSPPrincipal, error)
// TODO: put the constants in some more appropriate place
switch role {
case "admin":
principalBytes, err := proto.Marshal(&common.MSPRole{Role: common.MSPRole_ADMIN, MspIdentifier: mspid})
principalBytes, err := proto.Marshal(&msp.MSPRole{Role: msp.MSPRole_ADMIN, MspIdentifier: mspid})
if err != nil {
return nil, err
}

return &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
return &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: principalBytes}, nil
case "member":
principalBytes, err := proto.Marshal(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: mspid})
principalBytes, err := proto.Marshal(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: mspid})
if err != nil {
return nil, err
}

return &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
return &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: principalBytes}, nil
default:
return nil, fmt.Errorf("MSP Principal role [%s] not recognized.", role)
Expand Down
Loading

0 comments on commit a4e80cd

Please sign in to comment.