Skip to content

Commit

Permalink
Merge 934a8e6 into 807a3db
Browse files Browse the repository at this point in the history
  • Loading branch information
inikolcev committed Feb 6, 2020
2 parents 807a3db + 934a8e6 commit 82ec607
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion tlslite/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,10 @@ def _parse_tls12(self, p):
while index != chainLength:
certBytes = p.getVarBytes(3)
x509 = X509()
x509.parseBinary(certBytes)
try:
x509.parseBinary(certBytes)
except SyntaxError:
raise BadCertificateError("Certificate could not be parsed")
certificate_list.append(x509)
index += len(certBytes)+3
if certificate_list:
Expand Down
8 changes: 6 additions & 2 deletions tlslite/tlsrecordlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from .utils.compat import *
from .utils.cryptomath import *
from .utils.codec import Parser
from .utils.codec import Parser, BadCertificateError
from .utils.lists import to_str_delimiter, getFirstMatching
from .errors import *
from .messages import *
Expand Down Expand Up @@ -1201,9 +1201,13 @@ def _getMsg(self, expectedType, secondaryType=None, constructorType=None):
raise AssertionError()

#If an exception was raised by a Parser or Message instance:
except BadCertificateError as e:
for result in self._sendError(AlertDescription.bad_certificate,
formatExceptionTrace(e)):
yield result
except SyntaxError as e:
for result in self._sendError(AlertDescription.decode_error,
formatExceptionTrace(e)):
formatExceptionTrace(e)):
yield result

#Returns next record or next handshake message
Expand Down
5 changes: 5 additions & 0 deletions tlslite/utils/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class DecodeError(SyntaxError):
pass


class BadCertificateError(SyntaxError):
"""Exception raised in case of bad certificate."""
pass


class Writer(object):
"""Serialisation helper for complex byte-based structures."""

Expand Down

0 comments on commit 82ec607

Please sign in to comment.