Skip to content

Commit 336370a

Browse files
committed
Upgrade pyOpenSSL and cryptography
1 parent bce42b0 commit 336370a

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

requirements-manual.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Django==4.2.20
44
asgiref==3.7.2
55
django-allauth==65.0.2
6+
cryptography==44.0.1
67
gevent==24.11.1
78
Markdown==3.7
89
psycopg==3.2.3
@@ -11,7 +12,7 @@ psycopg-pool==3.2.3
1112
pycryptodome==3.21.0
1213
pygments==2.18.0
1314
pymemcache==4.0.0
14-
pyOpenSSL==24.2.1
15+
pyOpenSSL==24.3.0
1516
PyYAML==6.0.2
1617
requests==2.32.3
1718
uWSGI==2.0.28

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ asgiref==3.7.2
22
certifi==2025.4.26
33
cffi==1.17.1
44
charset-normalizer==3.4.1
5-
cryptography==43.0.3
5+
cryptography==44.0.1
66
Django==4.2.20
77
django-allauth==65.0.2
88
gevent==24.11.1
@@ -17,7 +17,7 @@ pycryptodome==3.21.0
1717
Pygments==2.18.0
1818
PyJWT==2.9.0
1919
pymemcache==4.0.0
20-
pyOpenSSL==24.2.1
20+
pyOpenSSL==24.3.0
2121
PyYAML==6.0.2
2222
requests==2.32.3
2323
setuptools==80.0.0

server/user/interface.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import base64
2-
import OpenSSL
2+
from cryptography.hazmat.primitives import serialization, hashes
3+
from cryptography.hazmat.primitives.asymmetric import padding
34
from hashlib import sha256
45
from uuid import uuid4
56

@@ -116,8 +117,10 @@ class User:
116117
'aff': RegexValidator(r'^.{1,100}$', '了解比赛的渠道格式错误'),
117118
'suspicious_reason': None,
118119
}
119-
_private_key = OpenSSL.crypto.load_privatekey(
120-
OpenSSL.crypto.FILETYPE_PEM, settings.PRIVATE_KEY)
120+
_private_key = serialization.load_pem_private_key(
121+
settings.PRIVATE_KEY.encode(),
122+
password=None,
123+
)
121124

122125
def __init__(self, context, obj: models.User):
123126
self._context = context
@@ -154,8 +157,11 @@ def create(cls, context, group, user=None, **kwargs):
154157
user = get_user_model().objects.create_user(str(uuid4()))
155158
self = cls(context, models.User(user=user.pk))
156159
pk = str(user.pk)
157-
sig = base64.b64encode(OpenSSL.crypto.sign(
158-
self._private_key, pk.encode(), 'sha256')).decode()
160+
sig = base64.b64encode(self._private_key.sign(
161+
pk.encode(),
162+
padding.PKCS1v15(),
163+
hashes.SHA256()
164+
)).decode()
159165
self._obj.token = pk + ':' + sig
160166
try:
161167
server.trigger.interface.Trigger.test_can_update_profile(context)

0 commit comments

Comments
 (0)