Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
fix jwk conversion (#472)
Browse files Browse the repository at this point in the history
* fix jwk conversion

* add conversion methods
  • Loading branch information
decentralgabe authored Oct 16, 2023
1 parent 7bd066d commit a0ddb18
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 496 deletions.
6 changes: 5 additions & 1 deletion crypto/jwx/jwk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
gocrypto "crypto"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/elliptic"
"crypto/rsa"
"encoding/base64"
"fmt"
Expand Down Expand Up @@ -83,7 +84,7 @@ func (k *PrivateKeyJWK) ToPrivateKey() (gocrypto.PrivateKey, error) {
}
k.ALG = alg
}
if IsSupportedJWXSigningVerificationAlgorithm(k.ALG) {
if IsSupportedJWXSigningVerificationAlgorithm(k.ALG) || IsSupportedKeyAgreementType(k.ALG) {
return k.toSupportedPrivateKey()
}
if IsExperimentalJWXSigningVerificationAlgorithm(k.ALG) {
Expand Down Expand Up @@ -303,6 +304,9 @@ func PrivateKeyToPrivateKeyJWK(keyID string, key gocrypto.PrivateKey) (*PublicKe
case secp256k1.PrivateKey:
pubKeyJWK, privKeyJWK, err = jwkFromSECP256k1PrivateKey(k)
case ecdsa.PrivateKey:
if k.Curve == elliptic.P224() {
return nil, nil, fmt.Errorf("unsupported curve: %s", k.Curve.Params().Name)
}
pubKeyJWK, privKeyJWK, err = jwkFromECDSAPrivateKey(k)
case mode2.PrivateKey:
privKey := dilithium.Mode2.PrivateKeyFromBytes(k.Bytes())
Expand Down
Loading

0 comments on commit a0ddb18

Please sign in to comment.