Skip to content

Commit

Permalink
include kid (name) in public JWK output (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter authored Dec 19, 2024
1 parent 9d59a4e commit bd6c969
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
7 changes: 1 addition & 6 deletions nodeman/internal_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
from cryptography.hazmat.primitives.serialization import load_pem_private_key
from cryptography.x509.oid import ExtendedKeyUsageOID, NameOID

from nodeman.x509 import (
CertificateAuthorityClient,
CertificateInformation,
PrivateKey,
verify_x509_csr_signature,
)
from nodeman.x509 import CertificateAuthorityClient, CertificateInformation, PrivateKey, verify_x509_csr_signature


class InternalCertificateAuthority(CertificateAuthorityClient):
Expand Down
3 changes: 2 additions & 1 deletion nodeman/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ async def get_node_public_key(
content = JWK(**node.public_key).export_to_pem().decode()
case PublicKeyFormat.JWK:
with tracer.start_as_current_span("get_public_key_jwk"):
content = json.dumps(node.public_key)
jwk_dict = {**node.public_key, "kid": name}
content = json.dumps(jwk_dict)
except ValueError as exc:
raise HTTPException(status.HTTP_406_NOT_ACCEPTABLE) from exc

Expand Down
13 changes: 5 additions & 8 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
from nodeman.models import PublicKeyFormat
from nodeman.server import NodemanServer
from nodeman.settings import Settings
from nodeman.x509 import (
RSA_EXPONENT,
CertificateAuthorityClient,
generate_ca_certificate,
generate_x509_csr,
)
from nodeman.x509 import RSA_EXPONENT, CertificateAuthorityClient, generate_ca_certificate, generate_x509_csr

ADMIN_TEST_NODE_COUNT = 100
BACKEND_CREDENTIALS = ("username", "password")
Expand Down Expand Up @@ -152,11 +147,13 @@ def _test_enroll(data_key: JWK, x509_key: PrivateKey, requested_name: str | None

response = client.get(public_key_url, headers={"Accept": "application/json"})
assert response.status_code == status.HTTP_200_OK
_ = JWK.from_json(response.text)
res = JWK.from_json(response.text)
assert res.kid == name

response = client.get(public_key_url, headers={"Accept": PublicKeyFormat.JWK})
assert response.status_code == status.HTTP_200_OK
_ = JWK.from_json(response.text)
res = JWK.from_json(response.text)
assert res.kid == name

response = client.get(public_key_url, headers={"Accept": PublicKeyFormat.PEM})
assert response.status_code == status.HTTP_200_OK
Expand Down

0 comments on commit bd6c969

Please sign in to comment.