php-jwt icon indicating copy to clipboard operation
php-jwt copied to clipboard

Cannot use JWK::parseKey for kty=='oct'

Open juacala opened this issue 1 year ago • 4 comments

The following code does not work:

$keyInfo = [ 
        "kty" => "oct",
        "kid" => "unitTestJWKHMAC",
        "alg" => "HS256",
        "k"   => "SecretKey",
    ]
$jwk = \Firebase\JWT\JWK::parseKey($keyInfo);

Is there an intention to support this?

juacala avatar Jan 12 '24 00:01 juacala

Hi @juacala , thanks for opening this issue. We are aware of this feature request of supporting octet sequence algorithm but it hasn't been on priority as of now and we cannot comment on when this will be supported. If you'd like to submit a feature PR for this, please do so, as that would be a huge help to us!

yash30201 avatar Jan 17 '24 16:01 yash30201

@yash30201 I'll circle back to this when I get some bandwidth. I didn't have a development branch checked out, but this addition to JWT::parseKey seemed to do the trick:

            case 'oct':
                    return new Key(JWT::urlsafeB64Decode($jwk['k']), $jwk['alg']);

juacala avatar Jan 22 '24 13:01 juacala

@juacala thank you for your suggestion. I'd like to do better than "seems to do the trick" if we add this to this library, however.

Can you provide us with more information about your use-case? a sample key that we could use for testing would also be great.

I've found some information on using the octet keys in the JWK IETF spec and this jwk generation guide

bshaffer avatar Jan 22 '24 16:01 bshaffer

I understand. I should have been more direct in my language. Adding the above code will satisfy the appropriate spec. I tested it both encoding and decoding using your library, as well as using a Javascript library as another party. I'll do my best to find some time to get a PR to y'all for your testing.

juacala avatar Jan 24 '24 18:01 juacala