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

Side by Side Diff: third_party/tlslite/patches/status_request.patch

Issue 92443002: Extract Certificate Transparency SCTs from stapled OCSP responses (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@extract_scts
Patch Set: rebase 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
(Empty)
1 diff --git a/third_party/tlslite/tlslite/TLSConnection.py b/third_party/tlslite/ tlslite/TLSConnection.py
2 index d2270a9..fe2c863 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 + ocspResponse=None):
12 """Perform a handshake in the role of server.
13
14 This function performs an SSL or TLS handshake. Depending on
15 @@ -1013,6 +1014,16 @@ 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 ocspResponse: str
20 + @param ocspResponse: An OCSP response (as a binary 8-bit string) that
21 + will be sent stapled in the handshake whenever the client announces
22 + support for the status_request extension.
23 + Note that the response is sent independent of the ClientHello
24 + status_request extension contents, and is thus only meant for testing
25 + environments. Real OCSP stapling is more complicated as it requires
26 + choosing a suitable response based on the ClientHello status_request
27 + extension contents.
28 +
29 @raise socket.error: If a socket error occurs.
30 @raise tlslite.errors.TLSAbruptCloseError: If the socket is closed
31 without a preceding alert.
32 @@ -1022,7 +1033,8 @@ class TLSConnection(TLSRecordLayer):
33 """
34 for result in self.handshakeServerAsync(sharedKeyDB, verifierDB,
35 certChain, privateKey, reqCert, sessionCache, settings,
36 - checker, reqCAs, tlsIntolerant, signedCertTimestamps):
37 + checker, reqCAs, tlsIntolerant, signedCertTimestamps,
38 + ocspResponse):
39 pass
40
41
42 @@ -1030,7 +1042,8 @@ class TLSConnection(TLSRecordLayer):
43 certChain=None, privateKey=None, reqCert=False,
44 sessionCache=None, settings=None, checker=None,
45 reqCAs=None, tlsIntolerant=0,
46 - signedCertTimestamps=None):
47 + signedCertTimestamps=None,
48 + ocspResponse=None):
49 """Start a server handshake operation on the TLS connection.
50
51 This function returns a generator which behaves similarly to
52 @@ -1049,7 +1062,8 @@ class TLSConnection(TLSRecordLayer):
53 sessionCache=sessionCache, settings=settings,
54 reqCAs=reqCAs,
55 tlsIntolerant=tlsIntolerant,
56 - signedCertTimestamps=signedCertTimestamps)
57 + signedCertTimestamps=signedCertTimestamps,
58 + ocspResponse=ocspResponse)
59 for result in self._handshakeWrapperAsync(handshaker, checker):
60 yield result
61
62 @@ -1057,7 +1071,8 @@ class TLSConnection(TLSRecordLayer):
63 def _handshakeServerAsyncHelper(self, sharedKeyDB, verifierDB,
64 certChain, privateKey, reqCert,
65 sessionCache, settings, reqCAs,
66 - tlsIntolerant, signedCertTimestamps):
67 + tlsIntolerant, signedCertTimestamps,
68 + ocspResponse):
69
70 self._handshakeStart(client=False)
71
72 @@ -1428,10 +1443,14 @@ class TLSConnection(TLSRecordLayer):
73 sessionID, cipherSuite, certificateType)
74 serverHello.channel_id = clientHello.channel_id
75 if clientHello.support_signed_cert_timestamps:
76 - serverHello.signed_cert_timestamps = signedCertTimestamps
77 + serverHello.signed_cert_timestamps = signedCertTimestamps
78 + serverHello.status_request = (clientHello.status_request and
79 + ocspResponse)
80 doingChannelID = clientHello.channel_id
81 msgs.append(serverHello)
82 msgs.append(Certificate(certificateType).create(serverCertChain))
83 + if serverHello.status_request:
84 + msgs.append(CertificateStatus().create(ocspResponse))
85 if reqCert and reqCAs:
86 msgs.append(CertificateRequest().create([], reqCAs))
87 elif reqCert:
88 diff --git a/third_party/tlslite/tlslite/constants.py b/third_party/tlslite/tlsl ite/constants.py
89 index b5a345a..cef56a0 100644
90 --- a/third_party/tlslite/tlslite/constants.py
91 +++ b/third_party/tlslite/tlslite/constants.py
92 @@ -22,6 +22,7 @@ class HandshakeType:
93 certificate_verify = 15
94 client_key_exchange = 16
95 finished = 20
96 + certificate_status = 22
97 encrypted_extensions = 203
98
99 class ContentType:
100 @@ -31,7 +32,11 @@ class ContentType:
101 application_data = 23
102 all = (20,21,22,23)
103
104 +class CertificateStatusType:
105 + ocsp = 1
106 +
107 class ExtensionType:
108 + status_request = 5 # OCSP stapling
109 signed_cert_timestamps = 18 # signed_certificate_timestamp in RFC 6962
110 channel_id = 30031
111
112 diff --git a/third_party/tlslite/tlslite/messages.py b/third_party/tlslite/tlsli te/messages.py
113 index 296f422..497ef60 100644
114 --- a/third_party/tlslite/tlslite/messages.py
115 +++ b/third_party/tlslite/tlslite/messages.py
116 @@ -132,6 +132,7 @@ class ClientHello(HandshakeMsg):
117 self.srp_username = None # a string
118 self.channel_id = False
119 self.support_signed_cert_timestamps = False
120 + self.status_request = False
121
122 def create(self, version, random, session_id, cipher_suites,
123 certificate_types=None, srp_username=None):
124 @@ -182,6 +183,19 @@ class ClientHello(HandshakeMsg):
125 if extLength:
126 raise SyntaxError()
127 self.support_signed_cert_timestamps = True
128 + elif extType == ExtensionType.status_request:
129 + # Extension contents are currently ignored.
130 + # According to RFC 6066, this is not strictly forbidden
131 + # (although it is suboptimal):
132 + # Servers that receive a client hello containing the
133 + # "status_request" extension MAY return a suitable
134 + # certificate status response to the client along with
135 + # their certificate. If OCSP is requested, they
136 + # SHOULD use the information contained in the extension
137 + # when selecting an OCSP responder and SHOULD include
138 + # request_extensions in the OCSP request.
139 + p.getFixBytes(extLength)
140 + self.status_request = True
141 else:
142 p.getFixBytes(extLength)
143 soFar += 4 + extLength
144 @@ -230,6 +244,7 @@ class ServerHello(HandshakeMsg):
145 self.compression_method = 0
146 self.channel_id = False
147 self.signed_cert_timestamps = None
148 + self.status_request = False
149
150 def create(self, version, random, session_id, cipher_suite,
151 certificate_type):
152 @@ -282,6 +297,9 @@ class ServerHello(HandshakeMsg):
153 if self.signed_cert_timestamps:
154 extLength += 4 + len(self.signed_cert_timestamps)
155
156 + if self.status_request:
157 + extLength += 4
158 +
159 if extLength != 0:
160 w.add(extLength, 2)
161
162 @@ -299,6 +317,10 @@ class ServerHello(HandshakeMsg):
163 w.add(ExtensionType.signed_cert_timestamps, 2)
164 w.addVarSeq(stringToBytes(self.signed_cert_timestamps), 1, 2)
165
166 + if self.status_request:
167 + w.add(ExtensionType.status_request, 2)
168 + w.add(0, 2)
169 +
170 return HandshakeMsg.postWrite(self, w, trial)
171
172 class Certificate(HandshakeMsg):
173 @@ -367,6 +389,37 @@ class Certificate(HandshakeMsg):
174 raise AssertionError()
175 return HandshakeMsg.postWrite(self, w, trial)
176
177 +class CertificateStatus(HandshakeMsg):
178 + def __init__(self):
179 + self.contentType = ContentType.handshake
180 +
181 + def create(self, ocsp_response):
182 + self.ocsp_response = ocsp_response
183 + return self
184 +
185 + # Defined for the sake of completeness, even though we currently only
186 + # support sending the status message (server-side), not requesting
187 + # or receiving it (client-side).
188 + def parse(self, p):
189 + p.startLengthCheck(3)
190 + status_type = p.get(1)
191 + # Only one type is specified, so hardwire it.
192 + if status_type != CertificateStatusType.ocsp:
193 + raise SyntaxError()
194 + ocsp_response = p.getVarBytes(3)
195 + if not ocsp_response:
196 + # Can't be empty
197 + raise SyntaxError()
198 + self.ocsp_response = ocsp_response
199 + return self
200 +
201 + def write(self, trial=False):
202 + w = HandshakeMsg.preWrite(self, HandshakeType.certificate_status,
203 + trial)
204 + w.add(CertificateStatusType.ocsp, 1)
205 + w.addVarSeq(stringToBytes(self.ocsp_response), 1, 3)
206 + return HandshakeMsg.postWrite(self, w, trial)
207 +
208 class CertificateRequest(HandshakeMsg):
209 def __init__(self):
210 self.contentType = ContentType.handshake
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698