Skip to content
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

meta_x509: avoid bad time values and catch error string exception #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 17 additions & 9 deletions laikaboss/modules/meta_x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ def _run(self, scanObject, result, depth, args):
scanObject.addMetadata(self.module_name, "issuer", issuer)

#validity dates
scanObject.addMetadata(self.module_name, "not_before", str(cert.get_not_before()))
scanObject.addMetadata(self.module_name, "not_after", str(cert.get_not_after()))
not_before = str(cert.get_not_before())
scanObject.addMetadata(self.module_name, "not_before", not_before)
not_after = str(cert.get_not_after())
scanObject.addMetadata(self.module_name, "not_after", not_after)


#string complete subject and issuers
Expand All @@ -86,10 +88,14 @@ def _run(self, scanObject, result, depth, args):
if str(cert.get_issuer()) == str(cert.get_subject()):
scanObject.addFlag("x509:nfo:self_signed_cert")

start = datetime.datetime.strptime(str(cert.get_not_before()), "%b %d %H:%M:%S %Y %Z")
end = datetime.datetime.strptime(str(cert.get_not_after()), "%b %d %H:%M:%S %Y %Z")
dur = end - start
scanObject.addMetadata(self.module_name, "duration", dur.days)
if not_before != 'Bad time value' and not_after != 'Bad time value':
try:
start = datetime.datetime.strptime(not_before, "%b %d %H:%M:%S %Y %Z")
end = datetime.datetime.strptime(not_after, "%b %d %H:%M:%S %Y %Z")
dur = end - start
scanObject.addMetadata(self.module_name, "duration", dur.days)
except ValueError:
pass

extensions = {}
for i in range(cert.get_ext_count()):
Expand All @@ -105,9 +111,11 @@ def _run(self, scanObject, result, depth, args):
logging.exception("Error parsing cert in "+str(get_scanObjectUID(getRootObject(result))))

ugly_error_string = str(exc_value)
nicer_error_string = string.split(string.split(ugly_error_string,":")[4])[0]

scanObject.addFlag("x509:err:"+nicer_error_string)
try:
nicer_error_string = string.split(string.split(ugly_error_string,":")[4])[0]
scanObject.addFlag("x509:err:"+nicer_error_string)
except IndexError:
scanObject.addFlag("x509:err:unknown")



Expand Down