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

Merge branch '8-fix-ed25519-key-conversion' into 'main'

Fix ed25519 public key conversion to JWK

Closes #8

See merge request eclipse/xfsc/tsa/signer!19
parents 25e2aba4 a090ebaf
Branches
Tags 0.0.1
No related merge requests found
......@@ -631,11 +631,15 @@ func (s *Service) jwkFromKey(key *VaultKey) (*jose.JSONWebKey, error) {
switch key.Type {
case "ed25519":
k.Key = ed25519.PublicKey(key.PublicKey)
case "ecdsa-p256", "ecdsa-p384", "ecdsa-p521", "rsa-2048":
pk, err := base64.StdEncoding.DecodeString(key.PublicKey)
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))
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)
......@@ -644,7 +648,7 @@ func (s *Service) jwkFromKey(key *VaultKey) (*jose.JSONWebKey, error) {
}
k.Key = pub
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment