Skip to content

Commit c4a109f

Browse files
authored
Merge pull request #31 from kerokim/main
cryptography의 deprecated 항목 대응
2 parents bc38a05 + ebabee4 commit c4a109f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

pypinksign/pypinksign.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
from os.path import expanduser
1010
from sys import platform as _platform
1111

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

29+
if cryptography_version >= '43.0.0':
30+
from cryptography.hazmat.decrepit.ciphers import algorithms
31+
else:
32+
from cryptography.hazmat.primitives.ciphers import algorithms
33+
34+
2935
ID_SEED_CBC = (1, 2, 410, 200004, 1, 4)
3036
ID_SEED_CBC_WITH_SHA1 = (1, 2, 410, 200004, 1, 15)
3137
ID_PBES2 = (1, 2, 840, 113549, 1, 5, 13)
@@ -250,11 +256,11 @@ def valid_date(self) -> (datetime, datetime):
250256
"""Get valid date range
251257
252258
p = PinkSign(pubkey_path="/some/path/signCert.der")
253-
print p.valid_date() # datetime.datetime(2019, 6, 11, 14, 59, 59), datetime.datetime(2018, 6, 5, 7, 22)
259+
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)
254260
"""
255261
if self.pub_cert is None:
256262
raise ValueError("Public key should be loaded before fetching valid date.")
257-
return self.pub_cert.not_valid_before, self.pub_cert.not_valid_after
263+
return self.pub_cert.not_valid_before_utc, self.pub_cert.not_valid_after_utc
258264

259265
def serialnum(self) -> int:
260266
"""Get serial number value

pypinksign/test_pinkSign.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@
144144
'issuer': 'yessign',
145145
'certClass': 'yessignCA-Test Class 4',
146146
'typeOid': '1.2.410.200005.1.1.4',
147-
'notValidBefore': datetime.datetime(2020, 2, 24, 15, 0),
148-
'notValidAfter': datetime.datetime(2020, 3, 25, 14, 59, 59),
147+
'notValidBefore': datetime.datetime(2020, 2, 24, 15, 0, tzinfo=datetime.timezone.utc),
148+
'notValidAfter': datetime.datetime(2020, 3, 25, 14, 59, 59, tzinfo=datetime.timezone.utc),
149149
'serialnum': 4562037,
150150
'r': bytes.fromhex('78 58 B4 32 83 90 80 51 29 F0 1C 97 FE 6C A4 A5 20 CB D4 79'.replace(' ', '')),
151151
'n': 16290209604510558512424059741651375064654753567992722580828628971708562130349008444810203521124558177825814339343207835427689025822285584732821780446150030117526628261085286225778211374294648916395223865257683288643551550943391795793773752999484548197810621853518105898239621319606067171572461184051376253498427234926384321524162077496373015541984328411287155862092598397499222651575268924929909579288769213787457173333761144872762255105990945866750105589086207927132458172404823977276816345606547939329781107327373658261705552620519785541773479297095905819124179278019444174466369977583873333772287403026516394802051,

0 commit comments

Comments
 (0)