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

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

Powered by Google App Engine
This is Rietveld 408576698