OLD | NEW |
---|---|
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | 1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 /* | 2 /* |
3 * SSL3 Protocol | 3 * SSL3 Protocol |
4 * | 4 * |
5 * This Source Code Form is subject to the terms of the Mozilla Public | 5 * This Source Code Form is subject to the terms of the Mozilla Public |
6 * License, v. 2.0. If a copy of the MPL was not distributed with this | 6 * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
8 /* $Id: ssl3con.c,v 1.192 2012/09/28 05:10:25 wtc%google.com Exp $ */ | 8 /* $Id: ssl3con.c,v 1.192 2012/09/28 05:10:25 wtc%google.com Exp $ */ |
9 | 9 |
10 /* TODO(ekr): Implement HelloVerifyRequest on server side. OK for now. */ | 10 /* TODO(ekr): Implement HelloVerifyRequest on server side. OK for now. */ |
(...skipping 2170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2181 (PK11_NeedLogin(slot) && !PK11_IsLoggedIn(slot, NULL))) { | 2181 (PK11_NeedLogin(slot) && !PK11_IsLoggedIn(slot, NULL))) { |
2182 isPresent = PR_FALSE; | 2182 isPresent = PR_FALSE; |
2183 } | 2183 } |
2184 if (slot) { | 2184 if (slot) { |
2185 PK11_FreeSlot(slot); | 2185 PK11_FreeSlot(slot); |
2186 } | 2186 } |
2187 return isPresent; | 2187 return isPresent; |
2188 } | 2188 } |
2189 | 2189 |
2190 /* Caller must hold the spec read lock. */ | 2190 /* Caller must hold the spec read lock. */ |
2191 /* The function uses the three members of wrBuf as follows: | |
2192 * - Reads wrBuf->buf and wrBuf->space. Note that it does not read wrBuf->len. | |
2193 * - Writes data into the buffer that wrBuf->buf points to. | |
2194 * - Sets wrBuf->len to the number of bytes written on successful return. | |
2195 */ | |
2191 SECStatus | 2196 SECStatus |
2192 ssl3_CompressMACEncryptRecord(ssl3CipherSpec * cwSpec, | 2197 ssl3_CompressMACEncryptRecord(ssl3CipherSpec * cwSpec, |
2193 PRBool isServer, | 2198 PRBool isServer, |
2194 PRBool isDTLS, | 2199 PRBool isDTLS, |
2195 PRBool capRecordVersion, | 2200 PRBool capRecordVersion, |
2196 SSL3ContentType type, | 2201 SSL3ContentType type, |
2197 const SSL3Opaque * pIn, | 2202 const SSL3Opaque * pIn, |
2198 PRUint32 contentLen, | 2203 PRUint32 contentLen, |
2199 sslBuffer * wrBuf) | 2204 sslBuffer * wrBuf) |
2200 { | 2205 { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2326 p2Len); /* input and inputLen*/ | 2331 p2Len); /* input and inputLen*/ |
2327 PORT_Assert(rv == SECSuccess && cipherBytesPart2 == (int) p2Len); | 2332 PORT_Assert(rv == SECSuccess && cipherBytesPart2 == (int) p2Len); |
2328 if (rv != SECSuccess || cipherBytesPart2 != (int) p2Len) { | 2333 if (rv != SECSuccess || cipherBytesPart2 != (int) p2Len) { |
2329 PORT_SetError(SSL_ERROR_ENCRYPTION_FAILURE); | 2334 PORT_SetError(SSL_ERROR_ENCRYPTION_FAILURE); |
2330 return SECFailure; | 2335 return SECFailure; |
2331 } | 2336 } |
2332 cipherBytes += cipherBytesPart2; | 2337 cipherBytes += cipherBytesPart2; |
2333 } | 2338 } |
2334 PORT_Assert(cipherBytes <= MAX_FRAGMENT_LENGTH + 1024); | 2339 PORT_Assert(cipherBytes <= MAX_FRAGMENT_LENGTH + 1024); |
2335 | 2340 |
2336 wrBuf->len = cipherBytes + headerLen; | 2341 wrBuf->len = cipherBytes + headerLen; |
wtc
2013/03/16 01:15:38
Here ssl3_CompressMACEncryptRecord sets wrBuf->len
| |
2337 wrBuf->buf[0] = type; | 2342 wrBuf->buf[0] = type; |
2338 if (isDTLS) { | 2343 if (isDTLS) { |
2339 SSL3ProtocolVersion version; | 2344 SSL3ProtocolVersion version; |
2340 | 2345 |
2341 version = dtls_TLSVersionToDTLSVersion(cwSpec->version); | 2346 version = dtls_TLSVersionToDTLSVersion(cwSpec->version); |
2342 wrBuf->buf[1] = MSB(version); | 2347 wrBuf->buf[1] = MSB(version); |
2343 wrBuf->buf[2] = LSB(version); | 2348 wrBuf->buf[2] = LSB(version); |
2344 wrBuf->buf[3] = (unsigned char)(cwSpec->write_seq_num.high >> 24); | 2349 wrBuf->buf[3] = (unsigned char)(cwSpec->write_seq_num.high >> 24); |
2345 wrBuf->buf[4] = (unsigned char)(cwSpec->write_seq_num.high >> 16); | 2350 wrBuf->buf[4] = (unsigned char)(cwSpec->write_seq_num.high >> 16); |
2346 wrBuf->buf[5] = (unsigned char)(cwSpec->write_seq_num.high >> 8); | 2351 wrBuf->buf[5] = (unsigned char)(cwSpec->write_seq_num.high >> 8); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2409 SECStatus rv; | 2414 SECStatus rv; |
2410 PRInt32 totalSent = 0; | 2415 PRInt32 totalSent = 0; |
2411 PRBool capRecordVersion; | 2416 PRBool capRecordVersion; |
2412 | 2417 |
2413 SSL_TRC(3, ("%d: SSL3[%d] SendRecord type: %s nIn=%d", | 2418 SSL_TRC(3, ("%d: SSL3[%d] SendRecord type: %s nIn=%d", |
2414 SSL_GETPID(), ss->fd, ssl3_DecodeContentType(type), | 2419 SSL_GETPID(), ss->fd, ssl3_DecodeContentType(type), |
2415 nIn)); | 2420 nIn)); |
2416 PRINT_BUF(3, (ss, "Send record (plain text)", pIn, nIn)); | 2421 PRINT_BUF(3, (ss, "Send record (plain text)", pIn, nIn)); |
2417 | 2422 |
2418 PORT_Assert( ss->opt.noLocks || ssl_HaveXmitBufLock(ss) ); | 2423 PORT_Assert( ss->opt.noLocks || ssl_HaveXmitBufLock(ss) ); |
2424 PORT_Assert( wrBuf->len == 0 ); | |
2419 | 2425 |
2420 capRecordVersion = ((flags & ssl_SEND_FLAG_CAP_RECORD_VERSION) != 0); | 2426 capRecordVersion = ((flags & ssl_SEND_FLAG_CAP_RECORD_VERSION) != 0); |
2421 | 2427 |
2422 if (capRecordVersion) { | 2428 if (capRecordVersion) { |
2423 /* ssl_SEND_FLAG_CAP_RECORD_VERSION can only be used with the | 2429 /* ssl_SEND_FLAG_CAP_RECORD_VERSION can only be used with the |
2424 * TLS initial ClientHello. */ | 2430 * TLS initial ClientHello. */ |
2425 PORT_Assert(!IS_DTLS(ss)); | 2431 PORT_Assert(!IS_DTLS(ss)); |
2426 PORT_Assert(!ss->firstHsDone); | 2432 PORT_Assert(!ss->firstHsDone); |
2427 PORT_Assert(type == content_handshake); | 2433 PORT_Assert(type == content_handshake); |
2428 PORT_Assert(ss->ssl3.hs.ws == wait_server_hello); | 2434 PORT_Assert(ss->ssl3.hs.ws == wait_server_hello); |
(...skipping 13 matching lines...) Expand all Loading... | |
2442 | 2448 |
2443 /* check for Token Presence */ | 2449 /* check for Token Presence */ |
2444 if (!ssl3_ClientAuthTokenPresent(ss->sec.ci.sid)) { | 2450 if (!ssl3_ClientAuthTokenPresent(ss->sec.ci.sid)) { |
2445 PORT_SetError(SSL_ERROR_TOKEN_INSERTION_REMOVAL); | 2451 PORT_SetError(SSL_ERROR_TOKEN_INSERTION_REMOVAL); |
2446 return SECFailure; | 2452 return SECFailure; |
2447 } | 2453 } |
2448 | 2454 |
2449 while (nIn > 0) { | 2455 while (nIn > 0) { |
2450 PRUint32 contentLen = PR_MIN(nIn, MAX_FRAGMENT_LENGTH); | 2456 PRUint32 contentLen = PR_MIN(nIn, MAX_FRAGMENT_LENGTH); |
2451 unsigned int spaceNeeded; | 2457 unsigned int spaceNeeded; |
2452 » unsigned int numRecords; | 2458 » unsigned int numRecords = 1; |
2453 | 2459 |
2454 ssl_GetSpecReadLock(ss); /********************************/ | 2460 ssl_GetSpecReadLock(ss); /********************************/ |
2455 | 2461 |
2456 if (nIn > 1 && ss->opt.cbcRandomIV && | 2462 if (nIn > 1 && ss->opt.cbcRandomIV && |
2457 ss->ssl3.cwSpec->version < SSL_LIBRARY_VERSION_TLS_1_1 && | 2463 ss->ssl3.cwSpec->version < SSL_LIBRARY_VERSION_TLS_1_1 && |
2458 type == content_application_data && | 2464 type == content_application_data && |
2459 ss->ssl3.cwSpec->cipher_def->type == type_block /* CBC mode */) { | 2465 ss->ssl3.cwSpec->cipher_def->type == type_block /* CBC mode */) { |
2460 /* We will split the first byte of the record into its own record, | 2466 /* We will split the first byte of the record into its own record, |
2461 * as explained in the documentation for SSL_CBC_RANDOM_IV in ssl.h | 2467 * as explained in the documentation for SSL_CBC_RANDOM_IV in ssl.h |
2462 */ | 2468 */ |
2463 numRecords = 2; | 2469 numRecords = 2; |
2464 » } else { | 2470 » } |
agl
2013/03/19 16:41:00
This could be an else if to make it clear that the
wtc
2013/03/22 01:33:29
Done.
| |
2465 » numRecords = 1; | 2471 » if (nIn > 1 && ss->opt.cbcRandomIV && |
2472 » type == content_application_data && | |
2473 » ss->ssl3.cwSpec->cipher_def->calg == ssl_calg_rc4 && | |
2474 » ss->ssl3.rc4EncryptedBytes < SSL3_BIASED_RC4_BYTES) { | |
wtc
2013/03/16 01:15:38
Reminder to self: add a comment to explain how we
| |
2475 » PRInt32 inBytes = nIn; | |
2476 | |
2477 » numRecords = 0; | |
2478 | |
2479 » /* Count how many one-byte records are needed to exhaust the | |
2480 » * biased RC4 keystream bytes. */ | |
2481 » while (inBytes > 0 && | |
2482 » » ss->ssl3.rc4EncryptedBytes < SSL3_BIASED_RC4_BYTES) { | |
2483 » » ss->ssl3.rc4EncryptedBytes += 1 + ss->ssl3.cwSpec->mac_size; | |
wtc
2013/03/16 01:15:38
It is non-ideal that we are incrementing ss->ssl3.
| |
2484 » » inBytes--; | |
2485 » » numRecords++; | |
2486 » } | |
2487 | |
2488 » /* Send any remaining bytes in one record. */ | |
2489 » if (inBytes > 0) { | |
2490 » » numRecords++; | |
2491 » } | |
2466 } | 2492 } |
2467 | 2493 |
2468 spaceNeeded = contentLen + (numRecords * SSL3_BUFFER_FUDGE); | 2494 spaceNeeded = contentLen + (numRecords * SSL3_BUFFER_FUDGE); |
2469 if (ss->ssl3.cwSpec->version >= SSL_LIBRARY_VERSION_TLS_1_1 && | 2495 if (ss->ssl3.cwSpec->version >= SSL_LIBRARY_VERSION_TLS_1_1 && |
2470 ss->ssl3.cwSpec->cipher_def->type == type_block) { | 2496 ss->ssl3.cwSpec->cipher_def->type == type_block) { |
2471 spaceNeeded += ss->ssl3.cwSpec->cipher_def->iv_size; | 2497 spaceNeeded += ss->ssl3.cwSpec->cipher_def->iv_size; |
2472 } | 2498 } |
2473 if (spaceNeeded > wrBuf->space) { | 2499 if (spaceNeeded > wrBuf->space) { |
2474 rv = sslBuffer_Grow(wrBuf, spaceNeeded); | 2500 rv = sslBuffer_Grow(wrBuf, spaceNeeded); |
Ryan Sleevi
2013/03/19 17:24:28
so sslBuffer_Grow caps the growth at MAX_FRAGMENT_
agl
2013/03/19 17:26:44
The MACs are also encrypted so each record is burn
Ryan Sleevi
2013/03/19 17:29:10
Doh! Right, forgot that important detail.
| |
2475 if (rv != SECSuccess) { | 2501 if (rv != SECSuccess) { |
2476 SSL_DBG(("%d: SSL3[%d]: SendRecord, tried to get %d bytes", | 2502 SSL_DBG(("%d: SSL3[%d]: SendRecord, tried to get %d bytes", |
2477 SSL_GETPID(), ss->fd, spaceNeeded)); | 2503 SSL_GETPID(), ss->fd, spaceNeeded)); |
2478 goto spec_locked_loser; /* sslBuffer_Grow set error code. */ | 2504 goto spec_locked_loser; /* sslBuffer_Grow set error code. */ |
2479 } | 2505 } |
2480 } | 2506 } |
2481 | 2507 |
2482 » if (numRecords == 2) { | 2508 » if (numRecords > 1) { |
2483 » sslBuffer secondRecord; | 2509 » sslBuffer recordBuf; |
2510 » unsigned int i; | |
2484 | 2511 |
2485 » rv = ssl3_CompressMACEncryptRecord(ss->ssl3.cwSpec, | 2512 » wrBuf->len = 0; |
2486 » » » » » ss->sec.isServer, IS_DTLS(ss), | 2513 » for (i = 0; i < numRecords; i++) { |
2487 » » » » » capRecordVersion, type, pIn, | 2514 » » recordBuf.buf = wrBuf->buf + wrBuf->len; |
2488 » » » » » 1, wrBuf); | 2515 » » recordBuf.len = 0; |
2489 » if (rv != SECSuccess) | 2516 » » recordBuf.space = wrBuf->space - wrBuf->len; |
2490 » goto spec_locked_loser; | |
2491 | 2517 |
2492 » PRINT_BUF(50, (ss, "send (encrypted) record data [1/2]:", | 2518 » » rv = ssl3_CompressMACEncryptRecord(ss->ssl3.cwSpec, |
2493 » wrBuf->buf, wrBuf->len)); | 2519 » » » » » » ss->sec.isServer, |
2520 » » » » » » IS_DTLS(ss), | |
2521 » » » » » » capRecordVersion, type, | |
2522 » » » » » » pIn + i, | |
2523 » » » » » » (i != numRecords - 1) ? | |
2524 » » » » » » 1 : contentLen - i, | |
2525 » » » » » » &recordBuf); | |
2526 » » if (rv != SECSuccess) | |
2527 » » break; | |
2494 | 2528 |
2495 » secondRecord.buf = wrBuf->buf + wrBuf->len; | 2529 » » PRINT_BUF(50, (ss, "send (encrypted) record data:", |
2496 » secondRecord.len = 0; | 2530 » » » recordBuf.buf, recordBuf.len)); |
2497 » secondRecord.space = wrBuf->space - wrBuf->len; | 2531 » » wrBuf->len += recordBuf.len; |
2498 | |
2499 » rv = ssl3_CompressMACEncryptRecord(ss->ssl3.cwSpec, | |
2500 » ss->sec.isServer, IS_DTLS(ss), | |
2501 » » » » » capRecordVersion, type, | |
2502 » » » » » pIn + 1, contentLen - 1, | |
2503 » &secondRecord); | |
2504 » if (rv == SECSuccess) { | |
2505 » PRINT_BUF(50, (ss, "send (encrypted) record data [2/2]:", | |
2506 » secondRecord.buf, secondRecord.len)); | |
2507 » wrBuf->len += secondRecord.len; | |
2508 } | 2532 } |
2509 } else { | 2533 } else { |
2510 if (!IS_DTLS(ss)) { | 2534 if (!IS_DTLS(ss)) { |
2511 rv = ssl3_CompressMACEncryptRecord(ss->ssl3.cwSpec, | 2535 rv = ssl3_CompressMACEncryptRecord(ss->ssl3.cwSpec, |
2512 ss->sec.isServer, | 2536 ss->sec.isServer, |
2513 IS_DTLS(ss), | 2537 IS_DTLS(ss), |
2514 capRecordVersion, | 2538 capRecordVersion, |
2515 type, pIn, | 2539 type, pIn, |
2516 contentLen, wrBuf); | 2540 contentLen, wrBuf); |
2517 } else { | 2541 } else { |
2518 rv = dtls_CompressMACEncryptRecord(ss, epoch, | 2542 rv = dtls_CompressMACEncryptRecord(ss, epoch, |
2519 !!(flags & ssl_SEND_FLAG_USE_ EPOCH), | 2543 !!(flags & ssl_SEND_FLAG_USE_ EPOCH), |
2520 type, pIn, | 2544 type, pIn, |
2521 contentLen, wrBuf); | 2545 contentLen, wrBuf); |
2522 } | 2546 } |
2523 | 2547 |
2524 if (rv == SECSuccess) { | 2548 if (rv == SECSuccess) { |
2525 PRINT_BUF(50, (ss, "send (encrypted) record data:", | 2549 PRINT_BUF(50, (ss, "send (encrypted) record data:", |
2526 wrBuf->buf, wrBuf->len)); | 2550 wrBuf->buf, wrBuf->len)); |
2551 | |
2552 if (ss->opt.cbcRandomIV && type == content_handshake && | |
2553 ss->ssl3.cwSpec->cipher_def->calg == ssl_calg_rc4) { | |
2554 ss->ssl3.rc4EncryptedBytes += | |
2555 wrBuf->len - SSL3_RECORD_HEADER_LENGTH; | |
wtc
2013/03/16 01:15:38
I could add an output argument to ssl3_CompressMAC
agl
2013/03/19 16:41:00
It doesn't. (I don't think it ever could if TLS is
| |
2556 } | |
2527 } | 2557 } |
2528 } | 2558 } |
2529 | 2559 |
2530 spec_locked_loser: | 2560 spec_locked_loser: |
2531 ssl_ReleaseSpecReadLock(ss); /************************************/ | 2561 ssl_ReleaseSpecReadLock(ss); /************************************/ |
2532 | 2562 |
2533 if (rv != SECSuccess) | 2563 if (rv != SECSuccess) |
2534 return SECFailure; | 2564 return SECFailure; |
2535 | 2565 |
2536 pIn += contentLen; | 2566 pIn += contentLen; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2584 return SECFailure; | 2614 return SECFailure; |
2585 } | 2615 } |
2586 /* now take all the remaining unsent new ciphertext and | 2616 /* now take all the remaining unsent new ciphertext and |
2587 * append it to the buffer of previously unsent ciphertext. | 2617 * append it to the buffer of previously unsent ciphertext. |
2588 */ | 2618 */ |
2589 rv = ssl_SaveWriteData(ss, wrBuf->buf + sent, wrBuf->len); | 2619 rv = ssl_SaveWriteData(ss, wrBuf->buf + sent, wrBuf->len); |
2590 if (rv != SECSuccess) { | 2620 if (rv != SECSuccess) { |
2591 /* presumably a memory error, SEC_ERROR_NO_MEMORY */ | 2621 /* presumably a memory error, SEC_ERROR_NO_MEMORY */ |
2592 return SECFailure; | 2622 return SECFailure; |
2593 } | 2623 } |
2624 wrBuf->len = 0; /* All cipher text is saved away. */ | |
2594 } | 2625 } |
2595 } | 2626 } |
2596 totalSent += contentLen; | 2627 totalSent += contentLen; |
2597 } | 2628 } |
2598 return totalSent; | 2629 return totalSent; |
2599 } | 2630 } |
2600 | 2631 |
2601 #define SSL3_PENDING_HIGH_WATER 1024 | 2632 #define SSL3_PENDING_HIGH_WATER 1024 |
2602 | 2633 |
2603 /* Attempt to send the content of "in" in an SSL application_data record. | 2634 /* Attempt to send the content of "in" in an SSL application_data record. |
(...skipping 10 matching lines...) Expand all Loading... | |
2614 /* These flags for internal use only */ | 2645 /* These flags for internal use only */ |
2615 PORT_Assert(!(flags & (ssl_SEND_FLAG_USE_EPOCH | | 2646 PORT_Assert(!(flags & (ssl_SEND_FLAG_USE_EPOCH | |
2616 ssl_SEND_FLAG_NO_RETRANSMIT))); | 2647 ssl_SEND_FLAG_NO_RETRANSMIT))); |
2617 if (len < 0 || !in) { | 2648 if (len < 0 || !in) { |
2618 PORT_SetError(PR_INVALID_ARGUMENT_ERROR); | 2649 PORT_SetError(PR_INVALID_ARGUMENT_ERROR); |
2619 return SECFailure; | 2650 return SECFailure; |
2620 } | 2651 } |
2621 | 2652 |
2622 if (ss->pendingBuf.len > SSL3_PENDING_HIGH_WATER && | 2653 if (ss->pendingBuf.len > SSL3_PENDING_HIGH_WATER && |
2623 !ssl_SocketIsBlocking(ss)) { | 2654 !ssl_SocketIsBlocking(ss)) { |
2624 PORT_Assert(!ssl_SocketIsBlocking(ss)); | |
2625 PORT_SetError(PR_WOULD_BLOCK_ERROR); | 2655 PORT_SetError(PR_WOULD_BLOCK_ERROR); |
2626 return SECFailure; | 2656 return SECFailure; |
2627 } | 2657 } |
2628 | 2658 |
2629 if (ss->appDataBuffered && len) { | 2659 if (ss->appDataBuffered && len) { |
2630 PORT_Assert (in[0] == (unsigned char)(ss->appDataBuffered)); | 2660 PORT_Assert (in[0] == (unsigned char)(ss->appDataBuffered)); |
2631 if (in[0] != (unsigned char)(ss->appDataBuffered)) { | 2661 if (in[0] != (unsigned char)(ss->appDataBuffered)) { |
2632 PORT_SetError(PR_INVALID_ARGUMENT_ERROR); | 2662 PORT_SetError(PR_INVALID_ARGUMENT_ERROR); |
2633 return SECFailure; | 2663 return SECFailure; |
2634 } | 2664 } |
2635 in++; | 2665 in++; |
2636 len--; | 2666 len--; |
2637 discarded = 1; | 2667 discarded = 1; |
2638 } | 2668 } |
2639 while (len > totalSent) { | 2669 while (len > totalSent) { |
2640 PRInt32 sent, toSend; | 2670 PRInt32 sent, toSend; |
2641 | 2671 |
2642 if (totalSent > 0) { | 2672 if (totalSent > 0) { |
2643 /* | 2673 /* |
2644 * The thread yield is intended to give the reader thread a | 2674 * The thread yield is intended to give the reader thread a |
2645 * chance to get some cycles while the writer thread is in | 2675 * chance to get some cycles while the writer thread is in |
2646 * the middle of a large application data write. (See | 2676 * the middle of a large application data write. (See |
2647 * Bugzilla bug 127740, comment #1.) | 2677 * Bugzilla bug 127740, comment #1.) |
2648 */ | 2678 */ |
2649 ssl_ReleaseXmitBufLock(ss); | 2679 ssl_ReleaseXmitBufLock(ss); |
2650 PR_Sleep(PR_INTERVAL_NO_WAIT); /* PR_Yield(); */ | 2680 PR_Sleep(PR_INTERVAL_NO_WAIT); /* PR_Yield(); */ |
2651 ssl_GetXmitBufLock(ss); | 2681 ssl_GetXmitBufLock(ss); |
2652 } | 2682 } |
2653 toSend = PR_MIN(len - totalSent, MAX_FRAGMENT_LENGTH); | 2683 toSend = PR_MIN(len - totalSent, MAX_FRAGMENT_LENGTH); |
wtc
2013/03/19 17:44:02
This PR_MIN call caps the |nIn| argument for ssl3_
| |
2654 /* | 2684 /* |
2655 * Note that the 0 epoch is OK because flags will never require | 2685 * Note that the 0 epoch is OK because flags will never require |
2656 * its use, as guaranteed by the PORT_Assert above. | 2686 * its use, as guaranteed by the PORT_Assert above. |
2657 */ | 2687 */ |
2658 sent = ssl3_SendRecord(ss, 0, content_application_data, | 2688 sent = ssl3_SendRecord(ss, 0, content_application_data, |
2659 in + totalSent, toSend, flags); | 2689 in + totalSent, toSend, flags); |
2660 if (sent < 0) { | 2690 if (sent < 0) { |
2661 if (totalSent > 0 && PR_GetError() == PR_WOULD_BLOCK_ERROR) { | 2691 if (totalSent > 0 && PR_GetError() == PR_WOULD_BLOCK_ERROR) { |
2662 PORT_Assert(ss->lastWriteBlocked); | 2692 PORT_Assert(ss->lastWriteBlocked); |
2663 break; | 2693 break; |
(...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4181 PORT_Assert(IS_DTLS(ss) || !resending); | 4211 PORT_Assert(IS_DTLS(ss) || !resending); |
4182 | 4212 |
4183 /* We might be starting a session renegotiation in which case we should | 4213 /* We might be starting a session renegotiation in which case we should |
4184 * clear previous state. | 4214 * clear previous state. |
4185 */ | 4215 */ |
4186 PORT_Memset(&ss->xtnData, 0, sizeof(TLSExtensionData)); | 4216 PORT_Memset(&ss->xtnData, 0, sizeof(TLSExtensionData)); |
4187 ss->ssl3.hs.may_get_cert_status = PR_FALSE; | 4217 ss->ssl3.hs.may_get_cert_status = PR_FALSE; |
4188 if (ss->ssl3.hs.cert_status.data) { | 4218 if (ss->ssl3.hs.cert_status.data) { |
4189 SECITEM_FreeItem(&ss->ssl3.hs.cert_status, PR_FALSE); | 4219 SECITEM_FreeItem(&ss->ssl3.hs.cert_status, PR_FALSE); |
4190 } | 4220 } |
4221 ss->ssl3.rc4EncryptedBytes = 0; | |
wtc
2013/03/16 01:15:38
I found the places where we need to reset
ss->ssl3
agl
2013/03/19 16:41:00
I think this would be taken care of naturally if t
wtc
2013/03/19 17:44:02
That seems like a good idea because rc4EncryptedBy
wtc
2013/03/22 01:33:29
Done.
| |
4191 | 4222 |
4192 SSL_TRC(30,("%d: SSL3[%d]: reset handshake hashes", | 4223 SSL_TRC(30,("%d: SSL3[%d]: reset handshake hashes", |
4193 SSL_GETPID(), ss->fd )); | 4224 SSL_GETPID(), ss->fd )); |
4194 rv = ssl3_RestartHandshakeHashes(ss); | 4225 rv = ssl3_RestartHandshakeHashes(ss); |
4195 if (rv != SECSuccess) { | 4226 if (rv != SECSuccess) { |
4196 return rv; | 4227 return rv; |
4197 } | 4228 } |
4198 | 4229 |
4199 /* | 4230 /* |
4200 * During a renegotiation, ss->clientHelloVersion will be used again to | 4231 * During a renegotiation, ss->clientHelloVersion will be used again to |
(...skipping 2608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6809 if (IS_DTLS(ss)) { | 6840 if (IS_DTLS(ss)) { |
6810 ss->nextHandshake = 0; | 6841 ss->nextHandshake = 0; |
6811 ss->securityHandshake = 0; | 6842 ss->securityHandshake = 0; |
6812 } | 6843 } |
6813 | 6844 |
6814 /* We might be starting session renegotiation in which case we should | 6845 /* We might be starting session renegotiation in which case we should |
6815 * clear previous state. | 6846 * clear previous state. |
6816 */ | 6847 */ |
6817 PORT_Memset(&ss->xtnData, 0, sizeof(TLSExtensionData)); | 6848 PORT_Memset(&ss->xtnData, 0, sizeof(TLSExtensionData)); |
6818 ss->statelessResume = PR_FALSE; | 6849 ss->statelessResume = PR_FALSE; |
6850 ss->ssl3.rc4EncryptedBytes = 0; | |
6819 | 6851 |
6820 rv = ssl3_InitState(ss); | 6852 rv = ssl3_InitState(ss); |
6821 if (rv != SECSuccess) { | 6853 if (rv != SECSuccess) { |
6822 return rv; /* ssl3_InitState has set the error code. */ | 6854 return rv; /* ssl3_InitState has set the error code. */ |
6823 } | 6855 } |
6824 | 6856 |
6825 if ((ss->ssl3.hs.ws != wait_client_hello) && | 6857 if ((ss->ssl3.hs.ws != wait_client_hello) && |
6826 (ss->ssl3.hs.ws != idle_handshake)) { | 6858 (ss->ssl3.hs.ws != idle_handshake)) { |
6827 desc = unexpected_message; | 6859 desc = unexpected_message; |
6828 errCode = SSL_ERROR_RX_UNEXPECTED_CLIENT_HELLO; | 6860 errCode = SSL_ERROR_RX_UNEXPECTED_CLIENT_HELLO; |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7568 int errCode = SSL_ERROR_RX_MALFORMED_CLIENT_HELLO; | 7600 int errCode = SSL_ERROR_RX_MALFORMED_CLIENT_HELLO; |
7569 SSL3AlertDescription desc = handshake_failure; | 7601 SSL3AlertDescription desc = handshake_failure; |
7570 | 7602 |
7571 SSL_TRC(3, ("%d: SSL3[%d]: handle v2 client_hello", SSL_GETPID(), ss->fd)); | 7603 SSL_TRC(3, ("%d: SSL3[%d]: handle v2 client_hello", SSL_GETPID(), ss->fd)); |
7572 | 7604 |
7573 PORT_Assert( ss->opt.noLocks || ssl_HaveRecvBufLock(ss) ); | 7605 PORT_Assert( ss->opt.noLocks || ssl_HaveRecvBufLock(ss) ); |
7574 | 7606 |
7575 ssl_GetSSL3HandshakeLock(ss); | 7607 ssl_GetSSL3HandshakeLock(ss); |
7576 | 7608 |
7577 PORT_Memset(&ss->xtnData, 0, sizeof(TLSExtensionData)); | 7609 PORT_Memset(&ss->xtnData, 0, sizeof(TLSExtensionData)); |
7610 ss->ssl3.rc4EncryptedBytes = 0; | |
7578 | 7611 |
7579 rv = ssl3_InitState(ss); | 7612 rv = ssl3_InitState(ss); |
7580 if (rv != SECSuccess) { | 7613 if (rv != SECSuccess) { |
7581 ssl_ReleaseSSL3HandshakeLock(ss); | 7614 ssl_ReleaseSSL3HandshakeLock(ss); |
7582 return rv; /* ssl3_InitState has set the error code. */ | 7615 return rv; /* ssl3_InitState has set the error code. */ |
7583 } | 7616 } |
7584 | 7617 |
7585 if (ss->ssl3.hs.ws != wait_client_hello) { | 7618 if (ss->ssl3.hs.ws != wait_client_hello) { |
7586 desc = unexpected_message; | 7619 desc = unexpected_message; |
7587 errCode = SSL_ERROR_RX_UNEXPECTED_CLIENT_HELLO; | 7620 errCode = SSL_ERROR_RX_UNEXPECTED_CLIENT_HELLO; |
(...skipping 3251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10839 ss->ssl3.hs.sendingSCSV = PR_FALSE; | 10872 ss->ssl3.hs.sendingSCSV = PR_FALSE; |
10840 ssl3_InitCipherSpec(ss, ss->ssl3.crSpec); | 10873 ssl3_InitCipherSpec(ss, ss->ssl3.crSpec); |
10841 ssl3_InitCipherSpec(ss, ss->ssl3.prSpec); | 10874 ssl3_InitCipherSpec(ss, ss->ssl3.prSpec); |
10842 | 10875 |
10843 ss->ssl3.hs.ws = (ss->sec.isServer) ? wait_client_hello : wait_server_hello; | 10876 ss->ssl3.hs.ws = (ss->sec.isServer) ? wait_client_hello : wait_server_hello; |
10844 #ifdef NSS_ENABLE_ECC | 10877 #ifdef NSS_ENABLE_ECC |
10845 ss->ssl3.hs.negotiatedECCurves = SSL3_SUPPORTED_CURVES_MASK; | 10878 ss->ssl3.hs.negotiatedECCurves = SSL3_SUPPORTED_CURVES_MASK; |
10846 #endif | 10879 #endif |
10847 ssl_ReleaseSpecWriteLock(ss); | 10880 ssl_ReleaseSpecWriteLock(ss); |
10848 | 10881 |
10882 /* XXX: move xtnData into ss->ssl3? */ | |
10849 PORT_Memset(&ss->xtnData, 0, sizeof(TLSExtensionData)); | 10883 PORT_Memset(&ss->xtnData, 0, sizeof(TLSExtensionData)); |
10884 ss->ssl3.rc4EncryptedBytes = 0; | |
10850 | 10885 |
10851 if (IS_DTLS(ss)) { | 10886 if (IS_DTLS(ss)) { |
10852 ss->ssl3.hs.sendMessageSeq = 0; | 10887 ss->ssl3.hs.sendMessageSeq = 0; |
10853 ss->ssl3.hs.recvMessageSeq = 0; | 10888 ss->ssl3.hs.recvMessageSeq = 0; |
10854 ss->ssl3.hs.rtTimeoutMs = INITIAL_DTLS_TIMEOUT_MS; | 10889 ss->ssl3.hs.rtTimeoutMs = INITIAL_DTLS_TIMEOUT_MS; |
10855 ss->ssl3.hs.rtRetries = 0; | 10890 ss->ssl3.hs.rtRetries = 0; |
10856 ss->ssl3.hs.recvdHighWater = -1; | 10891 ss->ssl3.hs.recvdHighWater = -1; |
10857 PR_INIT_CLIST(&ss->ssl3.hs.lastMessageFlight); | 10892 PR_INIT_CLIST(&ss->ssl3.hs.lastMessageFlight); |
10858 dtls_SetMTU(ss, 0); /* Set the MTU to the highest plateau */ | 10893 dtls_SetMTU(ss, 0); /* Set the MTU to the highest plateau */ |
10859 } | 10894 } |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11266 PORT_Free(ss->ssl3.hs.recvdFragments.buf); | 11301 PORT_Free(ss->ssl3.hs.recvdFragments.buf); |
11267 } | 11302 } |
11268 } | 11303 } |
11269 | 11304 |
11270 ss->ssl3.initialized = PR_FALSE; | 11305 ss->ssl3.initialized = PR_FALSE; |
11271 | 11306 |
11272 SECITEM_FreeItem(&ss->ssl3.nextProto, PR_FALSE); | 11307 SECITEM_FreeItem(&ss->ssl3.nextProto, PR_FALSE); |
11273 } | 11308 } |
11274 | 11309 |
11275 /* End of ssl3con.c */ | 11310 /* End of ssl3con.c */ |
OLD | NEW |