-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 generating ed25519 keys and certificates #1097
Closed
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9a17a34
add support for generating ed25519 keys and certs
izolight cf7fb43
add 5min ca testfiles
izolight 79fa3b0
only build for go1.13 as the ed25519 package is now part of std library
izolight 221d4ec
remove dependency on golang.org/x/crypto/ed25519
izolight 626680c
Change string domain and format
claucece 7f6b294
Change to use circl ed25519. This will fail due to issue cloudflare/c…
claucece b8f9375
Use circl only for signing
claucece f1bf794
Update vendor
claucece 259b11c
Update vendor to mod
claucece 35d039a
Remove go 1.12
claucece 887b6fc
Only use c25519 for generation
claucece 7dc5eca
Fix style
claucece 4685a06
Use circl library for all ed25519 key generation
claucece b4a68f6
Run the tests with expired data
claucece 7aff46b
Consistent naming
claucece 2725cfc
Not using pointers
claucece ad00b62
Fix 5min files
claucece 7d2779f
Use 25519 from stdlib
claucece acff4d8
This package is vendored
claucece 21fb139
Re add error line and mod tidy
claucece File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ package csr | |
import ( | ||
"crypto" | ||
"crypto/ecdsa" | ||
"crypto/ed25519" | ||
"crypto/elliptic" | ||
"crypto/rsa" | ||
"crypto/x509" | ||
|
@@ -20,7 +21,6 @@ import ( | |
//in KeyRequest field | ||
|
||
func TestNew(t *testing.T) { | ||
|
||
if cr := New(); cr.KeyRequest == nil { | ||
t.Fatalf("Should create a new, empty certificate request with KeyRequest") | ||
} | ||
|
@@ -44,6 +44,10 @@ func TestKeyRequest(t *testing.T) { | |
if kr.Algo() != "ecdsa" { | ||
t.Fatal("ECDSA key generated, but expected", kr.Algo()) | ||
} | ||
case ed25519.PrivateKey: | ||
if kr.Algo() != "ed25519" { | ||
t.Fatal("Ed25519 key generated, but expected", kr.Algo()) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -113,7 +117,7 @@ func TestParseRequest(t *testing.T) { | |
KeyRequest: NewKeyRequest(), | ||
Extensions: []pkix.Extension{ | ||
pkix.Extension{ | ||
Id: asn1.ObjectIdentifier{1, 2, 3, 4, 5}, | ||
Id: asn1.ObjectIdentifier{1, 2, 3, 4, 5}, | ||
Value: []byte("AgEB"), | ||
}, | ||
}, | ||
|
@@ -123,7 +127,7 @@ func TestParseRequest(t *testing.T) { | |
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
||
block, _ := pem.Decode(csrBytes) | ||
if block == nil { | ||
t.Fatalf("%v", err) | ||
|
@@ -310,6 +314,21 @@ func TestECGeneration(t *testing.T) { | |
} | ||
} | ||
|
||
func TestED25519Generation(t *testing.T) { | ||
kr := &KeyRequest{"ed25519", 256} | ||
priv, err := kr.Generate() | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
_, ok := priv.(ed25519.PrivateKey) | ||
if !ok { | ||
t.Fatal("Expected ed25519 key") | ||
} | ||
if sa := kr.SigAlgo(); sa == x509.UnknownSignatureAlgorithm { | ||
t.Fatal("Invalid signature algorithm!") | ||
} | ||
} | ||
|
||
func TestRSAKeyGeneration(t *testing.T) { | ||
var rsakey *rsa.PrivateKey | ||
|
||
|
@@ -356,6 +375,13 @@ func TestBadKeyRequest(t *testing.T) { | |
t.Fatal("The wrong signature algorithm was returned from SigAlgo!") | ||
} | ||
|
||
kr.A = "ed25519" | ||
if _, err := kr.Generate(); err == nil { | ||
t.Fatal("Key generation should fail with invalid key size") | ||
} else if sa := kr.SigAlgo(); sa != x509.PureEd25519 { | ||
t.Fatal("The wrong signature algorithm was returned from SigAlgo!") | ||
} | ||
|
||
kr = &KeyRequest{"tobig", 9216} | ||
|
||
kr.A = "rsa" | ||
|
@@ -403,6 +429,10 @@ func TestDefaultKeyRequest(t *testing.T) { | |
if DefaultKeyRequest.Algo() != "ecdsa" { | ||
t.Fatal("Invalid default key request.") | ||
} | ||
case "Ed25519 PRIVATE KEY": | ||
if DefaultKeyRequest.Algo() != "ed25519" { | ||
t.Fatal("Invalid default key request.") | ||
} | ||
} | ||
} | ||
|
||
|
@@ -429,6 +459,29 @@ func TestRSACertRequest(t *testing.T) { | |
} | ||
} | ||
|
||
// TestED25519CertRequest validates parsing a certificate request with an | ||
// ED25519 key. | ||
func TestED25519CertRequest(t *testing.T) { | ||
var req = &CertificateRequest{ | ||
Names: []Name{ | ||
{ | ||
C: "US", | ||
ST: "California", | ||
L: "San Francisco", | ||
O: "CloudFlare", | ||
OU: "Systems Engineering", | ||
}, | ||
}, | ||
CN: "cloudflare.com", | ||
Hosts: []string{"cloudflare.com", "www.cloudflare.com", "[email protected]", "https://www.cloudflare.com"}, | ||
KeyRequest: &KeyRequest{"ed25519", 256}, | ||
} | ||
_, _, err := ParseRequest(req) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
} | ||
|
||
// TestBadCertRequest checks for failure conditions of ParseRequest. | ||
func TestBadCertRequest(t *testing.T) { | ||
var req = &CertificateRequest{ | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the problem the todo refers to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this was a remanent of thinking how to change some x509 things..