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

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

Issue 7239002: net: Precede each CBC encrypted application data record with an empty one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 6 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/patches/cbcrandomiv.patch ('k') | no next file » | 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 * SSL3 Protocol 2 * SSL3 Protocol
3 * 3 *
4 * ***** BEGIN LICENSE BLOCK ***** 4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * 6 *
7 * The contents of this file are subject to the Mozilla Public License Version 7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with 8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at 9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/ 10 * http://www.mozilla.org/MPL/
(...skipping 2211 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 return SECFailure; /* ssl3_InitState has set the error code. */ 2222 return SECFailure; /* ssl3_InitState has set the error code. */
2223 } 2223 }
2224 } 2224 }
2225 2225
2226 /* check for Token Presence */ 2226 /* check for Token Presence */
2227 if (!ssl3_ClientAuthTokenPresent(ss->sec.ci.sid)) { 2227 if (!ssl3_ClientAuthTokenPresent(ss->sec.ci.sid)) {
2228 PORT_SetError(SSL_ERROR_TOKEN_INSERTION_REMOVAL); 2228 PORT_SetError(SSL_ERROR_TOKEN_INSERTION_REMOVAL);
2229 return SECFailure; 2229 return SECFailure;
2230 } 2230 }
2231 2231
2232 while (nIn > 0) { 2232 do {
2233 PRUint32 contentLen = PR_MIN(nIn, MAX_FRAGMENT_LENGTH); 2233 PRUint32 contentLen = PR_MIN(nIn, MAX_FRAGMENT_LENGTH);
2234 2234
2235 if (wrBuf->space < contentLen + SSL3_BUFFER_FUDGE) { 2235 if (wrBuf->space < contentLen + SSL3_BUFFER_FUDGE) {
2236 PRInt32 newSpace = PR_MAX(wrBuf->space * 2, contentLen); 2236 PRInt32 newSpace = PR_MAX(wrBuf->space * 2, contentLen);
2237 newSpace = PR_MIN(newSpace, MAX_FRAGMENT_LENGTH); 2237 newSpace = PR_MIN(newSpace, MAX_FRAGMENT_LENGTH);
2238 newSpace += SSL3_BUFFER_FUDGE; 2238 newSpace += SSL3_BUFFER_FUDGE;
2239 rv = sslBuffer_Grow(wrBuf, newSpace); 2239 rv = sslBuffer_Grow(wrBuf, newSpace);
2240 if (rv != SECSuccess) { 2240 if (rv != SECSuccess) {
2241 SSL_DBG(("%d: SSL3[%d]: SendRecord, tried to get %d bytes", 2241 SSL_DBG(("%d: SSL3[%d]: SendRecord, tried to get %d bytes",
2242 SSL_GETPID(), ss->fd, newSpace)); 2242 SSL_GETPID(), ss->fd, newSpace));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2299 * append it to the buffer of previously unsent ciphertext. 2299 * append it to the buffer of previously unsent ciphertext.
2300 */ 2300 */
2301 rv = ssl_SaveWriteData(ss, wrBuf->buf + sent, wrBuf->len); 2301 rv = ssl_SaveWriteData(ss, wrBuf->buf + sent, wrBuf->len);
2302 if (rv != SECSuccess) { 2302 if (rv != SECSuccess) {
2303 /* presumably a memory error, SEC_ERROR_NO_MEMORY */ 2303 /* presumably a memory error, SEC_ERROR_NO_MEMORY */
2304 return SECFailure; 2304 return SECFailure;
2305 } 2305 }
2306 } 2306 }
2307 } 2307 }
2308 totalSent += contentLen; 2308 totalSent += contentLen;
2309 } 2309 } while (nIn > 0);
2310 return totalSent; 2310 return totalSent;
2311 } 2311 }
2312 2312
2313 #define SSL3_PENDING_HIGH_WATER 1024 2313 #define SSL3_PENDING_HIGH_WATER 1024
2314 2314
2315 /* Attempt to send the content of "in" in an SSL application_data record. 2315 /* Attempt to send the content of "in" in an SSL application_data record.
2316 * Returns "len" or SECFailure, never SECWouldBlock, nor SECSuccess. 2316 * Returns "len" or SECFailure, never SECWouldBlock, nor SECSuccess.
2317 */ 2317 */
2318 int 2318 int
2319 ssl3_SendApplicationData(sslSocket *ss, const unsigned char *in, 2319 ssl3_SendApplicationData(sslSocket *ss, const unsigned char *in,
2320 PRInt32 len, PRInt32 flags) 2320 PRInt32 len, PRInt32 flags)
2321 { 2321 {
2322 PRInt32 totalSent = 0; 2322 PRInt32 totalSent = 0;
2323 PRInt32 discarded = 0; 2323 PRInt32 discarded = 0;
2324 PRBool isBlockCipher;
2324 2325
2325 PORT_Assert( ss->opt.noLocks || ssl_HaveXmitBufLock(ss) ); 2326 PORT_Assert( ss->opt.noLocks || ssl_HaveXmitBufLock(ss) );
2326 if (len < 0 || !in) { 2327 if (len < 0 || !in) {
2327 PORT_SetError(PR_INVALID_ARGUMENT_ERROR); 2328 PORT_SetError(PR_INVALID_ARGUMENT_ERROR);
2328 return SECFailure; 2329 return SECFailure;
2329 } 2330 }
2330 2331
2331 if (ss->pendingBuf.len > SSL3_PENDING_HIGH_WATER && 2332 if (ss->pendingBuf.len > SSL3_PENDING_HIGH_WATER &&
2332 !ssl_SocketIsBlocking(ss)) { 2333 !ssl_SocketIsBlocking(ss)) {
2333 PORT_Assert(!ssl_SocketIsBlocking(ss)); 2334 PORT_Assert(!ssl_SocketIsBlocking(ss));
2334 PORT_SetError(PR_WOULD_BLOCK_ERROR); 2335 PORT_SetError(PR_WOULD_BLOCK_ERROR);
2335 return SECFailure; 2336 return SECFailure;
2336 } 2337 }
2337 2338
2338 if (ss->appDataBuffered && len) { 2339 if (ss->appDataBuffered && len) {
2339 PORT_Assert (in[0] == (unsigned char)(ss->appDataBuffered)); 2340 PORT_Assert (in[0] == (unsigned char)(ss->appDataBuffered));
2340 if (in[0] != (unsigned char)(ss->appDataBuffered)) { 2341 if (in[0] != (unsigned char)(ss->appDataBuffered)) {
2341 PORT_SetError(PR_INVALID_ARGUMENT_ERROR); 2342 PORT_SetError(PR_INVALID_ARGUMENT_ERROR);
2342 return SECFailure; 2343 return SECFailure;
2343 } 2344 }
2344 in++; 2345 in++;
2345 len--; 2346 len--;
2346 discarded = 1; 2347 discarded = 1;
2347 } 2348 }
2349
2350 ssl_GetSpecReadLock(ss);
2351 isBlockCipher = ss->ssl3.cwSpec->cipher_def->type == type_block;
2352 ssl_ReleaseSpecReadLock(ss);
2353
2354 if (isBlockCipher && len > 0) {
2355 // We assume that block ciphers are used in CBC mode and prepend an
2356 // empty record. This effectively randomizes the IV in a backwards
2357 // compatible way.
2358 PRInt32 sent = ssl3_SendRecord(ss, content_application_data,
2359 in, 0 /* no payload */, flags);
2360 if (sent < 0) {
2361 return SECFailure; /* error code set by ssl3_SendRecord */
2362 }
2363 if (ss->pendingBuf.len) {
2364 /* must be a non-blocking socket */
2365 PORT_Assert(!ssl_SocketIsBlocking(ss));
2366 PORT_Assert(ss->lastWriteBlocked);
2367 goto writeBlocked;
2368 }
wtc 2011/06/27 18:11:55 I suspect what you described will indeed happen if
agl 2011/06/27 19:05:30 Done.
2369 }
2370
2348 while (len > totalSent) { 2371 while (len > totalSent) {
2349 PRInt32 sent, toSend; 2372 PRInt32 sent, toSend;
2350 2373
2351 if (totalSent > 0) { 2374 if (totalSent > 0) {
2352 /* 2375 /*
2353 * The thread yield is intended to give the reader thread a 2376 * The thread yield is intended to give the reader thread a
2354 * chance to get some cycles while the writer thread is in 2377 * chance to get some cycles while the writer thread is in
2355 * the middle of a large application data write. (See 2378 * the middle of a large application data write. (See
2356 * Bugzilla bug 127740, comment #1.) 2379 * Bugzilla bug 127740, comment #1.)
2357 */ 2380 */
(...skipping 12 matching lines...) Expand all
2370 return SECFailure; /* error code set by ssl3_SendRecord */ 2393 return SECFailure; /* error code set by ssl3_SendRecord */
2371 } 2394 }
2372 totalSent += sent; 2395 totalSent += sent;
2373 if (ss->pendingBuf.len) { 2396 if (ss->pendingBuf.len) {
2374 /* must be a non-blocking socket */ 2397 /* must be a non-blocking socket */
2375 PORT_Assert(!ssl_SocketIsBlocking(ss)); 2398 PORT_Assert(!ssl_SocketIsBlocking(ss));
2376 PORT_Assert(ss->lastWriteBlocked); 2399 PORT_Assert(ss->lastWriteBlocked);
2377 break; 2400 break;
2378 } 2401 }
2379 } 2402 }
2403
2404 writeBlocked:
wtc 2011/06/27 18:11:55 Nit: labels are not indented in the NSS source cod
agl 2011/06/27 19:05:30 (mooted: line removed.)
2380 if (ss->pendingBuf.len) { 2405 if (ss->pendingBuf.len) {
2381 /* Must be non-blocking. */ 2406 /* Must be non-blocking. */
2382 PORT_Assert(!ssl_SocketIsBlocking(ss)); 2407 PORT_Assert(!ssl_SocketIsBlocking(ss));
2383 if (totalSent > 0) { 2408 if (totalSent > 0) {
2384 ss->appDataBuffered = 0x100 | in[totalSent - 1]; 2409 ss->appDataBuffered = 0x100 | in[totalSent - 1];
2385 } 2410 }
2386 2411
2387 totalSent = totalSent + discarded - 1; 2412 totalSent = totalSent + discarded - 1;
2388 if (totalSent <= 0) { 2413 if (totalSent <= 0) {
2389 PORT_SetError(PR_WOULD_BLOCK_ERROR); 2414 PORT_SetError(PR_WOULD_BLOCK_ERROR);
(...skipping 7458 matching lines...) Expand 10 before | Expand all | Expand 10 after
9848 9873
9849 ss->ssl3.initialized = PR_FALSE; 9874 ss->ssl3.initialized = PR_FALSE;
9850 9875
9851 if (ss->ssl3.nextProto.data) { 9876 if (ss->ssl3.nextProto.data) {
9852 PORT_Free(ss->ssl3.nextProto.data); 9877 PORT_Free(ss->ssl3.nextProto.data);
9853 ss->ssl3.nextProto.data = NULL; 9878 ss->ssl3.nextProto.data = NULL;
9854 } 9879 }
9855 } 9880 }
9856 9881
9857 /* End of ssl3con.c */ 9882 /* End of ssl3con.c */
OLDNEW
« no previous file with comments | « net/third_party/nss/patches/cbcrandomiv.patch ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698