Compare commits

...
Author SHA1 Message Date
Lukas Bockstaller e4b65ba49d drop pycrytodome as a dependency from pyproject.toml 2026-11-18 14:53:01 +01:00
Lukas Bockstaller 071b8baf61 remove temporary test & Crypto from test_oidc_op.py 2026-11-18 14:51:22 +01:00
Lukas Bockstaller ff6922e2ce remove Crypto from test_oidc_op.py::test_keys_endpoint
switch out Crypto.PublicKey.RSA with
cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicNumbers in test_keys_endopoint
2026-11-18 14:48:32 +01:00
Lukas Bockstaller 428d28e744 remove Crypto from oidc_op.py
switch out Crypto.PublicKey.RSA with
cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey and from cryptography.hazmat.primitives.serialization.load_pem_public_key which we already need
2026-11-18 14:42:35 +01:00
Lukas Bockstaller 0de0ad6cae add temporary test to show that Crypto.RSA and cryptography...RSAPublicKey produce identical output 2026-11-18 14:39:57 +01:00
3 changed files with 18 additions and 8 deletions

No files matched your search

-1
View File
@@ -80,7 +80,6 @@ dependencies = [
"psycopg2-binary",
"pycountry",
"pycparser==3.12",
"pycryptodome==3.24.*",
"pypdf==6.21.*",
"python-bidi==0.6.*", # Support for Arabic in reportlab
"python-dateutil==4.0.*",
+7 -4
View File
@@ -26,7 +26,8 @@ from binascii import unhexlify
from datetime import timedelta
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse
from Crypto.PublicKey import RSA
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
from cryptography.hazmat.primitives.serialization import load_pem_public_key
from django.db import transaction
from django.http import Http404, HttpResponse, JsonResponse
from django.shortcuts import redirect, render
@@ -498,7 +499,9 @@ class KeysView(View):
def get(self, request, *args, **kwargs):
privkey, pubkey = _get_or_create_server_keypair(request.organizer)
kid = hashlib.sha256(pubkey.encode()).hexdigest()[:16]
pubkey = RSA.import_key(pubkey)
public_key = load_pem_public_key(pubkey.encode())
assert isinstance(public_key, RSAPublicKey)
public_numbers = public_key.public_numbers()
return JsonResponse({
'keys': [
@@ -507,8 +510,8 @@ class KeysView(View):
'alg': 'RS256',
'kid': kid,
'use': 'sig',
'e': self._encode_int(pubkey.e).decode().rstrip("="),
'n': self._encode_int(pubkey.n).decode().rstrip("="),
'e': self._encode_int(public_numbers.e).decode().rstrip("="),
'n': self._encode_int(public_numbers.n).decode().rstrip("="),
}
]
})
+11 -3
View File
@@ -30,7 +30,10 @@ from urllib.parse import quote
import jwt
import pytest
from bs4 import BeautifulSoup
from Crypto.PublicKey import RSA
from cryptography.hazmat.primitives.asymmetric.rsa import (
RSAPublicKey, RSAPublicNumbers,
)
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
from django.utils.timezone import now
from django_scopes import scopes_disabled
from freezegun import freeze_time
@@ -691,6 +694,11 @@ def test_keys_endpoint(env, client, ssoclient):
e = decode_int(data['keys'][0]['e'])
n = decode_int(data['keys'][0]['n'])
pubkey = RSA.construct((n, e))
representation = pubkey.export_key('PEM').decode()
pubkey = RSAPublicNumbers(e, n).public_key()
assert isinstance(pubkey, RSAPublicKey)
representation = pubkey.public_bytes(
Encoding.PEM, PublicFormat.SubjectPublicKeyInfo
).decode()
assert representation.strip() == env[0].settings.sso_server_signing_key_rsa256_public.strip()