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

Side by Side Diff: net/third_party/nss/patches/signedcertificatetimestamps.patch

Issue 64553002: Certificate Transparency TLS extension patch for NSS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 1 month 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/net/third_party/nss/ssl/ssl.h b/net/third_party/nss/ssl/ssl.h
2 index 47468a0..dac483a 100644
3 --- a/net/third_party/nss/ssl/ssl.h
4 +++ b/net/third_party/nss/ssl/ssl.h
5 @@ -166,6 +166,8 @@ SSL_IMPORT PRFileDesc *DTLS_ImportFD(PRFileDesc *model, PRFi leDesc *fd);
6 */
7 #define SSL_CBC_RANDOM_IV 23
8 #define SSL_ENABLE_OCSP_STAPLING 24 /* Request OCSP stapling (client) */
9 +/* Request Signed Certificate Timestamps via TLS extension (client) */
10 +#define SSL_ENABLE_SIGNED_CERT_TIMESTAMPS 25
11
12 #ifdef SSL_DEPRECATED_FUNCTION
13 /* Old deprecated function names */
14 @@ -469,6 +471,21 @@ SSL_IMPORT CERTCertList *SSL_PeerCertificateChain(PRFileDes c *fd);
15 */
16 SSL_IMPORT const SECItemArray * SSL_PeerStapledOCSPResponses(PRFileDesc *fd);
17
18 +/* SSL_PeerSignedCertTimestamps returns the signed_certificate_timestamp
19 + * extension data provided by the TLS server. The return value is a pointer
20 + * to an internal SECItem that contains the returned response; it is only valid
21 + * until the callback function that calls SSL_PeerSignedCertTimestamps returns.
22 + *
23 + * If no Signed Certificate Timestamps were given by the server then the result
24 + * will be empty. If there was an error, then the result will be NULL.
25 + *
26 + * You must set the SSL_ENABLE_SIGNED_CERT_TIMESTAMPS option to enable Signed
27 + * Certificate Timestamps to be provided by a server.
28 + *
29 + * libssl does not do any parsing or validation of the response itself.
30 + */
31 +SSL_IMPORT const SECItem * SSL_PeerSignedCertTimestamps(PRFileDesc *fd);
32 +
33 /* SSL_SetStapledOCSPResponses stores an array of one or multiple OCSP response s
34 * in the fd's data, which may be sent as part of a server side cert_status
35 * handshake message. Parameter |responses| is for the server certificate of
36 diff --git a/net/third_party/nss/ssl/ssl3con.c b/net/third_party/nss/ssl/ssl3con .c
37 index 7b93a63..ceb31bc 100644
38 --- a/net/third_party/nss/ssl/ssl3con.c
39 +++ b/net/third_party/nss/ssl/ssl3con.c
40 @@ -6612,6 +6612,18 @@ ssl3_HandleServerHello(sslSocket *ss, SSL3Opaque *b, PRUi nt32 length)
41 sid->u.ssl3.sessionIDLength = sidBytes.len;
42 PORT_Memcpy(sid->u.ssl3.sessionID, sidBytes.data, sidBytes.len);
43
44 + /* Copy Signed Certificate Timestamps, if any. */
45 + if (ss->xtnData.signedCertTimestamps.data) {
46 + rv = SECITEM_CopyItem(NULL, &sid->u.ssl3.signedCertTimestamps,
47 + &ss->xtnData.signedCertTimestamps);
48 + if (rv != SECSuccess)
49 + goto loser;
50 + }
51 +
52 + /* Clean up the temporary pointer to the handshake buffer. */
53 + ss->xtnData.signedCertTimestamps.data = NULL;
54 + ss->xtnData.signedCertTimestamps.len = 0;
55 +
56 ss->ssl3.hs.isResuming = PR_FALSE;
57 ss->ssl3.hs.ws = wait_server_cert;
58
59 @@ -6641,6 +6653,9 @@ alert_loser:
60 (void)SSL3_SendAlert(ss, alert_fatal, desc);
61
62 loser:
63 + /* Clean up the temporary pointer to the handshake buffer. */
64 + ss->xtnData.signedCertTimestamps.data = NULL;
65 + ss->xtnData.signedCertTimestamps.len = 0;
66 errCode = ssl_MapLowLevelError(errCode);
67 return SECFailure;
68 }
69 diff --git a/net/third_party/nss/ssl/ssl3ext.c b/net/third_party/nss/ssl/ssl3ext .c
70 index 0415770..4b51451 100644
71 --- a/net/third_party/nss/ssl/ssl3ext.c
72 +++ b/net/third_party/nss/ssl/ssl3ext.c
73 @@ -81,6 +81,12 @@ static PRInt32 ssl3_ClientSendSigAlgsXtn(sslSocket *ss, PRBoo l append,
74 PRUint32 maxBytes);
75 static SECStatus ssl3_ServerHandleSigAlgsXtn(sslSocket *ss, PRUint16 ex_type,
76 SECItem *data);
77 +static PRInt32 ssl3_ClientSendSignedCertTimestampXtn(sslSocket *ss,
78 + PRBool append,
79 + PRUint32 maxBytes);
80 +static SECStatus ssl3_ClientHandleSignedCertTimestampXtn(sslSocket *ss,
81 + PRUint16 ex_type,
82 + SECItem *data);
83
84 /*
85 * Write bytes. Using this function means the SECItem structure
86 @@ -259,6 +265,8 @@ static const ssl3HelloExtensionHandler serverHelloHandlersTL S[] = {
87 { ssl_use_srtp_xtn, &ssl3_HandleUseSRTPXtn },
88 { ssl_channel_id_xtn, &ssl3_ClientHandleChannelIDXtn },
89 { ssl_cert_status_xtn, &ssl3_ClientHandleStatusRequestXtn },
90 + { ssl_signed_certificate_timestamp_xtn,
91 + &ssl3_ClientHandleSignedCertTimestampXtn },
92 { -1, NULL }
93 };
94
95 @@ -287,7 +295,9 @@ ssl3HelloExtensionSender clientHelloSendersTLS[SSL_MAX_EXTEN SIONS] = {
96 { ssl_use_srtp_xtn, &ssl3_SendUseSRTPXtn },
97 { ssl_channel_id_xtn, &ssl3_ClientSendChannelIDXtn },
98 { ssl_cert_status_xtn, &ssl3_ClientSendStatusRequestXtn },
99 - { ssl_signature_algorithms_xtn, &ssl3_ClientSendSigAlgsXtn }
100 + { ssl_signature_algorithms_xtn, &ssl3_ClientSendSigAlgsXtn },
101 + { ssl_signed_certificate_timestamp_xtn,
102 + &ssl3_ClientSendSignedCertTimestampXtn },
103 /* any extra entries will appear as { 0, NULL } */
104 };
105
106 @@ -2297,3 +2307,60 @@ ssl3_ClientSendSigAlgsXtn(sslSocket * ss, PRBool append, PRUint32 maxBytes)
107 loser:
108 return -1;
109 }
110 +
111 +/* ssl3_ClientSendSignedCertTimestampXtn sends the signed_certificate_timestamp
112 + * extension for TLS ClientHellos. */
113 +static PRInt32
114 +ssl3_ClientSendSignedCertTimestampXtn(sslSocket *ss, PRBool append,
115 + PRUint32 maxBytes)
116 +{
117 + /* Only send the extension if processing is enabled. */
118 + if (!ss->opt.enableSignedCertTimestamps)
119 + return 0;
120 +
121 + PRInt32 extension_length = 2 /* extension_type */ +
122 + 2 /* length(extension_data) */;
123 +
124 + if (append && maxBytes >= extension_length) {
125 + SECStatus rv;
126 + /* extension_type */
127 + rv = ssl3_AppendHandshakeNumber(ss,
128 + ssl_signed_certificate_timestamp_xtn,
129 + 2);
130 + if (rv != SECSuccess)
131 + goto loser;
132 + /* zero length */
133 + rv = ssl3_AppendHandshakeNumber(ss, 0, 2);
134 + if (rv != SECSuccess)
135 + goto loser;
136 + ss->xtnData.advertised[ss->xtnData.numAdvertised++] =
137 + ssl_signed_certificate_timestamp_xtn;
138 + } else if (maxBytes < extension_length) {
139 + PORT_Assert(0);
140 + return 0;
141 + }
142 +
143 + return extension_length;
144 +loser:
145 + return -1;
146 +}
147 +
148 +static SECStatus
149 +ssl3_ClientHandleSignedCertTimestampXtn(sslSocket *ss, PRUint16 ex_type,
150 + SECItem *data)
151 +{
152 + /* We do not yet know whether we'll be reusing a session or creating
153 + * a new one, so we keep a pointer to the data in the TLSExtensionData
154 + * structure. This pointer is only valid in the scope of
155 + * ssl3_HandleServerHello, and, if not resuming a session, a copy of the
156 + * data is made once a new session has been set up.
157 + * All parsing is currently left to the application and we accept
158 + * everything, including empty data.
159 + */
160 + SECItem *scts = &ss->xtnData.signedCertTimestamps;
161 + PORT_Assert(!scts->data && !scts->len);
162 + *scts = *data;
163 + /* Keep track of negotiated extensions. */
164 + ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type;
165 + return SECSuccess;
166 +}
167 diff --git a/net/third_party/nss/ssl/sslimpl.h b/net/third_party/nss/ssl/sslimpl .h
168 index 614eed1..c17cc23 100644
169 --- a/net/third_party/nss/ssl/sslimpl.h
170 +++ b/net/third_party/nss/ssl/sslimpl.h
171 @@ -305,29 +305,30 @@ typedef struct sslOptionsStr {
172 * list of supported protocols. */
173 SECItem nextProtoNego;
174
175 - unsigned int useSecurity : 1; /* 1 */
176 - unsigned int useSocks : 1; /* 2 */
177 - unsigned int requestCertificate : 1; /* 3 */
178 - unsigned int requireCertificate : 2; /* 4-5 */
179 - unsigned int handshakeAsClient : 1; /* 6 */
180 - unsigned int handshakeAsServer : 1; /* 7 */
181 - unsigned int enableSSL2 : 1; /* 8 */
182 - unsigned int unusedBit9 : 1; /* 9 */
183 - unsigned int unusedBit10 : 1; /* 10 */
184 - unsigned int noCache : 1; /* 11 */
185 - unsigned int fdx : 1; /* 12 */
186 - unsigned int v2CompatibleHello : 1; /* 13 */
187 - unsigned int detectRollBack : 1; /* 14 */
188 - unsigned int noStepDown : 1; /* 15 */
189 - unsigned int bypassPKCS11 : 1; /* 16 */
190 - unsigned int noLocks : 1; /* 17 */
191 - unsigned int enableSessionTickets : 1; /* 18 */
192 - unsigned int enableDeflate : 1; /* 19 */
193 - unsigned int enableRenegotiation : 2; /* 20-21 */
194 - unsigned int requireSafeNegotiation : 1; /* 22 */
195 - unsigned int enableFalseStart : 1; /* 23 */
196 - unsigned int cbcRandomIV : 1; /* 24 */
197 - unsigned int enableOCSPStapling : 1; /* 25 */
198 + unsigned int useSecurity : 1; /* 1 */
199 + unsigned int useSocks : 1; /* 2 */
200 + unsigned int requestCertificate : 1; /* 3 */
201 + unsigned int requireCertificate : 2; /* 4-5 */
202 + unsigned int handshakeAsClient : 1; /* 6 */
203 + unsigned int handshakeAsServer : 1; /* 7 */
204 + unsigned int enableSSL2 : 1; /* 8 */
205 + unsigned int unusedBit9 : 1; /* 9 */
206 + unsigned int unusedBit10 : 1; /* 10 */
207 + unsigned int noCache : 1; /* 11 */
208 + unsigned int fdx : 1; /* 12 */
209 + unsigned int v2CompatibleHello : 1; /* 13 */
210 + unsigned int detectRollBack : 1; /* 14 */
211 + unsigned int noStepDown : 1; /* 15 */
212 + unsigned int bypassPKCS11 : 1; /* 16 */
213 + unsigned int noLocks : 1; /* 17 */
214 + unsigned int enableSessionTickets : 1; /* 18 */
215 + unsigned int enableDeflate : 1; /* 19 */
216 + unsigned int enableRenegotiation : 2; /* 20-21 */
217 + unsigned int requireSafeNegotiation : 1; /* 22 */
218 + unsigned int enableFalseStart : 1; /* 23 */
219 + unsigned int cbcRandomIV : 1; /* 24 */
220 + unsigned int enableOCSPStapling : 1; /* 25 */
221 + unsigned int enableSignedCertTimestamps : 1; /* 26 */
222 } sslOptions;
223
224 typedef enum { sslHandshakingUndetermined = 0,
225 @@ -698,6 +699,10 @@ struct sslSessionIDStr {
226 */
227 NewSessionTicket sessionTicket;
228 SECItem srvName;
229 + /* Signed certificate timestamps received in a TLS extension.
230 + ** (used only in client).
231 + */
232 + SECItem signedCertTimestamps;
233 } ssl3;
234 } u;
235 };
236 @@ -789,6 +794,15 @@ struct TLSExtensionDataStr {
237 * is beyond ssl3_HandleClientHello function. */
238 SECItem *sniNameArr;
239 PRUint32 sniNameArrSize;
240 + /* Signed Certificate Timestamps extracted from the TLS extension.
241 + * (client only).
242 + * This container holds a temporary pointer to the extension data,
243 + * until a session is setup that can hold a permanent copy of the data.
244 + * The data pointed to by this structure is neither explicitly allocated
245 + * nor copied: the pointer points to the handshake message buffer and is
246 + * only valid in the scope of ssl3_HandleServerHello.
247 + */
248 + SECItem signedCertTimestamps;
249 };
250
251 typedef SECStatus (*sslRestartTarget)(sslSocket *);
252 diff --git a/net/third_party/nss/ssl/sslnonce.c b/net/third_party/nss/ssl/sslnon ce.c
253 index a6f7349..6d330f0 100644
254 --- a/net/third_party/nss/ssl/sslnonce.c
255 +++ b/net/third_party/nss/ssl/sslnonce.c
256 @@ -142,13 +142,19 @@ ssl_DestroySID(sslSessionID *sid)
257 if ( sid->localCert ) {
258 CERT_DestroyCertificate(sid->localCert);
259 }
260 - if (sid->u.ssl3.sessionTicket.ticket.data) {
261 - SECITEM_FreeItem(&sid->u.ssl3.sessionTicket.ticket, PR_FALSE);
262 - }
263 - if (sid->u.ssl3.srvName.data) {
264 - SECITEM_FreeItem(&sid->u.ssl3.srvName, PR_FALSE);
265 +
266 + if (sid->version >= SSL_LIBRARY_VERSION_3_0) {
267 + if (sid->u.ssl3.sessionTicket.ticket.data) {
268 + SECITEM_FreeItem(&sid->u.ssl3.sessionTicket.ticket, PR_FALSE);
269 + }
270 + if (sid->u.ssl3.srvName.data) {
271 + SECITEM_FreeItem(&sid->u.ssl3.srvName, PR_FALSE);
272 + }
273 + if (sid->u.ssl3.signedCertTimestamps.data) {
274 + SECITEM_FreeItem(&sid->u.ssl3.signedCertTimestamps, PR_FALSE);
275 + }
276 }
277 -
278 +
279 PORT_ZFree(sid, sizeof(sslSessionID));
280 }
281
282 diff --git a/net/third_party/nss/ssl/sslsock.c b/net/third_party/nss/ssl/sslsock .c
283 index 072fad5..8072f23 100644
284 --- a/net/third_party/nss/ssl/sslsock.c
285 +++ b/net/third_party/nss/ssl/sslsock.c
286 @@ -173,7 +173,8 @@ static sslOptions ssl_defaults = {
287 PR_FALSE, /* requireSafeNegotiation */
288 PR_FALSE, /* enableFalseStart */
289 PR_TRUE, /* cbcRandomIV */
290 - PR_FALSE /* enableOCSPStapling */
291 + PR_FALSE, /* enableOCSPStapling */
292 + PR_FALSE /* enableSignedCertTimestamps */
293 };
294
295 /*
296 @@ -863,6 +864,10 @@ SSL_OptionSet(PRFileDesc *fd, PRInt32 which, PRBool on)
297 ss->opt.enableOCSPStapling = on;
298 break;
299
300 + case SSL_ENABLE_SIGNED_CERT_TIMESTAMPS:
301 + ss->opt.enableSignedCertTimestamps = on;
302 + break;
303 +
304 default:
305 PORT_SetError(SEC_ERROR_INVALID_ARGS);
306 rv = SECFailure;
307 @@ -933,6 +938,9 @@ SSL_OptionGet(PRFileDesc *fd, PRInt32 which, PRBool *pOn)
308 case SSL_ENABLE_FALSE_START: on = ss->opt.enableFalseStart; break;
309 case SSL_CBC_RANDOM_IV: on = ss->opt.cbcRandomIV; break;
310 case SSL_ENABLE_OCSP_STAPLING: on = ss->opt.enableOCSPStapling; break;
311 + case SSL_ENABLE_SIGNED_CERT_TIMESTAMPS:
312 + on = ss->opt.enableSignedCertTimestamps;
313 + break;
314
315 default:
316 PORT_SetError(SEC_ERROR_INVALID_ARGS);
317 @@ -994,6 +1002,9 @@ SSL_OptionGetDefault(PRInt32 which, PRBool *pOn)
318 case SSL_ENABLE_OCSP_STAPLING:
319 on = ssl_defaults.enableOCSPStapling;
320 break;
321 + case SSL_ENABLE_SIGNED_CERT_TIMESTAMPS:
322 + ssl_defaults.enableSignedCertTimestamps = on;
323 + break;
324
325 default:
326 PORT_SetError(SEC_ERROR_INVALID_ARGS);
327 @@ -1991,6 +2002,28 @@ SSL_PeerStapledOCSPResponses(PRFileDesc *fd)
328 return &ss->sec.ci.sid->peerCertStatus;
329 }
330
331 +const SECItem *
332 +SSL_PeerSignedCertTimestamps(PRFileDesc *fd)
333 +{
334 + sslSocket *ss = ssl_FindSocket(fd);
335 +
336 + if (!ss) {
337 + SSL_DBG(("%d: SSL[%d]: bad socket in SSL_PeerSignedCertTimestamps",
338 + SSL_GETPID(), fd));
339 + return NULL;
340 + }
341 +
342 + if (!ss->sec.ci.sid) {
343 + PORT_SetError(SEC_ERROR_NOT_INITIALIZED);
344 + return NULL;
345 + }
346 +
347 + if (ss->version < SSL_LIBRARY_VERSION_3_0) {
348 + return NULL;
349 + }
350 + return &ss->sec.ci.sid->u.ssl3.signedCertTimestamps;
351 +}
352 +
353 SECStatus
354 SSL_HandshakeResumedSession(PRFileDesc *fd, PRBool *handshake_resumed) {
355 sslSocket *ss = ssl_FindSocket(fd);
356 @@ -3131,4 +3164,3 @@ loser:
357 }
358 return ss;
359 }
360 -
361 diff --git a/net/third_party/nss/ssl/sslt.h b/net/third_party/nss/ssl/sslt.h
362 index a8007d8..ef77f21 100644
363 --- a/net/third_party/nss/ssl/sslt.h
364 +++ b/net/third_party/nss/ssl/sslt.h
365 @@ -205,9 +205,10 @@ typedef enum {
366 ssl_session_ticket_xtn = 35,
367 ssl_next_proto_nego_xtn = 13172,
368 ssl_channel_id_xtn = 30031,
369 - ssl_renegotiation_info_xtn = 0xff01 /* experimental number */
370 + ssl_renegotiation_info_xtn = 0xff01, /* experimental number */
371 + ssl_signed_certificate_timestamp_xtn = 18 /* RFC 6962 */
372 } SSLExtensionType;
373
374 -#define SSL_MAX_EXTENSIONS 11
375 +#define SSL_MAX_EXTENSIONS 12
376
377 #endif /* __sslt_h_ */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698