Home | History | Annotate | Download | only in patches
      1 diff --git a/third_party/tlslite/tlslite/TLSConnection.py b/third_party/tlslite/tlslite/TLSConnection.py
      2 index d2270a9..e6ce187 100644
      3 --- a/third_party/tlslite/tlslite/TLSConnection.py
      4 +++ b/third_party/tlslite/tlslite/TLSConnection.py
      5 @@ -937,7 +937,8 @@ class TLSConnection(TLSRecordLayer):
      6                          certChain=None, privateKey=None, reqCert=False,
      7                          sessionCache=None, settings=None, checker=None,
      8                          reqCAs=None, tlsIntolerant=0,
      9 -                        signedCertTimestamps=None):
     10 +                        signedCertTimestamps=None,
     11 +                        fallbackSCSV=False):
     12          """Perform a handshake in the role of server.
     13  
     14          This function performs an SSL or TLS handshake.  Depending on
     15 @@ -1014,6 +1014,19 @@ class TLSConnection(TLSRecordLayer):
     16          binary 8-bit string) that will be sent as a TLS extension whenever
     17          the client announces support for the extension.
     18  
     19 +        @type tlsIntolerant: int
     20 +        @param tlsIntolerant: if non-zero, the server will simulate TLS
     21 +        version intolerance by returning a fatal, handshake_failure alert.
     22 +        The versions to which it's intolerant vary depending on the value:
     23 +        1: reject all TLS versions.
     24 +        2: reject TLS 1.1 or higher.
     25 +        3: reject TLS 1.2 or higher.
     26 +
     27 +        @type fallbackSCSV: bool
     28 +        @param fallbackSCSV: if true, the server will implement
     29 +        TLS_FALLBACK_SCSV and thus reject connections using less than the
     30 +        server's maximum TLS version that include this cipher suite.
     31 +
     32          @raise socket.error: If a socket error occurs.
     33          @raise tlslite.errors.TLSAbruptCloseError: If the socket is closed
     34          without a preceding alert.
     35 @@ -1022,7 +1023,8 @@ class TLSConnection(TLSRecordLayer):
     36          """
     37          for result in self.handshakeServerAsync(sharedKeyDB, verifierDB,
     38                  certChain, privateKey, reqCert, sessionCache, settings,
     39 -                checker, reqCAs, tlsIntolerant, signedCertTimestamps):
     40 +                checker, reqCAs, tlsIntolerant, signedCertTimestamps,
     41 +                fallbackSCSV):
     42              pass
     43  
     44  
     45 @@ -1030,7 +1032,8 @@ class TLSConnection(TLSRecordLayer):
     46                               certChain=None, privateKey=None, reqCert=False,
     47                               sessionCache=None, settings=None, checker=None,
     48                               reqCAs=None, tlsIntolerant=0,
     49 -                             signedCertTimestamps=None):
     50 +                             signedCertTimestamps=None,
     51 +                             fallbackSCSV=False):
     52          """Start a server handshake operation on the TLS connection.
     53  
     54          This function returns a generator which behaves similarly to
     55 @@ -1049,7 +1052,8 @@ class TLSConnection(TLSRecordLayer):
     56              sessionCache=sessionCache, settings=settings,
     57              reqCAs=reqCAs,
     58              tlsIntolerant=tlsIntolerant,
     59 -            signedCertTimestamps=signedCertTimestamps)
     60 +            signedCertTimestamps=signedCertTimestamps,
     61 +            fallbackSCSV=fallbackSCSV)
     62          for result in self._handshakeWrapperAsync(handshaker, checker):
     63              yield result
     64  
     65 @@ -1057,7 +1061,8 @@ class TLSConnection(TLSRecordLayer):
     66      def _handshakeServerAsyncHelper(self, sharedKeyDB, verifierDB,
     67                                      certChain, privateKey, reqCert,
     68                                      sessionCache, settings, reqCAs,
     69 -                                    tlsIntolerant, signedCertTimestamps):
     70 +                                    tlsIntolerant, signedCertTimestamps,
     71 +                                    fallbackSCSV):
     72  
     73          self._handshakeStart(client=False)
     74  
     75 @@ -1141,12 +1146,18 @@ class TLSConnection(TLSRecordLayer):
     76                  yield result
     77  
     78          #If client's version is too high, propose my highest version
     79 -        elif clientHello.client_version > settings.maxVersion:
     80 +        if clientHello.client_version > settings.maxVersion:
     81              self.version = settings.maxVersion
     82 -
     83          else:
     84              #Set the version to the client's version
     85              self.version = clientHello.client_version
     86 +            if (fallbackSCSV and
     87 +                clientHello.client_version < settings.maxVersion):
     88 +                for cipherSuite in clientHello.cipher_suites:
     89 +                    if cipherSuite == 0x5600:
     90 +                        for result in self._sendError(\
     91 +                                AlertDescription.inappropriate_fallback):
     92 +                            yield result
     93  
     94          #Get the client nonce; create server nonce
     95          clientRandom = clientHello.random
     96 diff --git a/third_party/tlslite/tlslite/constants.py b/third_party/tlslite/tlslite/constants.py
     97 index b5a345a..23e3dcb 100644
     98 --- a/third_party/tlslite/tlslite/constants.py
     99 +++ b/third_party/tlslite/tlslite/constants.py
    100 @@ -91,6 +91,7 @@ class AlertDescription:
    101      protocol_version = 70
    102      insufficient_security = 71
    103      internal_error = 80
    104 +    inappropriate_fallback = 86
    105      user_canceled = 90
    106      no_renegotiation = 100
    107      unknown_srp_username = 120
    108 diff --git a/third_party/tlslite/tlslite/errors.py b/third_party/tlslite/tlslite/errors.py
    109 index c7f7ba8..45087e6 100644
    110 --- a/third_party/tlslite/tlslite/errors.py
    111 +++ b/third_party/tlslite/tlslite/errors.py
    112 @@ -48,6 +48,7 @@ class TLSAlert(TLSError):
    113          AlertDescription.protocol_version: "protocol_version",\
    114          AlertDescription.insufficient_security: "insufficient_security",\
    115          AlertDescription.internal_error: "internal_error",\
    116 +        AlertDescription.inappropriate_fallback: "inappropriate_fallback",\
    117          AlertDescription.user_canceled: "user_canceled",\
    118          AlertDescription.no_renegotiation: "no_renegotiation",\
    119          AlertDescription.unknown_srp_username: "unknown_srp_username",\
    120