-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-1420] Convert signature policy to provider
https://jira.hyperledger.org/browse/FAB-1420 The cuathdsl signature policy type used to be the only policy type available. In order to allow new types of policy, a provider framework is needed. This changeset introduces the provider framework and converts the existing cauthdsl based signature policy work to be one of these providers. Finally, in response to some changeset feedback, it also introduces the notion of a SignedData struct which can be common to all of the crypto implementations (and signficiantly simplifies the interface definitions). Change-Id: Ib67ff9f6de0433f73c96e5a4b229f1587a0f0363 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
- Loading branch information
Jason Yellick
committed
Jan 2, 2017
1 parent
46f7af0
commit bad7bdc
Showing
12 changed files
with
409 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cauthdsl | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/hyperledger/fabric/common/policies" | ||
cb "github.com/hyperledger/fabric/protos/common" | ||
|
||
"github.com/golang/protobuf/proto" | ||
) | ||
|
||
type provider struct { | ||
helper CryptoHelper | ||
} | ||
|
||
// NewProviderImpl provides a policy generator for cauthdsl type policies | ||
func NewPolicyProvider(helper CryptoHelper) policies.Provider { | ||
return &provider{ | ||
helper: helper, | ||
} | ||
} | ||
|
||
// NewPolicy creates a new policy based on the policy bytes | ||
func (pr *provider) NewPolicy(data []byte) (policies.Policy, error) { | ||
sigPolicy := &cb.SignaturePolicyEnvelope{} | ||
if err := proto.Unmarshal(data, sigPolicy); err != nil { | ||
return nil, fmt.Errorf("Error unmarshaling to SignaturePolicy: %s", err) | ||
} | ||
|
||
if sigPolicy.Version != 0 { | ||
return nil, fmt.Errorf("This evaluator only understands messages of version 0, but version was %d", sigPolicy.Version) | ||
} | ||
|
||
compiled, err := compile(sigPolicy.Policy, sigPolicy.Identities, pr.helper) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &policy{ | ||
evaluator: compiled, | ||
}, nil | ||
|
||
} | ||
|
||
type policy struct { | ||
evaluator func([]*cb.SignedData) bool | ||
} | ||
|
||
// Evaluate takes a set of SignedData and evaluates whether this set of signatures satisfies the policy | ||
func (p *policy) Evaluate(signatureSet []*cb.SignedData) error { | ||
if p == nil { | ||
return fmt.Errorf("No such policy") | ||
} | ||
|
||
ok := p.evaluator(signatureSet) | ||
if !ok { | ||
return errors.New("Failed to authenticate policy") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.