Skip to content

Commit

Permalink
added get_certificate_expiry_date and certificate_is_expired
Browse files Browse the repository at this point in the history
  • Loading branch information
anionDev committed Jan 21, 2023
1 parent 582a399 commit 1dc78c2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions .vscode/spellright.dict
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ docfx
cyclonedx
gitversion
dockerfile
pyOpenSSL
1 change: 1 addition & 0 deletions License.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ScriptCollection uses dependencies which are released under their own license:
-keyboard is licensed under the terms of the MIT-license (see appendix 1)
-lxml is licensed under the terms of the BSD-license (see https://pypi.org/project/lxml )
-ntplib is licensed under the terms of the MIT-license (see appendix 1)
-pyOpenSSL is licensed under the terms of the Apache License, Version 2.0-license (see https://raw.githubusercontent.com/pyca/pyopenssl/main/LICENSE )
-PyPDF2 is licensed under the terms of its own license (see appendix 2)
-pycdlib is licensed under the terms of the LGPL-v2.1-license (see appendix 3)
-qrcode is licensed under the terms of the BSD-license (see https://pypi.org/project/qrcode )
Expand Down
17 changes: 17 additions & 0 deletions ScriptCollection/ScriptCollection/GeneralUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from shutil import copyfile
import typing
from defusedxml.minidom import parse
from OpenSSL import crypto


class GeneralUtilities:
Expand Down Expand Up @@ -791,3 +792,19 @@ def generate_password(length: int = 16, alphabet: str = None) -> None:
def assert_condition(condition: bool, information: str) -> None:
if (not condition):
raise ValueError("Condition failed. "+information)

@staticmethod
@check_arguments
def get_certificate_expiry_date(certificate_file: str) -> datetime:
with open(certificate_file, encoding="utf-8") as certificate_file_content:
cert = crypto.load_certificate(crypto.FILETYPE_PEM, certificate_file_content.read())
date_as_bytes = cert.get_notAfter()
date_as_string = date_as_bytes.decode("utf-8")
result = datetime.strptime(date_as_string, '%Y%m%d%H%M%SZ')
return result


@staticmethod
@check_arguments
def certificate_is_expired(certificate_file: str) -> bool:
return GeneralUtilities.get_certificate_expiry_date(certificate_file) < datetime.now()
1 change: 1 addition & 0 deletions ScriptCollection/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ lxml
ntplib>=0.4.0
pycdlib>=1.13.0
pylint>=2.15.10
pyOpenSSL>=23.0.0
PyPDF2>=3.0.1
pytest>=7.2.1
qrcode>=7.3.1
Expand Down
1 change: 1 addition & 0 deletions ScriptCollection/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ install_requires =
ntplib>=0.4.0
pycdlib>=1.13.0
pylint>=2.15.10
pyOpenSSL>=23.0.0
PyPDF2>=3.0.1
pytest>=7.2.1
qrcode>=7.3.1
Expand Down

0 comments on commit 1dc78c2

Please sign in to comment.