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

Side by Side Diff: net/third_party/nss/ssl/sslsecur.c

Issue 23621040: Make SSL False Start work with asynchronous certificate validation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Update the patch file Created 7 years, 2 months 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 | Annotate | Revision Log
« no previous file with comments | « net/third_party/nss/ssl/sslinfo.c ('k') | net/third_party/nss/ssl/sslsock.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Various SSL functions. 2 * Various SSL functions.
3 * 3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public 4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "cert.h" 7 #include "cert.h"
8 #include "secitem.h" 8 #include "secitem.h"
9 #include "keyhi.h" 9 #include "keyhi.h"
10 #include "ssl.h" 10 #include "ssl.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 ss->nextHandshake = 0; 92 ss->nextHandshake = 0;
93 } 93 }
94 if (ss->handshake == 0) { 94 if (ss->handshake == 0) {
95 /* Previous handshake finished. Switch to security handshake */ 95 /* Previous handshake finished. Switch to security handshake */
96 ss->handshake = ss->securityHandshake; 96 ss->handshake = ss->securityHandshake;
97 ss->securityHandshake = 0; 97 ss->securityHandshake = 0;
98 } 98 }
99 if (ss->handshake == 0) { 99 if (ss->handshake == 0) {
100 ssl_GetRecvBufLock(ss); 100 ssl_GetRecvBufLock(ss);
101 ss->gs.recordLen = 0; 101 ss->gs.recordLen = 0;
102 ss->gs.writeOffset = 0;
103 ss->gs.readOffset = 0;
102 ssl_ReleaseRecvBufLock(ss); 104 ssl_ReleaseRecvBufLock(ss);
103 105
104 SSL_TRC(3, ("%d: SSL[%d]: handshake is completed", 106 SSL_TRC(3, ("%d: SSL[%d]: handshake is completed",
105 SSL_GETPID(), ss->fd)); 107 SSL_GETPID(), ss->fd));
106 /* call handshake callback for ssl v2 */
107 /* for v3 this is done in ssl3_HandleFinished() */
108 if ((ss->handshakeCallback != NULL) && /* has callback */
109 (!ss->firstHsDone) && /* only first time */
110 (ss->version < SSL_LIBRARY_VERSION_3_0)) { /* not ssl3 */
111 ss->firstHsDone = PR_TRUE;
112 (ss->handshakeCallback)(ss->fd, ss->handshakeCallbackData);
113 }
114 ss->firstHsDone = PR_TRUE;
115 ss->gs.writeOffset = 0;
116 ss->gs.readOffset = 0;
117 break; 108 break;
118 } 109 }
119 rv = (*ss->handshake)(ss); 110 rv = (*ss->handshake)(ss);
120 ++loopCount; 111 ++loopCount;
121 /* This code must continue to loop on SECWouldBlock, 112 /* This code must continue to loop on SECWouldBlock,
122 * or any positive value. See XXX_1 comments. 113 * or any positive value. See XXX_1 comments.
123 */ 114 */
124 } while (rv != SECFailure); /* was (rv >= 0); XXX_1 */ 115 } while (rv != SECFailure); /* was (rv >= 0); XXX_1 */
125 116
126 PORT_Assert(ss->opt.noLocks || !ssl_HaveRecvBufLock(ss)); 117 PORT_Assert(ss->opt.noLocks || !ssl_HaveRecvBufLock(ss));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 if (!ss->opt.useSecurity) 190 if (!ss->opt.useSecurity)
200 return SECSuccess; 191 return SECSuccess;
201 192
202 SSL_LOCK_READER(ss); 193 SSL_LOCK_READER(ss);
203 SSL_LOCK_WRITER(ss); 194 SSL_LOCK_WRITER(ss);
204 195
205 /* Reset handshake state */ 196 /* Reset handshake state */
206 ssl_Get1stHandshakeLock(ss); 197 ssl_Get1stHandshakeLock(ss);
207 198
208 ss->firstHsDone = PR_FALSE; 199 ss->firstHsDone = PR_FALSE;
200 ss->enoughFirstHsDone = PR_FALSE;
209 if ( asServer ) { 201 if ( asServer ) {
210 ss->handshake = ssl2_BeginServerHandshake; 202 ss->handshake = ssl2_BeginServerHandshake;
211 ss->handshaking = sslHandshakingAsServer; 203 ss->handshaking = sslHandshakingAsServer;
212 } else { 204 } else {
213 ss->handshake = ssl2_BeginClientHandshake; 205 ss->handshake = ssl2_BeginClientHandshake;
214 ss->handshaking = sslHandshakingAsClient; 206 ss->handshaking = sslHandshakingAsClient;
215 } 207 }
216 ss->nextHandshake = 0; 208 ss->nextHandshake = 0;
217 ss->securityHandshake = 0; 209 ss->securityHandshake = 0;
218 210
219 ssl_GetRecvBufLock(ss); 211 ssl_GetRecvBufLock(ss);
220 status = ssl_InitGather(&ss->gs); 212 status = ssl_InitGather(&ss->gs);
221 ssl_ReleaseRecvBufLock(ss); 213 ssl_ReleaseRecvBufLock(ss);
222 214
223 ssl_GetSSL3HandshakeLock(ss); 215 ssl_GetSSL3HandshakeLock(ss);
216 ss->ssl3.hs.canFalseStart = PR_FALSE;
217 ss->ssl3.hs.restartTarget = NULL;
224 218
225 /* 219 /*
226 ** Blow away old security state and get a fresh setup. 220 ** Blow away old security state and get a fresh setup.
227 */ 221 */
228 ssl_GetXmitBufLock(ss); 222 ssl_GetXmitBufLock(ss);
229 ssl_ResetSecurityInfo(&ss->sec, PR_TRUE); 223 ssl_ResetSecurityInfo(&ss->sec, PR_TRUE);
230 status = ssl_CreateSecurityInfo(ss); 224 status = ssl_CreateSecurityInfo(ss);
231 ssl_ReleaseXmitBufLock(ss); 225 ssl_ReleaseXmitBufLock(ss);
232 226
233 ssl_ReleaseSSL3HandshakeLock(ss); 227 ssl_ReleaseSSL3HandshakeLock(ss);
(...skipping 25 matching lines...) Expand all
259 return SECFailure; 253 return SECFailure;
260 } 254 }
261 255
262 if (!ss->opt.useSecurity) 256 if (!ss->opt.useSecurity)
263 return SECSuccess; 257 return SECSuccess;
264 258
265 ssl_Get1stHandshakeLock(ss); 259 ssl_Get1stHandshakeLock(ss);
266 260
267 /* SSL v2 protocol does not support subsequent handshakes. */ 261 /* SSL v2 protocol does not support subsequent handshakes. */
268 if (ss->version < SSL_LIBRARY_VERSION_3_0) { 262 if (ss->version < SSL_LIBRARY_VERSION_3_0) {
269 » PORT_SetError(SEC_ERROR_INVALID_ARGS); 263 » PORT_SetError(SSL_ERROR_FEATURE_NOT_SUPPORTED_FOR_SSL2);
270 rv = SECFailure; 264 rv = SECFailure;
271 } else { 265 } else {
272 ssl_GetSSL3HandshakeLock(ss); 266 ssl_GetSSL3HandshakeLock(ss);
273 rv = ssl3_RedoHandshake(ss, flushCache); /* force full handshake. */ 267 rv = ssl3_RedoHandshake(ss, flushCache); /* force full handshake. */
274 ssl_ReleaseSSL3HandshakeLock(ss); 268 ssl_ReleaseSSL3HandshakeLock(ss);
275 } 269 }
276 270
277 ssl_Release1stHandshakeLock(ss); 271 ssl_Release1stHandshakeLock(ss);
278 272
279 return rv; 273 return rv;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 318
325 ss->handshakeCallback = cb; 319 ss->handshakeCallback = cb;
326 ss->handshakeCallbackData = client_data; 320 ss->handshakeCallbackData = client_data;
327 321
328 ssl_ReleaseSSL3HandshakeLock(ss); 322 ssl_ReleaseSSL3HandshakeLock(ss);
329 ssl_Release1stHandshakeLock(ss); 323 ssl_Release1stHandshakeLock(ss);
330 324
331 return SECSuccess; 325 return SECSuccess;
332 } 326 }
333 327
328 /* Register an application callback to be called when false start may happen.
329 ** Acquires and releases HandshakeLock.
330 */
331 SECStatus
332 SSL_SetCanFalseStartCallback(PRFileDesc *fd, SSLCanFalseStartCallback cb,
333 void *client_data)
334 {
335 sslSocket *ss;
336
337 ss = ssl_FindSocket(fd);
338 if (!ss) {
339 SSL_DBG(("%d: SSL[%d]: bad socket in SSL_SetCanFalseStartCallback",
340 SSL_GETPID(), fd));
341 return SECFailure;
342 }
343
344 if (!ss->opt.useSecurity) {
345 PORT_SetError(SEC_ERROR_INVALID_ARGS);
346 return SECFailure;
347 }
348
349 ssl_Get1stHandshakeLock(ss);
350 ssl_GetSSL3HandshakeLock(ss);
351
352 ss->canFalseStartCallback = cb;
353 ss->canFalseStartCallbackData = client_data;
354
355 ssl_ReleaseSSL3HandshakeLock(ss);
356 ssl_Release1stHandshakeLock(ss);
357
358 return SECSuccess;
359 }
360
361 /* A utility function that can be called from a custom SSLCanFalseStartCallback
362 ** function to determine what NSS would have done for this connection if the
363 ** custom callback was not implemented.
364 */
365 SECStatus
366 SSL_DefaultCanFalseStart(PRFileDesc *fd, PRBool *canFalseStart)
367 {
368 sslSocket *ss;
369
370 *canFalseStart = PR_FALSE;
371 ss = ssl_FindSocket(fd);
372 if (!ss) {
373 SSL_DBG(("%d: SSL[%d]: bad socket in SSL_DefaultCanFalseStart",
374 SSL_GETPID(), fd));
375 return SECFailure;
376 }
377
378 if (!ss->ssl3.initialized) {
379 PORT_SetError(SEC_ERROR_INVALID_ARGS);
380 return SECFailure;
381 }
382
383 if (ss->version < SSL_LIBRARY_VERSION_3_0) {
384 PORT_SetError(SSL_ERROR_FEATURE_NOT_SUPPORTED_FOR_SSL2);
385 return SECFailure;
386 }
387
388 /* Require a forward-secret key exchange. */
389 *canFalseStart = ss->ssl3.hs.kea_def->kea == kea_dhe_dss ||
390 ss->ssl3.hs.kea_def->kea == kea_dhe_rsa ||
391 ss->ssl3.hs.kea_def->kea == kea_ecdhe_ecdsa ||
392 ss->ssl3.hs.kea_def->kea == kea_ecdhe_rsa;
393
394 return SECSuccess;
395 }
396
334 /* Try to make progress on an SSL handshake by attempting to read the 397 /* Try to make progress on an SSL handshake by attempting to read the
335 ** next handshake from the peer, and sending any responses. 398 ** next handshake from the peer, and sending any responses.
336 ** For non-blocking sockets, returns PR_ERROR_WOULD_BLOCK if it cannot 399 ** For non-blocking sockets, returns PR_ERROR_WOULD_BLOCK if it cannot
337 ** read the next handshake from the underlying socket. 400 ** read the next handshake from the underlying socket.
338 ** For SSLv2, returns when handshake is complete or fatal error occurs. 401 ** For SSLv2, returns when handshake is complete or fatal error occurs.
339 ** For SSLv3, returns when handshake is complete, or application data has 402 ** For SSLv3, returns when handshake is complete, or application data has
340 ** arrived that must be taken by application before handshake can continue, 403 ** arrived that must be taken by application before handshake can continue,
341 ** or a fatal error occurs. 404 ** or a fatal error occurs.
342 ** Application should use handshake completion callback to tell which. 405 ** Application should use handshake completion callback to tell which.
343 */ 406 */
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 } 1251 }
1189 1252
1190 if (len > 0) 1253 if (len > 0)
1191 ss->writerThread = PR_GetCurrentThread(); 1254 ss->writerThread = PR_GetCurrentThread();
1192 /* If any of these is non-zero, the initial handshake is not done. */ 1255 /* If any of these is non-zero, the initial handshake is not done. */
1193 if (!ss->firstHsDone) { 1256 if (!ss->firstHsDone) {
1194 PRBool canFalseStart = PR_FALSE; 1257 PRBool canFalseStart = PR_FALSE;
1195 ssl_Get1stHandshakeLock(ss); 1258 ssl_Get1stHandshakeLock(ss);
1196 if (ss->version >= SSL_LIBRARY_VERSION_3_0) { 1259 if (ss->version >= SSL_LIBRARY_VERSION_3_0) {
1197 ssl_GetSSL3HandshakeLock(ss); 1260 ssl_GetSSL3HandshakeLock(ss);
1198 » if ((ss->ssl3.hs.ws == wait_change_cipher || 1261 » canFalseStart = ss->ssl3.hs.canFalseStart;
1199 » » ss->ssl3.hs.ws == wait_finished ||
1200 » » ss->ssl3.hs.ws == wait_new_session_ticket) &&
1201 » » ssl3_CanFalseStart(ss)) {
1202 » » canFalseStart = PR_TRUE;
1203 » }
1204 ssl_ReleaseSSL3HandshakeLock(ss); 1262 ssl_ReleaseSSL3HandshakeLock(ss);
1205 } 1263 }
1206 if (!canFalseStart && 1264 if (!canFalseStart &&
1207 (ss->handshake || ss->nextHandshake || ss->securityHandshake)) { 1265 (ss->handshake || ss->nextHandshake || ss->securityHandshake)) {
1208 rv = ssl_Do1stHandshake(ss); 1266 rv = ssl_Do1stHandshake(ss);
1209 } 1267 }
1210 ssl_Release1stHandshakeLock(ss); 1268 ssl_Release1stHandshakeLock(ss);
1211 } 1269 }
1212 if (rv < 0) { 1270 if (rv < 0) {
1213 ss->writerThread = NULL; 1271 ss->writerThread = NULL;
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 if (!ss) { 1647 if (!ss) {
1590 SSL_DBG(("%d: SSL[%d]: bad socket in SNISocketConfigHook", 1648 SSL_DBG(("%d: SSL[%d]: bad socket in SNISocketConfigHook",
1591 SSL_GETPID(), fd)); 1649 SSL_GETPID(), fd));
1592 return SECFailure; 1650 return SECFailure;
1593 } 1651 }
1594 1652
1595 ss->sniSocketConfig = func; 1653 ss->sniSocketConfig = func;
1596 ss->sniSocketConfigArg = arg; 1654 ss->sniSocketConfigArg = arg;
1597 return SECSuccess; 1655 return SECSuccess;
1598 } 1656 }
OLDNEW
« no previous file with comments | « net/third_party/nss/ssl/sslinfo.c ('k') | net/third_party/nss/ssl/sslsock.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698