Shouldn't `jwk.import_from_pyca` also provide a `kid` param and set it to `thumbprint()` by default?

Open
#332 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
55/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
api

Research direction

Start in jwcrypto/jwk.py at import_from_pyca (around line 1012) and compare it with import_from_pem's handling of kid. Check how thumbprint() is used there and how JWKSet.export treats keys without a kid. Done when import_from_pyca can accept an optional kid and defaults it consistently, with tests covering both an explicit kid and the default case.

Written by the indexing model from the issue text.

Description

Easy Fix enhancement help wanted

When importing from a pem file (import_from_pem), the kid can be set or if not, it uses the thumbprint() by default.
Especially when the jwk is added to a jwks afterwards - and potentially multiple keys are in the jwks, a kid would be required to identify the right key.

https://github.com/latchset/jwcrypto/blob/41fb08a00ad2a36a1d85bf77ad973b31144ef9f2/jwcrypto/jwk.py#L1012

Example workaround:

    pub_jwk.import_from_pyca(pub_key)
    pub_jwk['kid'] = pub_jwk.thumbprint()
    jwks = JWKSet()
    jwks.add(pub_jwk)
    jwks_export = jwks.export(private_keys=False, as_dict=True)

Anything I'm doing wrong here?
Thanks,
Matthias

Dominant language
Python
Stars
478
Forks
132
Avg merge
7h 38m
Merged PRs (30d)
4

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from latchset/jwcrypto

All issues in latchset/jwcrypto

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.