| OLD | NEW |
| 1 /* | 1 /* |
| 2 * SSL3 Protocol | 2 * SSL3 Protocol |
| 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 | 7 |
| 8 /* TLS extension code moved here from ssl3ecc.c */ | 8 /* TLS extension code moved here from ssl3ecc.c */ |
| 9 | 9 |
| 10 #include "nssrenam.h" | 10 #include "nssrenam.h" |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 * sends an empty ticket. Servers always send empty tickets. | 494 * sends an empty ticket. Servers always send empty tickets. |
| 495 */ | 495 */ |
| 496 PRInt32 | 496 PRInt32 |
| 497 ssl3_SendSessionTicketXtn( | 497 ssl3_SendSessionTicketXtn( |
| 498 sslSocket * ss, | 498 sslSocket * ss, |
| 499 PRBool append, | 499 PRBool append, |
| 500 PRUint32 maxBytes) | 500 PRUint32 maxBytes) |
| 501 { | 501 { |
| 502 PRInt32 extension_length; | 502 PRInt32 extension_length; |
| 503 NewSessionTicket *session_ticket = NULL; | 503 NewSessionTicket *session_ticket = NULL; |
| 504 sslSessionID *sid = ss->sec.ci.sid; |
| 504 | 505 |
| 505 /* Ignore the SessionTicket extension if processing is disabled. */ | 506 /* Ignore the SessionTicket extension if processing is disabled. */ |
| 506 if (!ss->opt.enableSessionTickets) | 507 if (!ss->opt.enableSessionTickets) |
| 507 return 0; | 508 return 0; |
| 508 | 509 |
| 509 /* Empty extension length = extension_type (2-bytes) + | 510 /* Empty extension length = extension_type (2-bytes) + |
| 510 * length(extension_data) (2-bytes) | 511 * length(extension_data) (2-bytes) |
| 511 */ | 512 */ |
| 512 extension_length = 4; | 513 extension_length = 4; |
| 513 | 514 |
| 514 /* If we are a client then send a session ticket if one is availble. | 515 /* If we are a client then send a session ticket if one is availble. |
| 515 * Servers that support the extension and are willing to negotiate the | 516 * Servers that support the extension and are willing to negotiate the |
| 516 * the extension always respond with an empty extension. | 517 * the extension always respond with an empty extension. |
| 517 */ | 518 */ |
| 518 if (!ss->sec.isServer) { | 519 if (!ss->sec.isServer) { |
| 519 » sslSessionID *sid = ss->sec.ci.sid; | 520 » /* The caller must be holding sid->u.ssl3.lock for reading. We cannot |
| 520 » session_ticket = &sid->u.ssl3.sessionTicket; | 521 » * just acquire and release the lock within this function because the |
| 522 » * caller will call this function twice, and we need the inputs to be |
| 523 » * consistent between the two calls. Note that currently the caller |
| 524 » * will only be holding the lock when we are the client and when we're |
| 525 » * attempting to resume an existing session. |
| 526 » */ |
| 527 |
| 528 » session_ticket = &sid->u.ssl3.locked.sessionTicket; |
| 521 if (session_ticket->ticket.data) { | 529 if (session_ticket->ticket.data) { |
| 522 if (ss->xtnData.ticketTimestampVerified) { | 530 if (ss->xtnData.ticketTimestampVerified) { |
| 523 extension_length += session_ticket->ticket.len; | 531 extension_length += session_ticket->ticket.len; |
| 524 } else if (!append && | 532 } else if (!append && |
| 525 (session_ticket->ticket_lifetime_hint == 0 || | 533 (session_ticket->ticket_lifetime_hint == 0 || |
| 526 (session_ticket->ticket_lifetime_hint + | 534 (session_ticket->ticket_lifetime_hint + |
| 527 session_ticket->received_timestamp > ssl_Time()))) { | 535 session_ticket->received_timestamp > ssl_Time()))) { |
| 528 extension_length += session_ticket->ticket.len; | 536 extension_length += session_ticket->ticket.len; |
| 529 ss->xtnData.ticketTimestampVerified = PR_TRUE; | 537 ss->xtnData.ticketTimestampVerified = PR_TRUE; |
| 530 } | 538 } |
| 531 } | 539 } |
| 532 } | 540 } |
| 533 | 541 |
| 534 if (append && maxBytes >= extension_length) { | 542 if (append && maxBytes >= extension_length) { |
| 535 SECStatus rv; | 543 SECStatus rv; |
| 536 /* extension_type */ | 544 /* extension_type */ |
| 537 rv = ssl3_AppendHandshakeNumber(ss, ssl_session_ticket_xtn, 2); | 545 rv = ssl3_AppendHandshakeNumber(ss, ssl_session_ticket_xtn, 2); |
| 538 if (rv != SECSuccess) | 546 if (rv != SECSuccess) |
| 539 goto loser; | 547 goto loser; |
| 540 if (session_ticket && session_ticket->ticket.data && | 548 if (session_ticket && session_ticket->ticket.data && |
| 541 ss->xtnData.ticketTimestampVerified) { | 549 ss->xtnData.ticketTimestampVerified) { |
| 542 rv = ssl3_AppendHandshakeVariable(ss, session_ticket->ticket.data, | 550 rv = ssl3_AppendHandshakeVariable(ss, session_ticket->ticket.data, |
| 543 session_ticket->ticket.len, 2); | 551 session_ticket->ticket.len, 2); |
| 544 ss->xtnData.ticketTimestampVerified = PR_FALSE; | 552 ss->xtnData.ticketTimestampVerified = PR_FALSE; |
| 553 ss->xtnData.sentSessionTicketInClientHello = PR_TRUE; |
| 545 } else { | 554 } else { |
| 546 rv = ssl3_AppendHandshakeNumber(ss, 0, 2); | 555 rv = ssl3_AppendHandshakeNumber(ss, 0, 2); |
| 547 } | 556 } |
| 548 if (rv != SECSuccess) | 557 if (rv != SECSuccess) |
| 549 goto loser; | 558 goto loser; |
| 550 | 559 |
| 551 if (!ss->sec.isServer) { | 560 if (!ss->sec.isServer) { |
| 552 TLSExtensionData *xtnData = &ss->xtnData; | 561 TLSExtensionData *xtnData = &ss->xtnData; |
| 553 xtnData->advertised[xtnData->numAdvertised++] = | 562 xtnData->advertised[xtnData->numAdvertised++] = |
| 554 ssl_session_ticket_xtn; | 563 ssl_session_ticket_xtn; |
| (...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 | 1597 |
| 1589 temp = ssl3_ConsumeHandshakeNumber(ss, 2, &buffer, &buffer_len); | 1598 temp = ssl3_ConsumeHandshakeNumber(ss, 2, &buffer, &buffer_len); |
| 1590 if (temp < 0) goto no_ticket; | 1599 if (temp < 0) goto no_ticket; |
| 1591 parsed_session_ticket->ms_length = (PRUint16)temp; | 1600 parsed_session_ticket->ms_length = (PRUint16)temp; |
| 1592 if (parsed_session_ticket->ms_length == 0 || /* sanity check MS. */ | 1601 if (parsed_session_ticket->ms_length == 0 || /* sanity check MS. */ |
| 1593 parsed_session_ticket->ms_length > | 1602 parsed_session_ticket->ms_length > |
| 1594 sizeof(parsed_session_ticket->master_secret)) | 1603 sizeof(parsed_session_ticket->master_secret)) |
| 1595 goto no_ticket; | 1604 goto no_ticket; |
| 1596 | 1605 |
| 1597 /* Allow for the wrapped master secret to be longer. */ | 1606 /* Allow for the wrapped master secret to be longer. */ |
| 1598 » if (buffer_len < sizeof(SSL3_MASTER_SECRET_LENGTH)) | 1607 » if (buffer_len < parsed_session_ticket->ms_length) |
| 1599 goto no_ticket; | 1608 goto no_ticket; |
| 1600 PORT_Memcpy(parsed_session_ticket->master_secret, buffer, | 1609 PORT_Memcpy(parsed_session_ticket->master_secret, buffer, |
| 1601 parsed_session_ticket->ms_length); | 1610 parsed_session_ticket->ms_length); |
| 1602 buffer += parsed_session_ticket->ms_length; | 1611 buffer += parsed_session_ticket->ms_length; |
| 1603 buffer_len -= parsed_session_ticket->ms_length; | 1612 buffer_len -= parsed_session_ticket->ms_length; |
| 1604 | 1613 |
| 1605 /* Read client_identity */ | 1614 /* Read client_identity */ |
| 1606 temp = ssl3_ConsumeHandshakeNumber(ss, 1, &buffer, &buffer_len); | 1615 temp = ssl3_ConsumeHandshakeNumber(ss, 1, &buffer, &buffer_len); |
| 1607 if (temp < 0) | 1616 if (temp < 0) |
| 1608 goto no_ticket; | 1617 goto no_ticket; |
| (...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2428 | 2437 |
| 2429 if (!data->len) { | 2438 if (!data->len) { |
| 2430 /* Empty extension data: RFC 6962 mandates non-empty contents. */ | 2439 /* Empty extension data: RFC 6962 mandates non-empty contents. */ |
| 2431 return SECFailure; | 2440 return SECFailure; |
| 2432 } | 2441 } |
| 2433 *scts = *data; | 2442 *scts = *data; |
| 2434 /* Keep track of negotiated extensions. */ | 2443 /* Keep track of negotiated extensions. */ |
| 2435 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type; | 2444 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type; |
| 2436 return SECSuccess; | 2445 return SECSuccess; |
| 2437 } | 2446 } |
| OLD | NEW |