Skip to content

Commit

Permalink
[FABG-849] Update fabric pins to v2.0.0-alpha
Browse files Browse the repository at this point in the history
Updates to:
fabric: v2.0.0-alpha (be235fd)
fabric-ca: v2.0.0-alpha (4db6520)

Change-Id: I8748a3380dafd55e8afbee81eab2793f4094e19d
Signed-off-by: Troy Ronda <[email protected]>
  • Loading branch information
troyronda committed Apr 10, 2019
1 parent f1fd02a commit 8bb794d
Show file tree
Hide file tree
Showing 18 changed files with 142 additions and 156 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ FABRIC_DEV_REGISTRY_PRE_CMD ?= docker login -u docker -p docker nexus3.hyperledg

# Upstream fabric patching (overridable)
THIRDPARTY_FABRIC_CA_BRANCH ?= master
THIRDPARTY_FABRIC_CA_COMMIT ?= 4efeaca8226b1d0c29327daaccb629b8a05de2e9
THIRDPARTY_FABRIC_CA_COMMIT ?= v2.0.0-alpha
THIRDPARTY_FABRIC_BRANCH ?= master
THIRDPARTY_FABRIC_COMMIT ?= 55fc8015b9eb8889b5c4b0f36ed239795e0f2c07
THIRDPARTY_FABRIC_COMMIT ?= v2.0.0-alpha

# Force removal of images in cleanup (overridable)
FIXTURE_DOCKER_REMOVE_FORCE ?= false
Expand Down
2 changes: 1 addition & 1 deletion ci.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

