Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ed25519 support #3343

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8d22eba
Add ed25519 support
johannww Apr 20, 2022
e1c2f94
Add initial integration tests for ed25519
johannww Jul 9, 2022
46598c2
Add ed25519 channel and msp capabilities
johannww Jul 15, 2022
97d19b4
Enhance capabilities and add ed25519 integration tests
johannww Jul 19, 2022
d64e4db
Delete integration/ed25519 folder and revert vendor file
johannww Jul 20, 2022
c63c459
Update Channel capabilities and msp version to V3_0
johannww Jul 20, 2022
1c7e082
Remove oldPeerRunner from integration test net
johannww Jul 20, 2022
5df422e
Update ed25519 integration test case
johannww Jul 20, 2022
1a3f83d
Fix typo
johannww Aug 21, 2022
199fe83
Update signer interface documentation and params
johannww Aug 21, 2022
2182795
Fix ed25519 signature
johannww Aug 21, 2022
3647eed
Dereference *ed25519.PublicKey and *ed25519.PrivateKey
johannww Jul 21, 2022
903a5ca
Removing keyalg flag from cryptogen
johannww Jul 22, 2022
3f4662d
Handling ed25519 cast error
johannww Jul 22, 2022
6dc26ed
Add identities ed25519 test cases
johannww Aug 21, 2022
804fe1a
Add ed25519 signer test case
johannww Aug 21, 2022
cd6d9da
Fix fileks and keys for ed25519
johannww Aug 21, 2022
f6254b8
Gen ed25519 or ecdsa crypto for users
johannww Nov 25, 2022
5fb6800
Gen ed25519 or ecdsa crypto for templates
johannww Nov 25, 2022
0b0934c
Add PublicKeyAlgorithm to default spec
johannww Nov 25, 2022
f8b3282
Enhance warning for unsupported key
johannww Nov 25, 2022
0393599
Update capabilities test to ginkgo v2
johannww Nov 25, 2022
0a58142
Fix checkstyle complaints
johannww Nov 25, 2022
d8463fd
Fix channelV30 test for MSPv3_0
johannww Nov 25, 2022
b7fd2b6
Fix cryptogen default config and test
johannww Nov 26, 2022
4805a27
Add CA's PublicKeyAlgorithm to default config
johannww Nov 29, 2022
9e6c617
Add ecdsa as default PublicKeyAlgorithm for CA
johannww Nov 29, 2022
db87f33
Fix UpdateConfig() calls
johannww Jan 25, 2023
6116fd8
compute SHA256 only for ECDSA keys
johannww Jan 17, 2024
88a2f02
fix comments assuming ECDSA-only support
johannww Jan 17, 2024
1bb5565
fix key type error message
johannww Jan 27, 2024
2714ba4
remove an unnecessary test
johannww Jan 27, 2024
4d9a50a
replace ioutil with os
johannww Jan 29, 2024
5bab4b0
Improve ed25519 lifecycle integration test
johannww Feb 1, 2024
433bfbb
refactor
johannww Feb 1, 2024
9df7bf1
remove unecessary line from ed25519 test
johannww Feb 1, 2024
44c37b8
fix nwo.UpdateConfig() call from discovery test
johannww Feb 1, 2024
66524a7
use gomega funcs instead of println
johannww Feb 2, 2024
2b19c89
bump fabric-lib-go to v1.1.3
johannww May 24, 2024
c3019ef
remove uneeded file
johannww Jun 6, 2024
b4f60ac
fix integration test chaincode deploy
johannww Jun 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions cmd/common/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package signer
import (
"crypto"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/rand"
"crypto/x509"
"encoding/asn1"
Expand Down Expand Up @@ -37,7 +38,7 @@ type Config struct {
// initialize an MSP without a CA cert that signs the signing identity,
// this will do for now.
type Signer struct {
key *ecdsa.PrivateKey
key crypto.PrivateKey
Creator []byte
}

Expand Down Expand Up @@ -93,11 +94,19 @@ func validateEnrollmentCertificate(b []byte) error {
}

func (si *Signer) Sign(msg []byte) ([]byte, error) {
digest := util.ComputeSHA256(msg)
return signECDSA(si.key, digest)
switch key := si.key.(type) {
// Fabric only supports ECDSA and ed25519 at the moment.
case *ecdsa.PrivateKey:
digest := util.ComputeSHA256(msg)
return signECDSA(si.key.(*ecdsa.PrivateKey), digest)
case ed25519.PrivateKey:
return ed25519.Sign(si.key.(ed25519.PrivateKey), msg), nil
default:
return nil, errors.Errorf("found unknown private key type (%T) in msg signing", key)
}
}

func loadPrivateKey(file string) (*ecdsa.PrivateKey, error) {
func loadPrivateKey(file string) (crypto.PrivateKey, error) {
b, err := os.ReadFile(file)
if err != nil {
return nil, errors.WithStack(err)
Expand All @@ -110,7 +119,7 @@ func loadPrivateKey(file string) (*ecdsa.PrivateKey, error) {
if err != nil {
return nil, err
}
return key.(*ecdsa.PrivateKey), nil
return key, nil
}

// Based on crypto/tls/tls.go but modified for Fabric:
Expand All @@ -121,6 +130,8 @@ func parsePrivateKey(der []byte) (crypto.PrivateKey, error) {
// Fabric only supports ECDSA at the moment.
case *ecdsa.PrivateKey:
return key, nil
case ed25519.PrivateKey:
return key, nil
default:
return nil, errors.Errorf("found unknown private key type (%T) in PKCS#8 wrapping", key)
}
Expand Down
25 changes: 23 additions & 2 deletions cmd/common/signer/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package signer

import (
"crypto/ecdsa"
"crypto/ed25519"
"crypto/x509"
"encoding/pem"
"os"
Expand All @@ -19,7 +20,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestSigner(t *testing.T) {
func TestEcdsaSigner(t *testing.T) {
conf := Config{
MSPID: "SampleOrg",
IdentityPath: filepath.Join("testdata", "signer", "cert.pem"),
Expand All @@ -35,7 +36,27 @@ func TestSigner(t *testing.T) {

r, s, err := utils.UnmarshalECDSASignature(sig)
require.NoError(t, err)
ecdsa.Verify(&signer.key.PublicKey, util.ComputeSHA256(msg), r, s)
verify := ecdsa.Verify(&signer.key.(*ecdsa.PrivateKey).PublicKey, util.ComputeSHA256(msg), r, s)
require.True(t, verify)
}

func TestEd25519Signer(t *testing.T) {
conf := Config{
MSPID: "SampleOrg",
IdentityPath: filepath.Join("testdata", "signer", "ed25519.pem"),
KeyPath: filepath.Join("testdata", "signer", "ed25519_sk"),
}

signer, err := NewSigner(conf)
require.NoError(t, err)

msg := []byte("foo")
sig, err := signer.Sign(msg)
require.NoError(t, err)

require.NoError(t, err)
verify := ed25519.Verify(signer.key.(ed25519.PrivateKey).Public().(ed25519.PublicKey), msg, sig)
require.True(t, verify)
}

func TestSignerDifferentFormats(t *testing.T) {
Expand Down
13 changes: 13 additions & 0 deletions cmd/common/signer/testdata/signer/ed25519.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-----BEGIN CERTIFICATE-----
MIIB3zCCAZGgAwIBAgIUOl8Rs3mka5U/s4hFwkGHjK1dh8IwBQYDK2VwMFkxCzAJ
BgNVBAYTAlVTMRcwFQYDVQQIDA5Ob3J0aCBDYXJvbGluYTEQMA4GA1UEBwwHUmFs
ZWlnaDENMAsGA1UECgwEb3JnMTEQMA4GA1UEAwwHY2Eub3JnMTAeFw0yMjA0MTQy
MjI1NDRaFw0zMjA0MTEyMjI1NDRaMFYxCzAJBgNVBAYTAlVTMRcwFQYDVQQIDA5O
b3J0aCBDYXJvbGluYTEQMA4GA1UEBwwHUmFsZWlnaDENMAsGA1UECwwEb3JnMTEN
MAsGA1UEAwwEcGVlcjAqMAUGAytlcAMhAOzQFNesvxCuSDr/vTLx38nryWT+xzHZ
LO3ztNUH2BCUo24wbDAOBgNVHQ8BAf8EBAMCB4AwDAYDVR0TAQH/BAIwADArBgNV
HREEJDAihwR/AAABgglwZWVyLm9yZzGCCWxvY2FsaG9zdIcEfwAAATAfBgNVHSME
GDAWgBQ0P7GW2Hf1Hll6UiMtfeFsdUmF5jAFBgMrZXADQQAc4U4nbmXKZPuEFGzS
s9y3urd9W2jguFyOx6ZdoL2Tn6dnrHNApCaJtOMwZAklaLQKvYsVF4DR/QRfdLA/
Y4wK
-----END CERTIFICATE-----
3 changes: 3 additions & 0 deletions cmd/common/signer/testdata/signer/ed25519_sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIFRg7zy6CQrAGXOzvM6XVhpzYuYyxP36bmpjd8x+qE1H
-----END PRIVATE KEY-----