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 support for ED25519 CA cert key #555

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion counterecryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/aes"
"crypto/cipher"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/rsa"
"crypto/sha256"
"crypto/x509"
Expand All @@ -26,8 +27,12 @@ func NewCounterEncryptorRandFromKey(key interface{}, seed []byte) (r CounterEncr
if keyBytes, err = x509.MarshalECPrivateKey(key); err != nil {
return
}
case ed25519.PrivateKey:
if keyBytes, err = x509.MarshalPKCS8PrivateKey(key); err != nil {
return
}
default:
err = errors.New("only RSA and ECDSA keys supported")
err = errors.New("only RSA, ED25519 and ECDSA keys supported")
return
}
h := sha256.New()
Expand Down
14 changes: 8 additions & 6 deletions signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package goproxy
import (
"crypto"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/elliptic"
"crypto/rsa"
"crypto/sha1"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"fmt"
"math/big"
"math/rand"
Expand Down Expand Up @@ -53,11 +53,9 @@ func signHost(ca tls.Certificate, hosts []string) (cert *tls.Certificate, err er
// TODO(elazar): instead of this ugly hack, just encode the certificate and hash the binary form.
SerialNumber: serial,
Issuer: x509ca.Subject,
Subject: pkix.Name{
Organization: []string{"GoProxy untrusted MITM proxy Inc"},
},
NotBefore: start,
NotAfter: end,
Subject: x509ca.Subject,
NotBefore: start,
NotAfter: end,

KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
Expand Down Expand Up @@ -88,6 +86,10 @@ func signHost(ca tls.Certificate, hosts []string) (cert *tls.Certificate, err er
if certpriv, err = ecdsa.GenerateKey(elliptic.P256(), &csprng); err != nil {
return
}
case ed25519.PrivateKey:
if _, certpriv, err = ed25519.GenerateKey(&csprng); err != nil {
return
}
default:
err = fmt.Errorf("unsupported key type %T", ca.PrivateKey)
}
Expand Down