Skip to content

cryptography의 deprecated 항목 대응 #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions pypinksign/pypinksign.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
from os.path import expanduser
from sys import platform as _platform

from cryptography import x509
from cryptography import x509, __version__ as cryptography_version
from cryptography.exceptions import InvalidSignature, UnsupportedAlgorithm
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import padding, hashes, serialization
from cryptography.hazmat.primitives.asymmetric.padding import PKCS1v15
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicNumbers, RSAPrivateNumbers, rsa_crt_iqmp, \
rsa_crt_dmp1, rsa_crt_dmq1, RSAPublicKey, RSAPrivateKey
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives.ciphers import Cipher, modes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.primitives.serialization import pkcs12
from pyasn1.codec.der import decoder as der_decoder
Expand All @@ -26,6 +26,12 @@
from pyasn1.type.namedtype import NamedTypes, NamedType
from pyasn1.type.univ import Sequence, Integer, OctetString, ObjectIdentifier, Set, BitString, Null

if cryptography_version >= '43.0.0':
from cryptography.hazmat.decrepit.ciphers import algorithms
else:
from cryptography.hazmat.primitives.ciphers import algorithms


ID_SEED_CBC = (1, 2, 410, 200004, 1, 4)
ID_SEED_CBC_WITH_SHA1 = (1, 2, 410, 200004, 1, 15)
ID_PBES2 = (1, 2, 840, 113549, 1, 5, 13)
Expand Down Expand Up @@ -250,11 +256,11 @@ def valid_date(self) -> (datetime, datetime):
"""Get valid date range

p = PinkSign(pubkey_path="/some/path/signCert.der")
print p.valid_date() # datetime.datetime(2019, 6, 11, 14, 59, 59), datetime.datetime(2018, 6, 5, 7, 22)
print p.valid_date() # datetime.datetime(2019, 6, 11, 14, 59, 59, tzinfo=datetime.timezone.utc), datetime.datetime(2018, 6, 5, 7, 22, tzinfo=datetime.timezone.utc)
"""
if self.pub_cert is None:
raise ValueError("Public key should be loaded before fetching valid date.")
return self.pub_cert.not_valid_before, self.pub_cert.not_valid_after
return self.pub_cert.not_valid_before_utc, self.pub_cert.not_valid_after_utc

def serialnum(self) -> int:
"""Get serial number value
Expand Down
4 changes: 2 additions & 2 deletions pypinksign/test_pinkSign.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@
'issuer': 'yessign',
'certClass': 'yessignCA-Test Class 4',
'typeOid': '1.2.410.200005.1.1.4',
'notValidBefore': datetime.datetime(2020, 2, 24, 15, 0),
'notValidAfter': datetime.datetime(2020, 3, 25, 14, 59, 59),
'notValidBefore': datetime.datetime(2020, 2, 24, 15, 0, tzinfo=datetime.timezone.utc),
'notValidAfter': datetime.datetime(2020, 3, 25, 14, 59, 59, tzinfo=datetime.timezone.utc),
'serialnum': 4562037,
'r': bytes.fromhex('78 58 B4 32 83 90 80 51 29 F0 1C 97 FE 6C A4 A5 20 CB D4 79'.replace(' ', '')),
'n': 16290209604510558512424059741651375064654753567992722580828628971708562130349008444810203521124558177825814339343207835427689025822285584732821780446150030117526628261085286225778211374294648916395223865257683288643551550943391795793773752999484548197810621853518105898239621319606067171572461184051376253498427234926384321524162077496373015541984328411287155862092598397499222651575268924929909579288769213787457173333761144872762255105990945866750105589086207927132458172404823977276816345606547939329781107327373658261705552620519785541773479297095905819124179278019444174466369977583873333772287403026516394802051,
Expand Down