From 0e6087df295710976e9624b041886cef144d7d0c Mon Sep 17 00:00:00 2001 From: Derek Anderson Date: Mon, 6 May 2024 16:50:32 -0500 Subject: [PATCH] update certificate creation for ed25519, update makefile Signed-off-by: Derek Anderson --- Makefile | 15 --------------- host/cert.go | 8 +++++--- host/host.go | 4 +++- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 7a9ac0cc..22ed02cd 100644 --- a/Makefile +++ b/Makefile @@ -70,21 +70,6 @@ run-head: --rest-api :8081 @echo "\nāœ… Head Node is running!\n" - -.PHONY: run-worker -run-worker: - @echo "\nšŸš€ Launching Worker Node...\n" - ./dist/b7s --peer-db /tmp/b7s/head-peer-db \ - --function-db /tmp/b7s/head-fdb \ - --log-level debug \ - --port 9527 \ - --role head \ - --workspace /tmp/debug/head \ - --private-key ./configs/testkeys/ident1/priv.bin \ - --rest-api :8081 - @echo "\nāœ… Worker Node is running!\n" - - .PHONY: run-worker run-worker: @echo "\nšŸš€ Launching Worker Node...\n" diff --git a/host/cert.go b/host/cert.go index f2bf56a4..2d11985a 100644 --- a/host/cert.go +++ b/host/cert.go @@ -3,6 +3,7 @@ package host import ( "crypto" "crypto/ecdsa" + "crypto/ed25519" "crypto/rand" "crypto/rsa" "crypto/tls" @@ -27,12 +28,13 @@ func convertLibp2pPrivKeyToCryptoPrivKey(privKey libp2pcrypto.PrivKey) (crypto.P return x509.ParsePKCS1PrivateKey(rawKey) case libp2pcrypto.ECDSA: return x509.ParseECPrivateKey(rawKey) + case libp2pcrypto.Ed25519: + return ed25519.PrivateKey(rawKey), nil default: return nil, fmt.Errorf("unsupported key type for X.509 conversion") } } -// Generate an X.509 certificate using a generic crypto.PrivateKey func generateX509Certificate(privKey crypto.PrivateKey) (tls.Certificate, error) { // Define certificate template template := &x509.Certificate{ @@ -45,7 +47,6 @@ func generateX509Certificate(privKey crypto.PrivateKey) (tls.Certificate, error) KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, } - // Extract the public key from the private key pubKey := publicKey(privKey) // Create the certificate @@ -63,13 +64,14 @@ func generateX509Certificate(privKey crypto.PrivateKey) (tls.Certificate, error) return cert, nil } -// Extract the public key from a generic crypto.PrivateKey func publicKey(priv crypto.PrivateKey) crypto.PublicKey { switch key := priv.(type) { case *rsa.PrivateKey: return &key.PublicKey case *ecdsa.PrivateKey: return &key.PublicKey + case ed25519.PrivateKey: + return key.Public().(ed25519.PublicKey) default: panic("unsupported key type") } diff --git a/host/host.go b/host/host.go index e39a199a..fad4af70 100644 --- a/host/host.go +++ b/host/host.go @@ -57,8 +57,10 @@ func New(log zerolog.Logger, address string, port uint, options ...func(*Config) // Read private key, if provided. var key crypto.PrivKey + var err error + if cfg.PrivateKey != "" { - key, err := readPrivateKey(cfg.PrivateKey) + key, err = readPrivateKey(cfg.PrivateKey) if err != nil { return nil, fmt.Errorf("could not read private key: %w", err) }