GO_VER=1.11.5
GO_MIN_VER=1.11
GO_MAX_VER=1.12.1
GO_MAX_VER=1.12.3
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
/*
Copyright IBM Corp. 2017 All Rights Reserved.
Copyright IBM Corp. 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.
SPDX-License-Identifier: Apache-2.0
*/
/*
Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"crypto/x509"
"fmt"

"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/attrmgr"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/attrmgr"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/pkg/errors"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ func (f *SWFactory) Get(swOpts *SwOpts) (bccsp.BCCSP, error) {
}

var ks bccsp.KeyStore
if swOpts.Ephemeral == true {
switch {
case swOpts.Ephemeral:
ks = sw.NewDummyKeyStore()
} else if swOpts.FileKeystore != nil {
case swOpts.FileKeystore != nil:
fks, err := sw.NewFileBasedKeyStore(nil, swOpts.FileKeystore.KeyStorePath, false)
if err != nil {
return nil, errors.Wrapf(err, "Failed to initialize software key store")
}
ks = fks
} else if swOpts.InmemKeystore != nil {
case swOpts.InmemKeystore != nil:
ks = sw.NewInMemoryKeyStore()
} else {
default:
// Default to ephemeral key store
ks = sw.NewDummyKeyStore()
}
Expand Down
12 changes: 6 additions & 6 deletions internal/github.com/hyperledger/fabric/bccsp/pkcs11/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ func (csp *impl) Sign(k bccsp.Key, digest []byte, opts bccsp.SignerOpts) ([]byte
}

// Check key type
switch k.(type) {
switch key := k.(type) {
case *ecdsaPrivateKey:
return csp.signECDSA(*k.(*ecdsaPrivateKey), digest, opts)
return csp.signECDSA(*key, digest, opts)
default:
return csp.BCCSP.Sign(k, digest, opts)
return csp.BCCSP.Sign(key, digest, opts)
}
}

Expand All @@ -196,11 +196,11 @@ func (csp *impl) Verify(k bccsp.Key, signature, digest []byte, opts bccsp.Signer
}

// Check key type
switch k.(type) {
switch key := k.(type) {
case *ecdsaPrivateKey:
return csp.verifyECDSA(k.(*ecdsaPrivateKey).pub, signature, digest, opts)
return csp.verifyECDSA(key.pub, signature, digest, opts)
case *ecdsaPublicKey:
return csp.verifyECDSA(*k.(*ecdsaPublicKey), signature, digest, opts)
return csp.verifyECDSA(*key, signature, digest, opts)
default:
return csp.BCCSP.Verify(k, signature, digest, opts)
}
Expand Down
18 changes: 13 additions & 5 deletions internal/github.com/hyperledger/fabric/bccsp/pkcs11/pkcs11.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,20 @@ func (csp *impl) verifyP11ECDSA(ski []byte, msg []byte, R, S *big.Int, byteSize
return true, nil
}

type keyType int8

const (
privateKeyFlag = true
publicKeyFlag = false
publicKeyType keyType = iota
privateKeyType
)

func timeTrack(start time.Time, msg string) {
elapsed := time.Since(start)
logger.Debugf("%s took %s", msg, elapsed)
}

func (csp *impl) findKeyPairFromSKI(mod *pkcs11.Ctx, session pkcs11.SessionHandle, ski []byte, keyType bool) (*pkcs11.ObjectHandle, error) {
return cachebridge.GetKeyPairFromSessionSKI(&cachebridge.KeyPairCacheKey{Mod: mod, Session: session, SKI: ski, KeyType: keyType})
func (csp *impl) findKeyPairFromSKI(mod *pkcs11.Ctx, session pkcs11.SessionHandle, ski []byte, keyType keyType) (*pkcs11.ObjectHandle, error) {
return cachebridge.GetKeyPairFromSessionSKI(&cachebridge.KeyPairCacheKey{Mod: mod, Session: session, SKI: ski, KeyType: keyType == privateKeyType})
}

// Fairly straightforward EC-point query, other than opencryptoki
Expand Down Expand Up @@ -358,7 +360,7 @@ func ecPoint(p11lib *sdkp11.ContextHandle, session pkcs11.SessionHandle, key pkc
logger.Debugf("EC point: attr type %d/0x%x, len %d\n%s\n", a.Type, a.Type, len(a.Value), hex.Dump(a.Value))

// workarounds, see above
if (0 == (len(a.Value) % 2)) &&
if ((len(a.Value) % 2) == 0) &&
(byte(0x04) == a.Value[0]) &&
(byte(0x04) == a.Value[len(a.Value)-1]) {
logger.Debugf("Detected opencryptoki bug, trimming trailing 0x04")
Expand Down Expand Up @@ -421,3 +423,9 @@ func nextIDCtr() *big.Int {
idMutex.Unlock()
return idCtr
}

// TODO: Refactor using keyType
const (
privateKeyFlag = true
publicKeyFlag = false
)
30 changes: 10 additions & 20 deletions internal/github.com/hyperledger/fabric/bccsp/sw/fileks.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ func (ks *fileBasedKeyStore) GetKey(ski []byte) (bccsp.Key, error) {
return nil, fmt.Errorf("Failed loading secret key [%x] [%s]", ski, err)
}

switch key.(type) {
switch k := key.(type) {
case *ecdsa.PrivateKey:
return &ecdsaPrivateKey{key.(*ecdsa.PrivateKey)}, nil
return &ecdsaPrivateKey{k}, nil
case *rsa.PrivateKey:
return &rsaPrivateKey{key.(*rsa.PrivateKey)}, nil
return &rsaPrivateKey{k}, nil
default:
return nil, errors.New("Secret key type not recognized")
}
Expand All @@ -153,11 +153,11 @@ func (ks *fileBasedKeyStore) GetKey(ski []byte) (bccsp.Key, error) {
return nil, fmt.Errorf("Failed loading public key [%x] [%s]", ski, err)
}

switch key.(type) {
switch k := key.(type) {
case *ecdsa.PublicKey:
return &ecdsaPublicKey{key.(*ecdsa.PublicKey)}, nil
return &ecdsaPublicKey{k}, nil
case *rsa.PublicKey:
return &rsaPublicKey{key.(*rsa.PublicKey)}, nil
return &rsaPublicKey{k}, nil
default:
return nil, errors.New("Public key type not recognized")
}
Expand All @@ -176,42 +176,32 @@ func (ks *fileBasedKeyStore) StoreKey(k bccsp.Key) (err error) {
if k == nil {
return errors.New("Invalid key. It must be different from nil.")
}
switch k.(type) {
switch kk := k.(type) {
case *ecdsaPrivateKey:
kk := k.(*ecdsaPrivateKey)

err = ks.storePrivateKey(hex.EncodeToString(k.SKI()), kk.privKey)
if err != nil {
return fmt.Errorf("Failed storing ECDSA private key [%s]", err)
}

case *ecdsaPublicKey:
kk := k.(*ecdsaPublicKey)

err = ks.storePublicKey(hex.EncodeToString(k.SKI()), kk.pubKey)
if err != nil {
return fmt.Errorf("Failed storing ECDSA public key [%s]", err)
}

case *rsaPrivateKey:
kk := k.(*rsaPrivateKey)

err = ks.storePrivateKey(hex.EncodeToString(k.SKI()), kk.privKey)
if err != nil {
return fmt.Errorf("Failed storing RSA private key [%s]", err)
}

case *rsaPublicKey:
kk := k.(*rsaPublicKey)

err = ks.storePublicKey(hex.EncodeToString(k.SKI()), kk.pubKey)
if err != nil {
return fmt.Errorf("Failed storing RSA public key [%s]", err)
}

case *aesPrivateKey:
kk := k.(*aesPrivateKey)

err = ks.storeKey(hex.EncodeToString(k.SKI()), kk.privKey)
if err != nil {
return fmt.Errorf("Failed storing AES key [%s]", err)
Expand Down Expand Up @@ -246,11 +236,11 @@ func (ks *fileBasedKeyStore) searchKeystoreForSKI(ski []byte) (k bccsp.Key, err
continue
}

switch key.(type) {
switch kk := key.(type) {
case *ecdsa.PrivateKey:
k = &ecdsaPrivateKey{key.(*ecdsa.PrivateKey)}
k = &ecdsaPrivateKey{kk}
case *rsa.PrivateKey:
k = &rsaPrivateKey{key.(*rsa.PrivateKey)}
k = &rsaPrivateKey{kk}
default:
continue
}
Expand Down
Loading

0 comments on commit 8bb794d

Please sign in to comment.