Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: third_party/tlslite/tlslite/TLSConnection.py

Issue 92443002: Extract Certificate Transparency SCTs from stapled OCSP responses (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@extract_scts
Patch Set: Fix C++11 compile error Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 """ 1 """
2 MAIN CLASS FOR TLS LITE (START HERE!). 2 MAIN CLASS FOR TLS LITE (START HERE!).
3 """ 3 """
4 from __future__ import generators 4 from __future__ import generators
5 5
6 import socket 6 import socket
7 from utils.compat import formatExceptionTrace 7 from utils.compat import formatExceptionTrace
8 from TLSRecordLayer import TLSRecordLayer 8 from TLSRecordLayer import TLSRecordLayer
9 from Session import Session 9 from Session import Session
10 from constants import * 10 from constants import *
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 #Mark the connection as open 930 #Mark the connection as open
931 self.session._setResumable(True) 931 self.session._setResumable(True)
932 self._handshakeDone(resumed=False) 932 self._handshakeDone(resumed=False)
933 933
934 934
935 935
936 def handshakeServer(self, sharedKeyDB=None, verifierDB=None, 936 def handshakeServer(self, sharedKeyDB=None, verifierDB=None,
937 certChain=None, privateKey=None, reqCert=False, 937 certChain=None, privateKey=None, reqCert=False,
938 sessionCache=None, settings=None, checker=None, 938 sessionCache=None, settings=None, checker=None,
939 reqCAs=None, tlsIntolerant=0, 939 reqCAs=None, tlsIntolerant=0,
940 signedCertTimestamps=None, 940 signedCertTimestamps=None, fallbackSCSV=False,
941 fallbackSCSV=False): 941 ocspResponse=None):
942 """Perform a handshake in the role of server. 942 """Perform a handshake in the role of server.
943 943
944 This function performs an SSL or TLS handshake. Depending on 944 This function performs an SSL or TLS handshake. Depending on
945 the arguments and the behavior of the client, this function can 945 the arguments and the behavior of the client, this function can
946 perform a shared-key, SRP, or certificate-based handshake. It 946 perform a shared-key, SRP, or certificate-based handshake. It
947 can also perform a combined SRP and server-certificate 947 can also perform a combined SRP and server-certificate
948 handshake. 948 handshake.
949 949
950 Like any handshake function, this can be called on a closed 950 Like any handshake function, this can be called on a closed
951 TLS connection, or on a TLS connection that is already open. 951 TLS connection, or on a TLS connection that is already open.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 @type reqCAs: list of L{array.array} of unsigned bytes 1007 @type reqCAs: list of L{array.array} of unsigned bytes
1008 @param reqCAs: A collection of DER-encoded DistinguishedNames that 1008 @param reqCAs: A collection of DER-encoded DistinguishedNames that
1009 will be sent along with a certificate request. This does not affect 1009 will be sent along with a certificate request. This does not affect
1010 verification. 1010 verification.
1011 1011
1012 @type signedCertTimestamps: str 1012 @type signedCertTimestamps: str
1013 @param signedCertTimestamps: A SignedCertificateTimestampList (as a 1013 @param signedCertTimestamps: A SignedCertificateTimestampList (as a
1014 binary 8-bit string) that will be sent as a TLS extension whenever 1014 binary 8-bit string) that will be sent as a TLS extension whenever
1015 the client announces support for the extension. 1015 the client announces support for the extension.
1016 1016
1017 @type ocspResponse: str
1018 @param ocspResponse: An OCSP response (as a binary 8-bit string) that
1019 will be sent stapled in the handshake whenever the client announces
1020 support for the status_request extension.
1021 Note that the response is sent independent of the ClientHello
1022 status_request extension contents, and is thus only meant for testing
1023 environments. Real OCSP stapling is more complicated as it requires
1024 choosing a suitable response based on the ClientHello status_request
1025 extension contents.
1026
1017 @raise socket.error: If a socket error occurs. 1027 @raise socket.error: If a socket error occurs.
1018 @raise tlslite.errors.TLSAbruptCloseError: If the socket is closed 1028 @raise tlslite.errors.TLSAbruptCloseError: If the socket is closed
1019 without a preceding alert. 1029 without a preceding alert.
1020 @raise tlslite.errors.TLSAlert: If a TLS alert is signalled. 1030 @raise tlslite.errors.TLSAlert: If a TLS alert is signalled.
1021 @raise tlslite.errors.TLSAuthenticationError: If the checker 1031 @raise tlslite.errors.TLSAuthenticationError: If the checker
1022 doesn't like the other party's authentication credentials. 1032 doesn't like the other party's authentication credentials.
1023 """ 1033 """
1024 for result in self.handshakeServerAsync(sharedKeyDB, verifierDB, 1034 for result in self.handshakeServerAsync(sharedKeyDB, verifierDB,
1025 certChain, privateKey, reqCert, sessionCache, settings, 1035 certChain, privateKey, reqCert, sessionCache, settings,
1026 checker, reqCAs, tlsIntolerant, signedCertTimestamps, 1036 checker, reqCAs, tlsIntolerant, signedCertTimestamps,
1027 fallbackSCSV): 1037 fallbackSCSV, ocspResponse):
1028 pass 1038 pass
1029 1039
1030 1040
1031 def handshakeServerAsync(self, sharedKeyDB=None, verifierDB=None, 1041 def handshakeServerAsync(self, sharedKeyDB=None, verifierDB=None,
1032 certChain=None, privateKey=None, reqCert=False, 1042 certChain=None, privateKey=None, reqCert=False,
1033 sessionCache=None, settings=None, checker=None, 1043 sessionCache=None, settings=None, checker=None,
1034 reqCAs=None, tlsIntolerant=0, 1044 reqCAs=None, tlsIntolerant=0,
1035 signedCertTimestamps=None, 1045 signedCertTimestamps=None,
1036 fallbackSCSV=False): 1046 fallbackSCSV=False, ocspResponse=None):
1037 """Start a server handshake operation on the TLS connection. 1047 """Start a server handshake operation on the TLS connection.
1038 1048
1039 This function returns a generator which behaves similarly to 1049 This function returns a generator which behaves similarly to
1040 handshakeServer(). Successive invocations of the generator 1050 handshakeServer(). Successive invocations of the generator
1041 will return 0 if it is waiting to read from the socket, 1 if it is 1051 will return 0 if it is waiting to read from the socket, 1 if it is
1042 waiting to write to the socket, or it will raise StopIteration 1052 waiting to write to the socket, or it will raise StopIteration
1043 if the handshake operation is complete. 1053 if the handshake operation is complete.
1044 1054
1045 @rtype: iterable 1055 @rtype: iterable
1046 @return: A generator; see above for details. 1056 @return: A generator; see above for details.
1047 """ 1057 """
1048 handshaker = self._handshakeServerAsyncHelper(\ 1058 handshaker = self._handshakeServerAsyncHelper(\
1049 sharedKeyDB=sharedKeyDB, 1059 sharedKeyDB=sharedKeyDB,
1050 verifierDB=verifierDB, certChain=certChain, 1060 verifierDB=verifierDB, certChain=certChain,
1051 privateKey=privateKey, reqCert=reqCert, 1061 privateKey=privateKey, reqCert=reqCert,
1052 sessionCache=sessionCache, settings=settings, 1062 sessionCache=sessionCache, settings=settings,
1053 reqCAs=reqCAs, 1063 reqCAs=reqCAs,
1054 tlsIntolerant=tlsIntolerant, 1064 tlsIntolerant=tlsIntolerant,
1055 signedCertTimestamps=signedCertTimestamps, 1065 signedCertTimestamps=signedCertTimestamps,
1056 fallbackSCSV=fallbackSCSV) 1066 fallbackSCSV=fallbackSCSV, ocspResponse=ocspResponse)
1067
1057 for result in self._handshakeWrapperAsync(handshaker, checker): 1068 for result in self._handshakeWrapperAsync(handshaker, checker):
1058 yield result 1069 yield result
1059 1070
1060 1071
1061 def _handshakeServerAsyncHelper(self, sharedKeyDB, verifierDB, 1072 def _handshakeServerAsyncHelper(self, sharedKeyDB, verifierDB,
1062 certChain, privateKey, reqCert, 1073 certChain, privateKey, reqCert,
1063 sessionCache, settings, reqCAs, 1074 sessionCache, settings, reqCAs,
1064 tlsIntolerant, signedCertTimestamps, 1075 tlsIntolerant, signedCertTimestamps,
1065 fallbackSCSV): 1076 fallbackSCSV, ocspResponse):
1066 1077
1067 self._handshakeStart(client=False) 1078 self._handshakeStart(client=False)
1068 1079
1069 if (not sharedKeyDB) and (not verifierDB) and (not certChain): 1080 if (not sharedKeyDB) and (not verifierDB) and (not certChain):
1070 raise ValueError("Caller passed no authentication credentials") 1081 raise ValueError("Caller passed no authentication credentials")
1071 if certChain and not privateKey: 1082 if certChain and not privateKey:
1072 raise ValueError("Caller passed a certChain but no privateKey") 1083 raise ValueError("Caller passed a certChain but no privateKey")
1073 if privateKey and not certChain: 1084 if privateKey and not certChain:
1074 raise ValueError("Caller passed a privateKey but no certChain") 1085 raise ValueError("Caller passed a privateKey but no certChain")
1075 if reqCAs and not reqCert: 1086 if reqCAs and not reqCert:
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 elif cipherSuite in CipherSuite.rsaSuites: 1443 elif cipherSuite in CipherSuite.rsaSuites:
1433 1444
1434 #Send ServerHello, Certificate[, CertificateRequest], 1445 #Send ServerHello, Certificate[, CertificateRequest],
1435 #ServerHelloDone 1446 #ServerHelloDone
1436 msgs = [] 1447 msgs = []
1437 serverHello = ServerHello().create( 1448 serverHello = ServerHello().create(
1438 self.version, serverRandom, 1449 self.version, serverRandom,
1439 sessionID, cipherSuite, certificateType) 1450 sessionID, cipherSuite, certificateType)
1440 serverHello.channel_id = clientHello.channel_id 1451 serverHello.channel_id = clientHello.channel_id
1441 if clientHello.support_signed_cert_timestamps: 1452 if clientHello.support_signed_cert_timestamps:
1442 serverHello.signed_cert_timestamps = signedCertTimestamps 1453 serverHello.signed_cert_timestamps = signedCertTimestamps
1454 serverHello.status_request = (clientHello.status_request and
1455 ocspResponse)
1443 doingChannelID = clientHello.channel_id 1456 doingChannelID = clientHello.channel_id
1444 msgs.append(serverHello) 1457 msgs.append(serverHello)
1445 msgs.append(Certificate(certificateType).create(serverCertChain)) 1458 msgs.append(Certificate(certificateType).create(serverCertChain))
1459 if serverHello.status_request:
1460 msgs.append(CertificateStatus().create(ocspResponse))
1446 if reqCert and reqCAs: 1461 if reqCert and reqCAs:
1447 msgs.append(CertificateRequest().create([], reqCAs)) 1462 msgs.append(CertificateRequest().create([], reqCAs))
1448 elif reqCert: 1463 elif reqCert:
1449 msgs.append(CertificateRequest()) 1464 msgs.append(CertificateRequest())
1450 msgs.append(ServerHelloDone()) 1465 msgs.append(ServerHelloDone())
1451 for result in self._sendMsgs(msgs): 1466 for result in self._sendMsgs(msgs):
1452 yield result 1467 yield result
1453 1468
1454 #From here on, the client's messages must have the right version 1469 #From here on, the client's messages must have the right version
1455 self._versionCheck = True 1470 self._versionCheck = True
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 if len(publicKey) < settings.minKeySize: 1676 if len(publicKey) < settings.minKeySize:
1662 for result in self._sendError(AlertDescription.handshake_failure, 1677 for result in self._sendError(AlertDescription.handshake_failure,
1663 "Other party's public key too small: %d" % len(publicKey)): 1678 "Other party's public key too small: %d" % len(publicKey)):
1664 yield result 1679 yield result
1665 if len(publicKey) > settings.maxKeySize: 1680 if len(publicKey) > settings.maxKeySize:
1666 for result in self._sendError(AlertDescription.handshake_failure, 1681 for result in self._sendError(AlertDescription.handshake_failure,
1667 "Other party's public key too large: %d" % len(publicKey)): 1682 "Other party's public key too large: %d" % len(publicKey)):
1668 yield result 1683 yield result
1669 1684
1670 yield publicKey, certChain 1685 yield publicKey, certChain
OLDNEW
« no previous file with comments | « third_party/tlslite/patches/status_request.patch ('k') | third_party/tlslite/tlslite/constants.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698