| OLD | NEW |
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 |
| 1 /* | 5 /* |
| 2 * DTLS Protocol | 6 * DTLS Protocol |
| 3 * | 7 */ |
| 4 * ***** BEGIN LICENSE BLOCK ***** | 8 /* $Id: dtlscon.c,v 1.5 2012/09/28 01:46:45 wtc%google.com Exp $ */ |
| 5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | |
| 6 * | |
| 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 | |
| 9 * the License. You may obtain a copy of the License at | |
| 10 * http://www.mozilla.org/MPL/ | |
| 11 * | |
| 12 * Software distributed under the License is distributed on an "AS IS" basis, | |
| 13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
| 14 * for the specific language governing rights and limitations under the | |
| 15 * License. | |
| 16 * | |
| 17 * The Original Code is the Netscape security libraries. | |
| 18 * | |
| 19 * The Initial Developer of the Original Code is | |
| 20 * Netscape Communications Corporation. | |
| 21 * Portions created by the Initial Developer are Copyright (C) 1994-2000 | |
| 22 * the Initial Developer. All Rights Reserved. | |
| 23 * | |
| 24 * Contributor(s): | |
| 25 * Eric Rescorla <ekr@rtfm.com> | |
| 26 * | |
| 27 * Alternatively, the contents of this file may be used under the terms of | |
| 28 * either the GNU General Public License Version 2 or later (the "GPL"), or | |
| 29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | |
| 30 * in which case the provisions of the GPL or the LGPL are applicable instead | |
| 31 * of those above. If you wish to allow use of your version of this file only | |
| 32 * under the terms of either the GPL or the LGPL, and not to allow others to | |
| 33 * use your version of this file under the terms of the MPL, indicate your | |
| 34 * decision by deleting the provisions above and replace them with the notice | |
| 35 * and other provisions required by the GPL or the LGPL. If you do not delete | |
| 36 * the provisions above, a recipient may use your version of this file under | |
| 37 * the terms of any one of the MPL, the GPL or the LGPL. | |
| 38 * | |
| 39 * ***** END LICENSE BLOCK ***** */ | |
| 40 /* $Id: $ */ | |
| 41 | 9 |
| 42 #include "ssl.h" | 10 #include "ssl.h" |
| 43 #include "sslimpl.h" | 11 #include "sslimpl.h" |
| 44 #include "sslproto.h" | 12 #include "sslproto.h" |
| 45 | 13 |
| 46 #ifndef PR_ARRAY_SIZE | 14 #ifndef PR_ARRAY_SIZE |
| 47 #define PR_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) | 15 #define PR_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) |
| 48 #endif | 16 #endif |
| 49 | 17 |
| 50 static SECStatus dtls_TransmitMessageFlight(sslSocket *ss); | 18 static SECStatus dtls_TransmitMessageFlight(sslSocket *ss); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 */ | 247 */ |
| 280 if ((message_seq == ss->ssl3.hs.recvMessageSeq) | 248 if ((message_seq == ss->ssl3.hs.recvMessageSeq) |
| 281 && (fragment_offset == 0) | 249 && (fragment_offset == 0) |
| 282 && (fragment_length == message_length)) { | 250 && (fragment_length == message_length)) { |
| 283 /* Complete next message. Process immediately */ | 251 /* Complete next message. Process immediately */ |
| 284 ss->ssl3.hs.msg_type = (SSL3HandshakeType)type; | 252 ss->ssl3.hs.msg_type = (SSL3HandshakeType)type; |
| 285 ss->ssl3.hs.msg_len = message_length; | 253 ss->ssl3.hs.msg_len = message_length; |
| 286 | 254 |
| 287 /* At this point we are advancing our state machine, so | 255 /* At this point we are advancing our state machine, so |
| 288 * we can free our last flight of messages */ | 256 * we can free our last flight of messages */ |
| 289 dtls_FreeHandshakeMessages(ss->ssl3.hs.lastMessageFlight); | 257 dtls_FreeHandshakeMessages(&ss->ssl3.hs.lastMessageFlight); |
| 290 ss->ssl3.hs.recvdHighWater = -1; | 258 ss->ssl3.hs.recvdHighWater = -1; |
| 291 dtls_CancelTimer(ss); | 259 dtls_CancelTimer(ss); |
| 292 | 260 |
| 293 /* Reset the timer to the initial value if the retry counter | 261 /* Reset the timer to the initial value if the retry counter |
| 294 * is 0, per Sec. 4.2.4.1 */ | 262 * is 0, per Sec. 4.2.4.1 */ |
| 295 if (ss->ssl3.hs.rtRetries == 0) { | 263 if (ss->ssl3.hs.rtRetries == 0) { |
| 296 ss->ssl3.hs.rtTimeoutMs = INITIAL_DTLS_TIMEOUT_MS; | 264 ss->ssl3.hs.rtTimeoutMs = INITIAL_DTLS_TIMEOUT_MS; |
| 297 } | 265 } |
| 298 | 266 |
| 299 rv = ssl3_HandleHandshakeMessage(ss, buf.buf, ss->ssl3.hs.msg_len); | 267 rv = ssl3_HandleHandshakeMessage(ss, buf.buf, ss->ssl3.hs.msg_len); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 ss->ssl3.hs.recvdHighWater = -1; | 414 ss->ssl3.hs.recvdHighWater = -1; |
| 447 | 415 |
| 448 rv = ssl3_HandleHandshakeMessage(ss, | 416 rv = ssl3_HandleHandshakeMessage(ss, |
| 449 ss->ssl3.hs.msg_body.buf, | 417 ss->ssl3.hs.msg_body.buf, |
| 450 ss->ssl3.hs.msg_len); | 418 ss->ssl3.hs.msg_len); |
| 451 if (rv == SECFailure) | 419 if (rv == SECFailure) |
| 452 break; /* Skip rest of record */ | 420 break; /* Skip rest of record */ |
| 453 | 421 |
| 454 /* At this point we are advancing our state machine, so | 422 /* At this point we are advancing our state machine, so |
| 455 * we can free our last flight of messages */ | 423 * we can free our last flight of messages */ |
| 456 » » dtls_FreeHandshakeMessages(ss->ssl3.hs.lastMessageFlight); | 424 » » dtls_FreeHandshakeMessages(&ss->ssl3.hs.lastMessageFlight); |
| 457 dtls_CancelTimer(ss); | 425 dtls_CancelTimer(ss); |
| 458 | 426 |
| 459 /* If there have been no retries this time, reset the | 427 /* If there have been no retries this time, reset the |
| 460 * timer value to the default per Section 4.2.4.1 */ | 428 * timer value to the default per Section 4.2.4.1 */ |
| 461 if (ss->ssl3.hs.rtRetries == 0) { | 429 if (ss->ssl3.hs.rtRetries == 0) { |
| 462 ss->ssl3.hs.rtTimeoutMs = INITIAL_DTLS_TIMEOUT_MS; | 430 ss->ssl3.hs.rtTimeoutMs = INITIAL_DTLS_TIMEOUT_MS; |
| 463 } | 431 } |
| 464 } | 432 } |
| 465 } | 433 } |
| 466 } | 434 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 490 | 458 |
| 491 PORT_Assert(ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss)); | 459 PORT_Assert(ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss)); |
| 492 PORT_Assert(ss->opt.noLocks || ssl_HaveXmitBufLock(ss)); | 460 PORT_Assert(ss->opt.noLocks || ssl_HaveXmitBufLock(ss)); |
| 493 | 461 |
| 494 msg = dtls_AllocQueuedMessage(ss->ssl3.cwSpec->epoch, type, pIn, nIn); | 462 msg = dtls_AllocQueuedMessage(ss->ssl3.cwSpec->epoch, type, pIn, nIn); |
| 495 | 463 |
| 496 if (!msg) { | 464 if (!msg) { |
| 497 PORT_SetError(SEC_ERROR_NO_MEMORY); | 465 PORT_SetError(SEC_ERROR_NO_MEMORY); |
| 498 rv = SECFailure; | 466 rv = SECFailure; |
| 499 } else { | 467 } else { |
| 500 » PR_APPEND_LINK(&msg->link, ss->ssl3.hs.lastMessageFlight); | 468 » PR_APPEND_LINK(&msg->link, &ss->ssl3.hs.lastMessageFlight); |
| 501 } | 469 } |
| 502 | 470 |
| 503 return rv; | 471 return rv; |
| 504 } | 472 } |
| 505 | 473 |
| 506 /* Add DTLS handshake message to the pending queue | 474 /* Add DTLS handshake message to the pending queue |
| 507 * Empty the sendBuf buffer. | 475 * Empty the sendBuf buffer. |
| 508 * This function returns SECSuccess or SECFailure, never SECWouldBlock. | 476 * This function returns SECSuccess or SECFailure, never SECWouldBlock. |
| 509 * Always set sendBuf.len to 0, even when returning SECFailure. | 477 * Always set sendBuf.len to 0, even when returning SECFailure. |
| 510 * | 478 * |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 ssl_GetXmitBufLock(ss); | 584 ssl_GetXmitBufLock(ss); |
| 617 ssl_GetSpecReadLock(ss); | 585 ssl_GetSpecReadLock(ss); |
| 618 | 586 |
| 619 /* DTLS does not buffer its handshake messages in | 587 /* DTLS does not buffer its handshake messages in |
| 620 * ss->pendingBuf, but rather in the lastMessageFlight | 588 * ss->pendingBuf, but rather in the lastMessageFlight |
| 621 * structure. This is just a sanity check that | 589 * structure. This is just a sanity check that |
| 622 * some programming error hasn't inadvertantly | 590 * some programming error hasn't inadvertantly |
| 623 * stuffed something in ss->pendingBuf | 591 * stuffed something in ss->pendingBuf |
| 624 */ | 592 */ |
| 625 PORT_Assert(!ss->pendingBuf.len); | 593 PORT_Assert(!ss->pendingBuf.len); |
| 626 for (msg_p = PR_LIST_HEAD(ss->ssl3.hs.lastMessageFlight); | 594 for (msg_p = PR_LIST_HEAD(&ss->ssl3.hs.lastMessageFlight); |
| 627 » msg_p != ss->ssl3.hs.lastMessageFlight; | 595 » msg_p != &ss->ssl3.hs.lastMessageFlight; |
| 628 msg_p = PR_NEXT_LINK(msg_p)) { | 596 msg_p = PR_NEXT_LINK(msg_p)) { |
| 629 DTLSQueuedMessage *msg = (DTLSQueuedMessage *)msg_p; | 597 DTLSQueuedMessage *msg = (DTLSQueuedMessage *)msg_p; |
| 630 | 598 |
| 631 /* The logic here is: | 599 /* The logic here is: |
| 632 * | 600 * |
| 633 * 1. If this is a message that will not fit into the remaining | 601 * 1. If this is a message that will not fit into the remaining |
| 634 * space, then flush. | 602 * space, then flush. |
| 635 * 2. If the message will now fit into the remaining space, | 603 * 2. If the message will now fit into the remaining space, |
| 636 * encrypt, buffer, and loop. | 604 * encrypt, buffer, and loop. |
| 637 * 3. If the message will not fit, then fragment. | 605 * 3. If the message will not fit, then fragment. |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 desired = PR_MillisecondsToInterval(ss->ssl3.hs.rtTimeoutMs); | 1124 desired = PR_MillisecondsToInterval(ss->ssl3.hs.rtTimeoutMs); |
| 1157 if (elapsed > desired) { | 1125 if (elapsed > desired) { |
| 1158 /* Timer expired */ | 1126 /* Timer expired */ |
| 1159 *timeout = PR_INTERVAL_NO_WAIT; | 1127 *timeout = PR_INTERVAL_NO_WAIT; |
| 1160 } else { | 1128 } else { |
| 1161 *timeout = desired - elapsed; | 1129 *timeout = desired - elapsed; |
| 1162 } | 1130 } |
| 1163 | 1131 |
| 1164 return SECSuccess; | 1132 return SECSuccess; |
| 1165 } | 1133 } |
| OLD | NEW |