@@ -174,8 +174,6 @@ func (k JSONWebKey) MarshalJSON() ([]byte, error) {
174
174
return json .Marshal (raw )
175
175
}
176
176
177
- var errUnsupportedJWK = errors .New ("go-jose/go-jose: unsupported json web key" )
178
-
179
177
// UnmarshalJSON reads a key from its JSON representation.
180
178
func (k * JSONWebKey ) UnmarshalJSON (data []byte ) (err error ) {
181
179
var raw rawJSONWebKey
@@ -230,7 +228,7 @@ func (k *JSONWebKey) UnmarshalJSON(data []byte) (err error) {
230
228
}
231
229
key , err = raw .symmetricKey ()
232
230
case "OKP" :
233
- if raw .Crv == "Ed25519" {
231
+ if raw .Crv == "Ed25519" && raw . X != nil {
234
232
if raw .D != nil {
235
233
key , err = raw .edPrivateKey ()
236
234
if err == nil {
@@ -240,29 +238,17 @@ func (k *JSONWebKey) UnmarshalJSON(data []byte) (err error) {
240
238
key , err = raw .edPublicKey ()
241
239
keyPub = key
242
240
}
241
+ } else {
242
+ err = fmt .Errorf ("go-jose/go-jose: unknown curve %s'" , raw .Crv )
243
243
}
244
- case "" :
245
- // kty MUST be present
246
- err = fmt .Errorf ("go-jose/go-jose: missing json web key type" )
244
+ default :
245
+ err = fmt .Errorf ("go-jose/go-jose: unknown json web key type '%s'" , raw .Kty )
247
246
}
248
247
249
248
if err != nil {
250
249
return
251
250
}
252
251
253
- if key == nil {
254
- // RFC 7517:
255
- // 5. JWK Set Format
256
- // ...
257
- // Implementations SHOULD ignore JWKs within a JWK Set that use "kty"
258
- // (key type) values that are not understood by them, that are missing
259
- // required members, or for which values are out of the supported
260
- // ranges.
261
-
262
- // Fail unmarshal with errUnsupportedJWK
263
- return errUnsupportedJWK
264
- }
265
-
266
252
if certPub != nil && keyPub != nil {
267
253
if ! reflect .DeepEqual (certPub , keyPub ) {
268
254
return errors .New ("go-jose/go-jose: invalid JWK, public keys in key and x5c fields do not match" )
@@ -362,34 +348,6 @@ func (s *JSONWebKeySet) Key(kid string) []JSONWebKey {
362
348
return keys
363
349
}
364
350
365
- func (s * JSONWebKeySet ) UnmarshalJSON (data []byte ) (err error ) {
366
- type rawJSONWebKeySet struct {
367
- Keys []json.RawMessage `json:"keys"`
368
- }
369
-
370
- var rs rawJSONWebKeySet
371
- err = json .Unmarshal (data , & rs )
372
- if err != nil {
373
- return err
374
- }
375
-
376
- for _ , rk := range rs .Keys {
377
- var k JSONWebKey
378
- err = json .Unmarshal (rk , & k )
379
- if err != nil {
380
- // Skip key and continue unmarshalling the key set if key unmarshal
381
- // failed because of unsupported key type or parameters.
382
- if ! errors .Is (err , errUnsupportedJWK ) {
383
- return err
384
- }
385
- } else {
386
- s .Keys = append (s .Keys , k )
387
- }
388
- }
389
-
390
- return nil
391
- }
392
-
393
351
const rsaThumbprintTemplate = `{"e":"%s","kty":"RSA","n":"%s"}`
394
352
const ecThumbprintTemplate = `{"crv":"%s","kty":"EC","x":"%s","y":"%s"}`
395
353
const edThumbprintTemplate = `{"crv":"%s","kty":"OKP","x":"%s"}`
0 commit comments