Skip to content

Commit

Permalink
[FAB-7528] Update thirdparty pinning scripts
Browse files Browse the repository at this point in the history
- To accomodate changes done for internal/fabric-ca
for embedded cryptoconfig

Change-Id: I1bf3d587c56106b3e9892f178399307ac46c2885
Signed-off-by: Sudesh Shetty <sudesh.shetty@securekey.com>
  • Loading branch information
sudeshrshetty committed Dec 20, 2017
1 parent 9027753 commit 8d39602
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
17 changes: 8 additions & 9 deletions internal/github.com/hyperledger/fabric-ca/util/csp.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,37 +126,36 @@ func ImportBCCSPKeyFromPEM(keyFile string, myCSP apicryptosuite.CryptoSuite, tem
if err != nil {
return nil, err
}

key, err := ImportBCCSPKeyFromPEMBytes(keyBuff, myCSP, temporary)

if err != nil {
return nil, errors.WithMessage(err, fmt.Sprintf("Failed parsing private key from %s", keyFile))
return nil, errors.WithMessage(err, fmt.Sprintf("Failed parsing private key from key file %s", keyFile))
}

return key, nil
}

// ImportBCCSPKeyFromPEMBytes attempts to create a private BCCSP key from a pem byte slice
func ImportBCCSPKeyFromPEMBytes(keyBuff []byte, myCSP apicryptosuite.CryptoSuite, temporary bool) (apicryptosuite.Key, error) {
keyFile := "pem bytes"

key, err := factory.PEMtoPrivateKey(keyBuff, nil)
if err != nil {
return nil, err
return nil, errors.WithMessage(err, fmt.Sprintf("Failed parsing private key from %s", keyFile))
}
switch key.(type) {
case *ecdsa.PrivateKey:
priv, err := factory.PrivateKeyToDER(key.(*ecdsa.PrivateKey))
if err != nil {
return nil, errors.WithMessage(err, fmt.Sprintf("Failed to convert ECDSA private key"))
return nil, errors.WithMessage(err, fmt.Sprintf("Failed to convert ECDSA private key for '%s'", keyFile))
}
sk, err := myCSP.KeyImport(priv, factory.GetECDSAPrivateKeyImportOpts(temporary))
if err != nil {
return nil, errors.WithMessage(err, fmt.Sprintf("Failed to import ECDSA private key"))
return nil, errors.WithMessage(err, fmt.Sprintf("Failed to import ECDSA private key for '%s'", keyFile))
}
return sk, nil
case *rsa.PrivateKey:
return nil, errors.Errorf("Failed to import RSA key: RSA private key import is not supported")
return nil, errors.Errorf("Failed to import RSA key from %s; RSA private key import is not supported", keyFile)
default:
return nil, errors.Errorf("Failed to import key: invalid secret key type")
return nil, errors.Errorf("Failed to import key from %s: invalid secret key type", keyFile)
}
}

Expand Down
7 changes: 4 additions & 3 deletions internal/github.com/hyperledger/fabric-ca/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ import (
"io/ioutil"
"math/big"
mrand "math/rand"

"github.com/hyperledger/fabric-sdk-go/api/apicryptosuite"
factory "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/sdkpatch/cryptosuitebridge"

"net/http"
"path/filepath"
"reflect"
"regexp"
"strings"
"time"

"github.com/hyperledger/fabric-sdk-go/api/apicryptosuite"
factory "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/sdkpatch/cryptosuitebridge"

"github.com/hyperledger/fabric-sdk-go/pkg/errors"

"golang.org/x/crypto/ocsp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ package signer

import (
"crypto"
"io"

"github.com/hyperledger/fabric-sdk-go/api/apicryptosuite"

"io"

"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp/utils"
"github.com/hyperledger/fabric-sdk-go/pkg/errors"
)
Expand Down
5 changes: 3 additions & 2 deletions internal/github.com/hyperledger/fabric/msp/identities.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import (
"crypto/rand"
"crypto/x509"
"encoding/hex"
"encoding/pem"
"time"

"github.com/hyperledger/fabric-sdk-go/api/apicryptosuite"

"encoding/pem"
"time"

"github.com/golang/protobuf/proto"
bccsp "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/sdkpatch/cryptosuitebridge"
flogging "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/sdkpatch/logbridge"
Expand Down
11 changes: 11 additions & 0 deletions scripts/third_party_pins/fabric-ca/apply_fabric_ca_client_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ sed -i'' -e 's/&bccsp.ECDSAPrivateKeyImportOpts{Temporary: temporary}/factory.Ge
sed -i'' -e 's/cspsigner.New(/factory.NewCspSigner(/g' "${TMP_PROJECT_PATH}/${FILTER_FILENAME}"
sed -i'' -e 's/utils.PrivateKeyToDER/factory.PrivateKeyToDER/g' "${TMP_PROJECT_PATH}/${FILTER_FILENAME}"
sed -i'' -e 's/utils.PEMtoPrivateKey/factory.PEMtoPrivateKey/g' "${TMP_PROJECT_PATH}/${FILTER_FILENAME}"
sed -i'' -e '/key, err := factory.PEMtoPrivateKey(keyBuff, nil)/ i\
key, err := ImportBCCSPKeyFromPEMBytes(keyBuff, myCSP, temporary) \
if err != nil { \
return nil, errors.WithMessage(err, fmt.Sprintf("Failed parsing private key from key file %s", keyFile)) \
} \
return key, nil \
} \
\/\/ ImportBCCSPKeyFromPEMBytes attempts to create a private BCCSP key from a pem byte slice \
func ImportBCCSPKeyFromPEMBytes(keyBuff []byte, myCSP apicryptosuite.CryptoSuite, temporary bool) (apicryptosuite.Key, error) { \
keyFile := "pem bytes" \
' "${TMP_PROJECT_PATH}/${FILTER_FILENAME}"


FILTER_FILENAME="util/util.go"
Expand Down

0 comments on commit 8d39602

Please sign in to comment.