Skip to content

Commit e5d771f

Browse files
committed
Address comments
Signed-off-by: senthil <cendhu@gmail.com>
1 parent 009a287 commit e5d771f

File tree

6 files changed

+75
-21
lines changed

6 files changed

+75
-21
lines changed

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/google/uuid v1.6.0
2020
github.com/hyperledger/fabric-lib-go v1.1.3-0.20240523144151-25edd1eaf5f5
2121
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.7
22-
github.com/hyperledger/fabric-x-common v0.0.0-20251023133631-047a3c32c228
22+
github.com/hyperledger/fabric-x-common v0.0.0-20251027142320-96a137a5adfb
2323
github.com/jackc/puddle v1.3.0
2424
github.com/mitchellh/mapstructure v1.5.0
2525
github.com/onsi/gomega v1.34.2
@@ -112,7 +112,6 @@ require (
112112
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
113113
github.com/nxadm/tail v1.4.11 // indirect
114114
github.com/onsi/ginkgo v1.16.5 // indirect
115-
github.com/onsi/ginkgo/v2 v2.20.2 // indirect
116115
github.com/opencontainers/go-digest v1.0.0 // indirect
117116
github.com/opencontainers/image-spec v1.1.0 // indirect
118117
github.com/pelletier/go-toml/v2 v2.2.4 // indirect

go.sum

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -919,17 +919,10 @@ github.com/hyperledger/fabric-config v0.3.0 h1:FS5/dc9GAniljP6RYxQRG92AaiBVoN2vT
919919
github.com/hyperledger/fabric-config v0.3.0/go.mod h1:kSevTn78K83Suc++JsEo7Nt1tYIPqDajW+ORz3OhWlg=
920920
github.com/hyperledger/fabric-lib-go v1.1.3-0.20240523144151-25edd1eaf5f5 h1:RPWTL5wxAb+xDOrsCU3QYZP65305F8v3PaOyzdbPVMU=
921921
github.com/hyperledger/fabric-lib-go v1.1.3-0.20240523144151-25edd1eaf5f5/go.mod h1:SHNCq8AB0VpHAmvJEtdbzabv6NNV1F48JdmDihasBjc=
922-
<<<<<<< HEAD
923922
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.7 h1:sQ5qv8vQQfwewa1JlCiSCC8dLElmaU2/frLolpgibEY=
924923
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.7/go.mod h1:bJnwzfv03oZQeCc863pdGTDgf5nmCy6Za3RAE7d2XsQ=
925-
github.com/hyperledger/fabric-x-common v0.0.0-20251023133631-047a3c32c228 h1:JdVLvE5ExlHvGL2LuaX3IQLo+7ZExsJhPkDutmNCJEU=
926-
github.com/hyperledger/fabric-x-common v0.0.0-20251023133631-047a3c32c228/go.mod h1:eztTd6MwzVOZtlWcOXWZepDBK/pQz3c3epu91BXAp6o=
927-
=======
928-
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.3 h1:Xpd6fzG/KjAOHJsq7EQXY2l+qi/y8muxBaY7R6QWABk=
929-
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.3/go.mod h1:2pq0ui6ZWA0cC8J+eCErgnMDCS1kPOEYVY+06ZAK0qE=
930-
github.com/hyperledger/fabric-x-common v0.0.0-20250929135229-402ed28111ec h1:qN9nTEzDkwHl8ZXba04tKsbT0UbJwH431EO2SrVEq6s=
931-
github.com/hyperledger/fabric-x-common v0.0.0-20250929135229-402ed28111ec/go.mod h1:Jq5eZFxs8ofSglp5YOYKlNfz1NLw9hBVWTz6bk52vc4=
932-
>>>>>>> e3c14f2 (Enable multiple policies type)
924+
github.com/hyperledger/fabric-x-common v0.0.0-20251027142320-96a137a5adfb h1:oh/k9KIvG/GOuBC92LaEZoI6IlFM91inQ7quoAV8L6w=
925+
github.com/hyperledger/fabric-x-common v0.0.0-20251027142320-96a137a5adfb/go.mod h1:5C4Ab/S56VXzP9BpePfbKr3Clmi1t1soKMThJeGBSIQ=
933926
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
934927
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
935928
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=

integration/test/config_update_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
"testing"
1212
"time"
1313

14-
"github.com/golang/protobuf/proto"
1514
"github.com/onsi/gomega"
1615
"github.com/stretchr/testify/require"
16+
"google.golang.org/protobuf/proto"
1717

1818
"github.com/hyperledger/fabric-x-committer/api/protoblocktx"
1919
"github.com/hyperledger/fabric-x-committer/api/protoloadgen"

service/coordinator/coordinator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"time"
1616

1717
"github.com/google/uuid"
18-
"github.com/hyperledger/fabric/protoutil"
18+
"github.com/hyperledger/fabric-x-common/protoutil"
1919
"github.com/stretchr/testify/assert"
2020
"github.com/stretchr/testify/require"
2121
"google.golang.org/protobuf/proto"

service/verifier/policy/test_exports.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package policy
99
import (
1010
"testing"
1111

12-
"github.com/hyperledger/fabric/protoutil"
12+
"github.com/hyperledger/fabric-x-common/protoutil"
1313
"github.com/stretchr/testify/require"
1414
"google.golang.org/protobuf/proto"
1515

service/verifier/verifier_server_test.go

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,25 @@ package verifier
88

99
import (
1010
"context"
11+
"crypto/ecdsa"
12+
"crypto/ed25519"
13+
"crypto/rand"
14+
"crypto/sha256"
15+
"crypto/x509"
16+
"encoding/pem"
1117
"fmt"
1218
"os"
1319
"path/filepath"
1420
"testing"
1521
"time"
1622

23+
bccsputils "github.com/hyperledger/fabric-lib-go/bccsp/utils"
24+
"github.com/hyperledger/fabric-protos-go-apiv2/msp"
1725
"github.com/hyperledger/fabric-x-common/common/policydsl"
1826
"github.com/hyperledger/fabric-x-common/core/config/configtest"
19-
"github.com/hyperledger/fabric/integration/nwo"
20-
"github.com/hyperledger/fabric/protoutil"
27+
"github.com/hyperledger/fabric-x-common/protoutil"
2128
"github.com/stretchr/testify/require"
29+
"google.golang.org/protobuf/proto"
2230

2331
"github.com/hyperledger/fabric-x-committer/api/protoblocktx"
2432
"github.com/hyperledger/fabric-x-committer/api/protosigverifierservice"
@@ -156,21 +164,21 @@ func TestSignatureRule(t *testing.T) {
156164
err = stream.Send(&protosigverifierservice.Batch{Update: update})
157165
require.NoError(t, err)
158166

159-
signingIdentities := make([]*nwo.SigningIdentity, 2)
167+
signingIdentities := make([]*signingIdentity, 2)
160168

161169
for i, org := range []string{"Org1", "Org2"} {
162-
signingIdentities[i] = &nwo.SigningIdentity{
170+
signingIdentities[i] = &signingIdentity{
163171
CertPath: filepath.Join(configtest.GetDevConfigDir(), "crypto/"+org+"/users/User1@"+org+"/msp",
164172
"signcerts", "User1@"+org+"-cert.pem"),
165173
KeyPath: filepath.Join(configtest.GetDevConfigDir(), "crypto/"+org+"/users/User1@"+org+"/msp",
166-
"keystore", "key.pem"),
174+
"keystore", "priv_sk"),
167175
MSPID: org,
168176
}
169177
}
170178

171179
serializedSigningIdentities := make([][]byte, len(signingIdentities))
172180
for i, si := range signingIdentities {
173-
serializedIdentity, serr := si.Serialize()
181+
serializedIdentity, serr := si.serialize()
174182
require.NoError(t, serr)
175183
serializedSigningIdentities[i] = serializedIdentity
176184
}
@@ -206,7 +214,7 @@ func TestSignatureRule(t *testing.T) {
206214
mspIDs := make([][]byte, len(signingIdentities))
207215
certsBytes := make([][]byte, len(signingIdentities))
208216
for i, si := range signingIdentities {
209-
s, serr := si.Sign(data)
217+
s, serr := si.sign(data)
210218
require.NoError(t, serr)
211219
signatures[i] = s
212220

@@ -603,3 +611,57 @@ func createVerifierClientWithTLS(
603611
t.Helper()
604612
return test.CreateClientWithTLS(t, ep, tlsCfg, protosigverifierservice.NewVerifierClient)
605613
}
614+
615+
// A signingIdentity represents an MSP signing identity.
616+
type signingIdentity struct {
617+
CertPath string
618+
KeyPath string
619+
MSPID string
620+
}
621+
622+
// serialize returns the probobuf encoding of an msp.SerializedIdenity.
623+
func (s *signingIdentity) serialize() ([]byte, error) {
624+
cert, err := os.ReadFile(s.CertPath)
625+
if err != nil {
626+
return nil, err
627+
}
628+
return proto.Marshal(&msp.SerializedIdentity{
629+
Mspid: s.MSPID,
630+
IdBytes: cert,
631+
})
632+
}
633+
634+
// sign computes a SHA256 message digest if key is ECDSA,
635+
// signs it with the associated private key, and returns the
636+
// signature. Low-S normlization is applied for ECDSA signatures.
637+
func (s *signingIdentity) sign(msg []byte) ([]byte, error) {
638+
digest := sha256.Sum256(msg)
639+
pemKey, err := os.ReadFile(s.KeyPath)
640+
if err != nil {
641+
return nil, err
642+
}
643+
block, _ := pem.Decode(pemKey)
644+
if block.Type != "EC PRIVATE KEY" && block.Type != "PRIVATE KEY" {
645+
return nil, fmt.Errorf("file %s does not contain a private key", s.KeyPath)
646+
}
647+
key, err := x509.ParsePKCS8PrivateKey(block.Bytes)
648+
if err != nil {
649+
return nil, err
650+
}
651+
switch k := key.(type) {
652+
case *ecdsa.PrivateKey:
653+
r, _s, err := ecdsa.Sign(rand.Reader, k, digest[:])
654+
if err != nil {
655+
return nil, err
656+
}
657+
sig, err := bccsputils.MarshalECDSASignature(r, _s)
658+
if err != nil {
659+
return nil, err
660+
}
661+
return bccsputils.SignatureToLowS(&k.PublicKey, sig)
662+
case ed25519.PrivateKey:
663+
return ed25519.Sign(k, msg), nil
664+
default:
665+
return nil, fmt.Errorf("unexpected key type: %T", key)
666+
}
667+
}

0 commit comments

Comments
 (0)