forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FABG-999] Update pinning to Fabric v2.2.0 (hyperledger#102)
Signed-off-by: Troy Ronda <[email protected]>
- Loading branch information
Showing
47 changed files
with
501 additions
and
556 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
81 changes: 81 additions & 0 deletions
81
internal/github.com/hyperledger/fabric-ca/sdkpatch/keyutil/keys.go
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,81 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
/* | ||
Notice: This file has been modified for Hyperledger Fabric SDK Go usage. | ||
Please review third_party pinning scripts and patches for more details. | ||
*/ | ||
|
||
package keyutil | ||
|
||
import ( | ||
"crypto/ecdsa" | ||
"crypto/x509" | ||
"encoding/pem" | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
func PrivateKeyToDER(privateKey *ecdsa.PrivateKey) ([]byte, error) { | ||
if privateKey == nil { | ||
return nil, errors.New("invalid ecdsa private key. It must be different from nil") | ||
} | ||
|
||
return x509.MarshalECPrivateKey(privateKey) | ||
} | ||
|
||
func derToPrivateKey(der []byte) (key interface{}, err error) { | ||
|
||
if key, err = x509.ParsePKCS1PrivateKey(der); err == nil { | ||
return key, nil | ||
} | ||
|
||
if key, err = x509.ParsePKCS8PrivateKey(der); err == nil { | ||
switch key.(type) { | ||
case *ecdsa.PrivateKey: | ||
return | ||
default: | ||
return nil, errors.New("found unknown private key type in PKCS#8 wrapping") | ||
} | ||
} | ||
|
||
if key, err = x509.ParseECPrivateKey(der); err == nil { | ||
return | ||
} | ||
|
||
return nil, errors.New("invalid key type. The DER must contain an ecdsa.PrivateKey") | ||
} | ||
|
||
func PEMToPrivateKey(raw []byte, pwd []byte) (interface{}, error) { | ||
block, _ := pem.Decode(raw) | ||
if block == nil { | ||
return nil, fmt.Errorf("failed decoding PEM. Block must be different from nil [% x]", raw) | ||
} | ||
|
||
// TODO: derive from header the type of the key | ||
|
||
if x509.IsEncryptedPEMBlock(block) { | ||
if len(pwd) == 0 { | ||
return nil, errors.New("encrypted Key. Need a password") | ||
} | ||
|
||
decrypted, err := x509.DecryptPEMBlock(block, pwd) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed PEM decryption: [%s]", err) | ||
} | ||
|
||
key, err := derToPrivateKey(decrypted) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return key, err | ||
} | ||
|
||
cert, err := derToPrivateKey(block.Bytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return cert, err | ||
} |
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
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
Oops, something went wrong.