mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 11:38:02 +00:00
Add support for ed25519 (#11780)
* update azure instructions Update instructions in regards to azure AD Authentication and OIDC * Initial pass of ed25519 * Fix typos on marshal function * test wip * typo * fix tests * missef changelog * fix mismatch between signature and algo * added test coverage for ed25519 * remove pkcs1 since does not exist for ed25519 * add ed25519 support to getsigner * pull request feedback Signed-off-by: Anner J. Bonilla <abonilla@hoyosintegrity.com> * typo on key Signed-off-by: Anner J. Bonilla <abonilla@hoyosintegrity.com> * cast mistake Signed-off-by: Anner J. Bonilla <abonilla@hoyosintegrity.com> Co-authored-by: Jim Kalafut <jkalafut@hashicorp.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"crypto"
|
||||
"crypto/ecdsa"
|
||||
"crypto/ed25519"
|
||||
"crypto/elliptic"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
@@ -211,6 +212,8 @@ func TestBackend_Roles(t *testing.T) {
|
||||
{"RSACSR", &rsaCAKey, &rsaCACert, true},
|
||||
{"EC", &ecCAKey, &ecCACert, false},
|
||||
{"ECCSR", &ecCAKey, &ecCACert, true},
|
||||
{"ED", &edCAKey, &edCACert, false},
|
||||
{"EDCSR", &edCAKey, &edCACert, true},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
@@ -309,6 +312,13 @@ func checkCertsAndPrivateKey(keyType string, key crypto.Signer, usage x509.KeyUs
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing EC key: %s", err)
|
||||
}
|
||||
case "ed25519":
|
||||
parsedCertBundle.PrivateKeyType = certutil.Ed25519PrivateKey
|
||||
parsedCertBundle.PrivateKey = key
|
||||
parsedCertBundle.PrivateKeyBytes, err = x509.MarshalPKCS8PrivateKey(key.(ed25519.PrivateKey))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing Ed25519 key: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,6 +334,8 @@ func checkCertsAndPrivateKey(keyType string, key crypto.Signer, usage x509.KeyUs
|
||||
}
|
||||
|
||||
switch {
|
||||
case parsedCertBundle.PrivateKeyType == certutil.Ed25519PrivateKey && keyType != "ed25519":
|
||||
fallthrough
|
||||
case parsedCertBundle.PrivateKeyType == certutil.RSAPrivateKey && keyType != "rsa":
|
||||
fallthrough
|
||||
case parsedCertBundle.PrivateKeyType == certutil.ECPrivateKey && keyType != "ec":
|
||||
@@ -707,7 +719,7 @@ func generateRoleSteps(t *testing.T, useCSRs bool) []logicaltest.TestStep {
|
||||
|
||||
generatedRSAKeys := map[int]crypto.Signer{}
|
||||
generatedECKeys := map[int]crypto.Signer{}
|
||||
|
||||
generatedEdKeys := map[int]crypto.Signer{}
|
||||
/*
|
||||
// For the number of tests being run, a seed of 1 has been tested
|
||||
// to hit all of the various values below. However, for normal
|
||||
@@ -1017,6 +1029,13 @@ func generateRoleSteps(t *testing.T, useCSRs bool) []logicaltest.TestStep {
|
||||
generatedECKeys[keyBits] = privKey
|
||||
}
|
||||
|
||||
case "ed25519":
|
||||
privKey, ok = generatedEdKeys[keyBits]
|
||||
if !ok {
|
||||
_, privKey, _ = ed25519.GenerateKey(rand.Reader)
|
||||
generatedEdKeys[keyBits] = privKey
|
||||
}
|
||||
|
||||
default:
|
||||
panic("invalid key type: " + keyType)
|
||||
}
|
||||
@@ -3095,6 +3114,36 @@ func setCerts() {
|
||||
Bytes: caBytes,
|
||||
}
|
||||
rsaCACert = strings.TrimSpace(string(pem.EncodeToMemory(caCertPEMBlock)))
|
||||
|
||||
_, edk, err := ed25519.GenerateKey(rand.Reader)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
marshaledKey, err = x509.MarshalPKCS8PrivateKey(edk)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
keyPEMBlock = &pem.Block{
|
||||
Type: "PRIVATE KEY",
|
||||
Bytes: marshaledKey,
|
||||
}
|
||||
edCAKey = strings.TrimSpace(string(pem.EncodeToMemory(keyPEMBlock)))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
subjKeyID, err = certutil.GetSubjKeyID(edk)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
caBytes, err = x509.CreateCertificate(rand.Reader, caCertTemplate, caCertTemplate, edk.Public(), edk)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
caCertPEMBlock = &pem.Block{
|
||||
Type: "CERTIFICATE",
|
||||
Bytes: caBytes,
|
||||
}
|
||||
edCACert = strings.TrimSpace(string(pem.EncodeToMemory(caCertPEMBlock)))
|
||||
}
|
||||
|
||||
func TestBackend_RevokePlusTidy_Intermediate(t *testing.T) {
|
||||
@@ -3281,4 +3330,6 @@ var (
|
||||
rsaCACert string
|
||||
ecCAKey string
|
||||
ecCACert string
|
||||
edCAKey string
|
||||
edCACert string
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user