Skip to content

Commit 8f8c6dc

Browse files
adecarogaborh-da
authored andcommitted
Removing core/chaincode/shim/crypto
This change-set removes the crypto package under core/chaincode/shim. All of its functions have been moved to the accesscontrol package and the chaincode examples using it have been updated to use the new package. Notice that the accesscontrol package is still under development. More change-sets will be submitted to shape it. This change-set comes in the context of https://jira.hyperledger.org/browse/FAB-831 Change-Id: I42bc59265f1a84aae71e971c063d119a410eb361 Signed-off-by: Angelo De Caro <[email protected]>
1 parent c20fd9d commit 8f8c6dc

File tree

23 files changed

+90
-1447
lines changed

23 files changed

+90
-1447
lines changed

accesscontrol/crypto/ecdsa/ecdsa.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"encoding/asn1"
2222
"math/big"
2323

24-
"github.com/hyperledger/fabric/core/chaincode/shim/crypto"
24+
"github.com/hyperledger/fabric/accesscontrol/crypto"
2525
)
2626

2727
type x509ECDSASignatureVerifierImpl struct {

accesscontrol/impl/chaincode.go

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package impl
2+
3+
import (
4+
"github.com/hyperledger/fabric/accesscontrol"
5+
"github.com/hyperledger/fabric/accesscontrol/crypto/attr"
6+
"github.com/hyperledger/fabric/accesscontrol/crypto/ecdsa"
7+
"github.com/hyperledger/fabric/core/chaincode/shim"
8+
"github.com/hyperledger/fabric/core/crypto/primitives"
9+
)
10+
11+
// NewAccessControlShim create a new AccessControlShim instance
12+
func NewAccessControlShim(stub shim.ChaincodeStubInterface) *AccessControlShim {
13+
// TODO: The package accesscontrol still depends on the initialization
14+
// of the primitives package.
15+
// This has to be removed by using the BCCSP which will carry this information.
16+
// A similar approach has been used to remove the calls
17+
// to InitSecurityLevel and SetSecurityLevel from the core.
18+
primitives.SetSecurityLevel("SHA2", 256)
19+
20+
return &AccessControlShim{stub}
21+
}
22+
23+
// AccessControlShim wraps the object passed to chaincode for shim side handling of
24+
// APIs to provide access control capabilities.
25+
type AccessControlShim struct {
26+
stub shim.ChaincodeStubInterface
27+
}
28+
29+
//ReadCertAttribute is used to read an specific attribute from the transaction certificate, *attributeName* is passed as input parameter to this function.
30+
// Example:
31+
// attrValue,error:=stub.ReadCertAttribute("position")
32+
func (shim *AccessControlShim) ReadCertAttribute(attributeName string) ([]byte, error) {
33+
attributesHandler, err := attr.NewAttributesHandlerImpl(shim.stub)
34+
if err != nil {
35+
return nil, err
36+
}
37+
return attributesHandler.GetValue(attributeName)
38+
}
39+
40+
//VerifyAttribute is used to verify if the transaction certificate has an attribute with name *attributeName* and value *attributeValue* which are the input parameters received by this function.
41+
//Example:
42+
// containsAttr, error := stub.VerifyAttribute("position", "Software Engineer")
43+
func (shim *AccessControlShim) VerifyAttribute(attributeName string, attributeValue []byte) (bool, error) {
44+
attributesHandler, err := attr.NewAttributesHandlerImpl(shim.stub)
45+
if err != nil {
46+
return false, err
47+
}
48+
return attributesHandler.VerifyAttribute(attributeName, attributeValue)
49+
}
50+
51+
//VerifyAttributes does the same as VerifyAttribute but it checks for a list of attributes and their respective values instead of a single attribute/value pair
52+
// Example:
53+
// containsAttrs, error:= stub.VerifyAttributes(&attr.Attribute{"position", "Software Engineer"}, &attr.Attribute{"company", "ACompany"})
54+
func (shim *AccessControlShim) VerifyAttributes(attrs ...*accesscontrol.Attribute) (bool, error) {
55+
attributesHandler, err := attr.NewAttributesHandlerImpl(shim.stub)
56+
if err != nil {
57+
return false, err
58+
}
59+
return attributesHandler.VerifyAttributes(attrs...)
60+
}
61+
62+
// VerifySignature verifies the transaction signature and returns `true` if
63+
// correct and `false` otherwise
64+
func (shim *AccessControlShim) VerifySignature(certificate, signature, message []byte) (bool, error) {
65+
// Instantiate a new SignatureVerifier
66+
sv := ecdsa.NewX509ECDSASignatureVerifier()
67+
68+
// Verify the signature
69+
return sv.Verify(certificate, signature, message)
70+
}

core/chaincode/shim/chaincode.go

-45
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import (
3030

3131
"github.com/golang/protobuf/proto"
3232
"github.com/golang/protobuf/ptypes/timestamp"
33-
"github.com/hyperledger/fabric/core/chaincode/shim/crypto/attr"
34-
"github.com/hyperledger/fabric/core/chaincode/shim/crypto/ecdsa"
3533
"github.com/hyperledger/fabric/core/comm"
3634
"github.com/hyperledger/fabric/core/util"
3735
pb "github.com/hyperledger/fabric/protos/peer"
@@ -315,39 +313,6 @@ func (stub *ChaincodeStub) DelState(key string) error {
315313
return stub.handler.handleDelState(key, stub.TxID)
316314
}
317315

318-
//ReadCertAttribute is used to read an specific attribute from the transaction certificate, *attributeName* is passed as input parameter to this function.
319-
// Example:
320-
// attrValue,error:=stub.ReadCertAttribute("position")
321-
func (stub *ChaincodeStub) ReadCertAttribute(attributeName string) ([]byte, error) {
322-
attributesHandler, err := attr.NewAttributesHandlerImpl(stub)
323-
if err != nil {
324-
return nil, err
325-
}
326-
return attributesHandler.GetValue(attributeName)
327-
}
328-
329-
//VerifyAttribute is used to verify if the transaction certificate has an attribute with name *attributeName* and value *attributeValue* which are the input parameters received by this function.
330-
//Example:
331-
// containsAttr, error := stub.VerifyAttribute("position", "Software Engineer")
332-
func (stub *ChaincodeStub) VerifyAttribute(attributeName string, attributeValue []byte) (bool, error) {
333-
attributesHandler, err := attr.NewAttributesHandlerImpl(stub)
334-
if err != nil {
335-
return false, err
336-
}
337-
return attributesHandler.VerifyAttribute(attributeName, attributeValue)
338-
}
339-
340-
//VerifyAttributes does the same as VerifyAttribute but it checks for a list of attributes and their respective values instead of a single attribute/value pair
341-
// Example:
342-
// containsAttrs, error:= stub.VerifyAttributes(&attr.Attribute{"position", "Software Engineer"}, &attr.Attribute{"company", "ACompany"})
343-
func (stub *ChaincodeStub) VerifyAttributes(attrs ...*attr.Attribute) (bool, error) {
344-
attributesHandler, err := attr.NewAttributesHandlerImpl(stub)
345-
if err != nil {
346-
return false, err
347-
}
348-
return attributesHandler.VerifyAttributes(attrs...)
349-
}
350-
351316
// StateRangeQueryIterator allows a chaincode to iterate over a range of
352317
// key/value pairs in the state.
353318
type StateRangeQueryIterator struct {
@@ -688,16 +653,6 @@ func deleteRowInternal(stub ChaincodeStubInterface, tableName string, key []Colu
688653
return nil
689654
}
690655

691-
// VerifySignature verifies the transaction signature and returns `true` if
692-
// correct and `false` otherwise
693-
func (stub *ChaincodeStub) VerifySignature(certificate, signature, message []byte) (bool, error) {
694-
// Instantiate a new SignatureVerifier
695-
sv := ecdsa.NewX509ECDSASignatureVerifier()
696-
697-
// Verify the signature
698-
return sv.Verify(certificate, signature, message)
699-
}
700-
701656
// GetCallerCertificate returns caller certificate
702657
func (stub *ChaincodeStub) GetCallerCertificate() ([]byte, error) {
703658
return nil, nil

core/chaincode/shim/crypto/attr/attr_support.go

-214
This file was deleted.

0 commit comments

Comments
 (0)