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 EdDSA support #555

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main
import (
"crypto"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/elliptic"
"crypto/rand"
"crypto/rsa"
Expand Down Expand Up @@ -167,6 +168,10 @@ func (m *mkcert) generateKey(rootCA bool) (crypto.PrivateKey, error) {
if m.ecdsa {
return ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
}
if m.eddsa {
_, privkey, error := ed25519.GenerateKey(rand.Reader)
return privkey, error
}
if rootCA {
return rsa.GenerateKey(rand.Reader, 3072)
}
Expand Down
16 changes: 10 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const advancedUsage = `Advanced options:
-ecdsa
Generate a certificate with an ECDSA key.

-eddsa
Generate a certificate with an EdDSA key.

-pkcs12
Generate a ".p12" PKCS #12 file, also know as a ".pfx" file,
containing certificate and key for legacy applications.
Expand Down Expand Up @@ -95,6 +98,7 @@ func main() {
uninstallFlag = flag.Bool("uninstall", false, "")
pkcs12Flag = flag.Bool("pkcs12", false, "")
ecdsaFlag = flag.Bool("ecdsa", false, "")
eddsaFlag = flag.Bool("eddsa", false, "")
clientFlag = flag.Bool("client", false, "")
helpFlag = flag.Bool("help", false, "")
carootFlag = flag.Bool("CAROOT", false, "")
Expand Down Expand Up @@ -136,15 +140,15 @@ func main() {
if *installFlag && *uninstallFlag {
log.Fatalln("ERROR: you can't set -install and -uninstall at the same time")
}
if *csrFlag != "" && (*pkcs12Flag || *ecdsaFlag || *clientFlag) {
if *csrFlag != "" && (*pkcs12Flag || *ecdsaFlag || *eddsaFlag || *clientFlag) {
log.Fatalln("ERROR: can only combine -csr with -install and -cert-file")
}
if *csrFlag != "" && flag.NArg() != 0 {
log.Fatalln("ERROR: can't specify extra arguments when using -csr")
}
(&mkcert{
installMode: *installFlag, uninstallMode: *uninstallFlag, csrPath: *csrFlag,
pkcs12: *pkcs12Flag, ecdsa: *ecdsaFlag, client: *clientFlag,
pkcs12: *pkcs12Flag, ecdsa: *ecdsaFlag, eddsa: *eddsaFlag, client: *clientFlag,
certFile: *certFileFlag, keyFile: *keyFileFlag, p12File: *p12FileFlag,
}).Run(flag.Args())
}
Expand All @@ -153,10 +157,10 @@ const rootName = "rootCA.pem"
const rootKeyName = "rootCA-key.pem"

type mkcert struct {
installMode, uninstallMode bool
pkcs12, ecdsa, client bool
keyFile, certFile, p12File string
csrPath string
installMode, uninstallMode bool
pkcs12, ecdsa, eddsa, client bool
keyFile, certFile, p12File string
csrPath string

CAROOT string
caCert *x509.Certificate
Expand Down