Skip to content
Snippets Groups Projects
Commit a090ebaf authored by Lyuben Penkovski's avatar Lyuben Penkovski
Browse files

Fix ed25519 public key conversion to JWK

parent 25e2aba4
Branches
No related tags found
No related merge requests found
...@@ -631,11 +631,15 @@ func (s *Service) jwkFromKey(key *VaultKey) (*jose.JSONWebKey, error) { ...@@ -631,11 +631,15 @@ func (s *Service) jwkFromKey(key *VaultKey) (*jose.JSONWebKey, error) {
switch key.Type { switch key.Type {
case "ed25519": case "ed25519":
k.Key = ed25519.PublicKey(key.PublicKey) pk, err := base64.StdEncoding.DecodeString(key.PublicKey)
case "ecdsa-p256", "ecdsa-p384", "ecdsa-p521", "rsa-2048": if err != nil {
return nil, fmt.Errorf("jwkFromKey: failed to decode ed25519 key: %v", err)
}
k.Key = ed25519.PublicKey(pk)
case "ecdsa-p256", "ecdsa-p384", "ecdsa-p521", "rsa-2048", "rsa-3072", "rsa-4096":
block, _ := pem.Decode([]byte(key.PublicKey)) block, _ := pem.Decode([]byte(key.PublicKey))
if block == nil { if block == nil {
return nil, fmt.Errorf("no public key found during PEM decode") return nil, fmt.Errorf("jwkFromKey: no public key found during PEM decode")
} }
pub, err := x509.ParsePKIXPublicKey(block.Bytes) pub, err := x509.ParsePKIXPublicKey(block.Bytes)
...@@ -644,7 +648,7 @@ func (s *Service) jwkFromKey(key *VaultKey) (*jose.JSONWebKey, error) { ...@@ -644,7 +648,7 @@ func (s *Service) jwkFromKey(key *VaultKey) (*jose.JSONWebKey, error) {
} }
k.Key = pub k.Key = pub
default: default:
return nil, fmt.Errorf("unsupported key type: %s", key.Type) return nil, fmt.Errorf("jwkFromKey: unsupported key type: %s", key.Type)
} }
return k, nil return k, nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment