|
|
|
|
@ -255,34 +255,21 @@ func parsePEMToJWK(pemStr string) (*jose.JSONWebKey, error) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Check if it's a raw 32-byte ED25519 key
|
|
|
|
|
var ed25519Key ed25519.PublicKey |
|
|
|
|
if len(keyBytes) == 32 { |
|
|
|
|
ed25519Key := ed25519.PublicKey(keyBytes) |
|
|
|
|
|
|
|
|
|
jwk := &jose.JSONWebKey{ |
|
|
|
|
Key: ed25519Key, |
|
|
|
|
Algorithm: "EdDSA", |
|
|
|
|
Use: "sig", |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
thumbprint, err := jwk.Thumbprint(crypto.SHA256) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
jwk.KeyID = base64.RawURLEncoding.EncodeToString(thumbprint) |
|
|
|
|
|
|
|
|
|
return jwk, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Try to parse as PKIX public key
|
|
|
|
|
pub, err := x509.ParsePKIXPublicKey(keyBytes) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, fmt.Errorf("failed to parse raw key: %v", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Create JWK for ED25519 key
|
|
|
|
|
ed25519Key, ok := pub.(ed25519.PublicKey) |
|
|
|
|
if !ok { |
|
|
|
|
return nil, fmt.Errorf("expected ED25519 key, got %T", pub) |
|
|
|
|
} else { |
|
|
|
|
// Try to parse as PKIX public key
|
|
|
|
|
pub, err := x509.ParsePKIXPublicKey(keyBytes) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, fmt.Errorf("failed to parse raw key: %v", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Create JWK for ED25519 key
|
|
|
|
|
ed25519Key, ok := pub.(ed25519.PublicKey) |
|
|
|
|
if !ok { |
|
|
|
|
return nil, fmt.Errorf("expected ED25519 key, got %T", pub) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
jwk := &jose.JSONWebKey{ |
|
|
|
|
|