Skip to content

Commit

Permalink
Version 0.50. See CHANGELOG.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Git committed Oct 15, 2023
1 parent 281068a commit 59ed0cd
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 2023/10/14
## Version 0.50
### Fixes
* Fixing bug introduced with version's 0.49 and 0.48

# 2023/09/15
## Version 0.49
### Enhancements
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Certificate Checker

Version: 0.49
Version: 0.50

Author: TheScriptGuy

Expand Down Expand Up @@ -30,7 +30,7 @@ usage: certCheck.py [-h] [--hostname HOSTNAME] [--displayCertificate] [--display
[--sendEmail] [--retryAmount RETRYAMOUNT] [--timeBetweenRetries TIMEBETWEENRETRIES] [--contextVariables] [--environmentVariables] [--setTag SETTAG] [--delTag] [--getTag] [--renewDeviceId]
[--getDeviceId] [--deleteDeviceId] [--setTenantId SETTENANTID] [--getTenantId] [--delTenantId] [--createBlankConfiguration]

Certificate Checker v0.49
Certificate Checker v0.50

optional arguments:
-h, --help show this help message and exit
Expand Down
6 changes: 3 additions & 3 deletions certCheck.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Program: Certificate Checker
# Author: Nolan Rumble
# Date: 2023/09/15
# Version: 0.49
# Date: 2023/10/14
# Version: 0.50

import argparse
import datetime
Expand All @@ -18,7 +18,7 @@
from data import sendDataEmail
from mongo import mongo_connection

scriptVersion = "0.49"
scriptVersion = "0.50"

# Global Variables
args = None
Expand Down
160 changes: 160 additions & 0 deletions certificate/certificateModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,166 @@ def getCertificate(self, __hostinfo: dict) -> dict:

return __hostnameData

@staticmethod
def printSubject(__certificateObject: dict) -> None:
"""Print the subject name of the certificate."""
if __certificateObject is not None:
subject = dict(x[0] for x in __certificateObject['subject'])
issued_to = subject['commonName']
print("Subject: ", issued_to, end='')

@staticmethod
def printSubjectAltName(__certificateObject) -> None:
"""Print the Subject Alternate Name(s) of the certificate."""
__subjectAltName = []

for field, value in __certificateObject['subjectAltName']:
__subjectAltName.append({field: value})

print("Subject Alt Name: ", __subjectAltName)

@staticmethod
def printIssuer(__certificateObject) -> None:
"""Print the Issuer of the certificate."""
if __certificateObject is not None:
issuer = dict(x[0] for x in __certificateObject['issuer'])
issued_by = issuer['commonName']
print("Issued by: ", issued_by)

@staticmethod
def printNotBefore(__certificateObject) -> None:
"""Print the notBefore field of the certificate."""
if __certificateObject is not None:
notBefore = __certificateObject['notBefore']
print("Certificate start date: ", notBefore)

@staticmethod
def printNotAfter(__certificateObject) -> None:
"""Print the notAfter field of the certificate."""
if __certificateObject is not None:
notAfter = __certificateObject['notAfter']
print("Certificate end date: ", notAfter)

@staticmethod
def returnNotBefore(__certificateObject) -> None:
"""Return the notBefore field from the certificate."""
if __certificateObject is not None:
return __certificateObject['notBefore']
return ""
@staticmethod
def checkIssuer(__certificateObject) -> bool:
"""Check to see if issuers are trusted."""
return True

@staticmethod
def checkRevocation(__certificateObject) -> bool:
"""Check to see if certificate hasn't been revoked."""
return True

def checkTimeValidity(self, __certificateObject) -> bool:
"""
Check to see if the certificate is valid:
current date is after certificate start date
current date is before certificate expiry date
"""
if __certificateObject is not None:
timeNow = datetime.datetime.utcnow().replace(microsecond=0).date()
certNotAfter = datetime.datetime.strptime(
self.returnNotAfter(__certificateObject),
self.certTimeFormat
).date()

certNotBefore = datetime.datetime.strptime(
self.returnNotBefore(__certificateObject),
self.certTimeFormat
).date()

# Assume time not valid
isValid = bool(certNotBefore < timeNow < certNotAfter)

return isValid
return False

@staticmethod
def printOCSP(__certificateObject) -> None:
"""Print the OCSP field of the certificate."""
if __certificateObject is not None:
__OCSPList = []
for value in __certificateObject['OCSP']:
__OCSPList.append(value)
print("OCSP: ", __OCSPList)

@staticmethod
def printCRLDistributionPoints(__certificateObject) -> None:
"""Print the CRL distribution points of the certificate."""
if __certificateObject is not None:
__CRLList = []
if 'crlDistributionPoints' in __certificateObject:
for value in __certificateObject['crlDistributionPoints']:
__CRLList.append(value)
print("CRL: ", __CRLList)

@staticmethod
def printCertificateSerialNumber(__certificateObject) -> None:
"""Print the certificate serial number."""
if __certificateObject is not None:
certificateSerialNumber = __certificateObject['serialNumber']
print("Serial Number: ", certificateSerialNumber)

@staticmethod
def printCaIssuers(__certificateObject) -> None:
"""Print the certificates CA issuers."""
if __certificateObject is not None:
certificateCaIssuers = __certificateObject['caIssuers']
print("CA Issuers: ", certificateCaIssuers)

def printHowMuchTimeLeft(self, __certificateObject) -> None:
"""Print how much time is left on the certificate."""
if __certificateObject is not None:
timeLeft = self.howMuchTimeLeft(__certificateObject)
print("Time left: ", timeLeft)

def printCertInfo(self, __certificateObject) -> None:
"""Print out all the certificate properties."""
if __certificateObject is not None:
self.printSubject(__certificateObject)
print()
self.printIssuer(__certificateObject)
self.printSubjectAltName(__certificateObject)
self.printNotBefore(__certificateObject)
self.printNotAfter(__certificateObject)
self.printOCSP(__certificateObject)
self.printCRLDistributionPoints(__certificateObject)
self.printCaIssuers(__certificateObject)
self.printCertificateSerialNumber(__certificateObject)
self.printHowMuchTimeLeft(__certificateObject)
else:
print("No certificate info to display!")

@staticmethod
def printCertInfoJSON(__certificateObject) -> None:
"""Print the certificate information in JSON format."""
if __certificateObject is not None:
jsonCertInfoFormat = json.dumps(__certificateObject)
print(jsonCertInfoFormat)
else:
jsonCertInfoFormat = {
"subject": {"None": "None"},
"certificateIssuer": {"None": "None"},
"version": 0,
"serialNumber": "0",
"notBefore": "Jan 1 00:00:00 0000 GMT",
"notAfter": "Jan 1 00:00:00 0000 GMT",
"timeLeft": "0 seconds",
"OCSP": "None",
"crlDistributionPoints": "None",
"caIssuers": "None",
"subjectAltName": {"None": "None"}
}
print(jsonCertInfoFormat)



@staticmethod
def returnNotAfter(__certificateObject) -> None:
"""Return the notAfter field from the certificate."""
Expand Down

0 comments on commit 59ed0cd

Please sign in to comment.