forked from hyperledger/fabric
-
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.
Re-add the RSA definitions to BCCSP - RSA implementation
BCCSP supported RSA in version 1.4. The Fabric CA is currently using the Fabric 1.4 dependency. It is necessary to move Fabric CA off of Fabric 1.4 dependencies since they are no longer maintained. Fabric 2.X does not support RSA, however the CA still needs to support RSA for any older but not expired certificates that may be in use by older netwo Github: hyperledger#4625 Signed-off-by: Chris Elder <celder@Chriss-MacBook-Pro.local>
- Loading branch information
Chris Elder
authored and
Chris Elder
committed
Jan 20, 2024
1 parent
8d5cb3a
commit a0779c1
Showing
7 changed files
with
222 additions
and
48 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package sw | ||
|
||
import ( | ||
"crypto/rsa" | ||
"crypto/sha256" | ||
"crypto/x509" | ||
"encoding/asn1" | ||
"errors" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/hyperledger/fabric/bccsp" | ||
) | ||
|
||
// rsaPublicKey reflects the ASN.1 structure of a PKCS#1 public key. | ||
type rsaPublicKeyASN struct { | ||
N *big.Int | ||
E int | ||
} | ||
|
||
type rsaPrivateKey struct { | ||
privKey *rsa.PrivateKey | ||
} | ||
|
||
// Bytes converts this key to its byte representation, | ||
// if this operation is allowed. | ||
func (k *rsaPrivateKey) Bytes() ([]byte, error) { | ||
return nil, errors.New("Not supported.") | ||
} | ||
|
||
// SKI returns the subject key identifier of this key. | ||
func (k *rsaPrivateKey) SKI() []byte { | ||
if k.privKey == nil { | ||
return nil | ||
} | ||
|
||
// Marshall the public key | ||
raw, _ := asn1.Marshal(rsaPublicKeyASN{ | ||
N: k.privKey.N, | ||
E: k.privKey.E, | ||
}) | ||
|
||
// Hash it | ||
hash := sha256.New() | ||
hash.Write(raw) | ||
return hash.Sum(nil) | ||
} | ||
|
||
// Symmetric returns true if this key is a symmetric key, | ||
// false is this key is asymmetric | ||
func (k *rsaPrivateKey) Symmetric() bool { | ||
return false | ||
} | ||
|
||
// Private returns true if this key is an asymmetric private key, | ||
// false otherwise. | ||
func (k *rsaPrivateKey) Private() bool { | ||
return true | ||
} | ||
|
||
// PublicKey returns the corresponding public key part of an asymmetric public/private key pair. | ||
// This method returns an error in symmetric key schemes. | ||
func (k *rsaPrivateKey) PublicKey() (bccsp.Key, error) { | ||
return &rsaPublicKey{&k.privKey.PublicKey}, nil | ||
} | ||
|
||
type rsaPublicKey struct { | ||
pubKey *rsa.PublicKey | ||
} | ||
|
||
// Bytes converts this key to its byte representation, | ||
// if this operation is allowed. | ||
func (k *rsaPublicKey) Bytes() (raw []byte, err error) { | ||
if k.pubKey == nil { | ||
return nil, errors.New("Failed marshalling key. Key is nil.") | ||
} | ||
raw, err = x509.MarshalPKIXPublicKey(k.pubKey) | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed marshalling key [%s]", err) | ||
} | ||
return | ||
} | ||
|
||
// SKI returns the subject key identifier of this key. | ||
func (k *rsaPublicKey) SKI() []byte { | ||
if k.pubKey == nil { | ||
return nil | ||
} | ||
|
||
// Marshall the public key | ||
raw, _ := asn1.Marshal(rsaPublicKeyASN{ | ||
N: k.pubKey.N, | ||
E: k.pubKey.E, | ||
}) | ||
|
||
// Hash it | ||
hash := sha256.New() | ||
hash.Write(raw) | ||
return hash.Sum(nil) | ||
} | ||
|
||
// Symmetric returns true if this key is a symmetric key, | ||
// false is this key is asymmetric | ||
func (k *rsaPublicKey) Symmetric() bool { | ||
return false | ||
} | ||
|
||
// Private returns true if this key is an asymmetric private key, | ||
// false otherwise. | ||
func (k *rsaPublicKey) Private() bool { | ||
return false | ||
} | ||
|
||
// PublicKey returns the corresponding public key part of an asymmetric public/private key pair. | ||
// This method returns an error in symmetric key schemes. | ||
func (k *rsaPublicKey) PublicKey() (bccsp.Key, error) { | ||
return k, nil | ||
} |