OLD | NEW |
1 /* | 1 /* |
2 * Gather (Read) entire SSL3 records from socket into buffer. | 2 * Gather (Read) entire SSL3 records from socket into buffer. |
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 18 matching lines...) Expand all Loading... |
29 * in which case the provisions of the GPL or the LGPL are applicable instead | 29 * in which case the provisions of the GPL or the LGPL are applicable instead |
30 * of those above. If you wish to allow use of your version of this file only | 30 * of those above. If you wish to allow use of your version of this file only |
31 * under the terms of either the GPL or the LGPL, and not to allow others to | 31 * under the terms of either the GPL or the LGPL, and not to allow others to |
32 * use your version of this file under the terms of the MPL, indicate your | 32 * use your version of this file under the terms of the MPL, indicate your |
33 * decision by deleting the provisions above and replace them with the notice | 33 * decision by deleting the provisions above and replace them with the notice |
34 * and other provisions required by the GPL or the LGPL. If you do not delete | 34 * and other provisions required by the GPL or the LGPL. If you do not delete |
35 * the provisions above, a recipient may use your version of this file under | 35 * the provisions above, a recipient may use your version of this file under |
36 * the terms of any one of the MPL, the GPL or the LGPL. | 36 * the terms of any one of the MPL, the GPL or the LGPL. |
37 * | 37 * |
38 * ***** END LICENSE BLOCK ***** */ | 38 * ***** END LICENSE BLOCK ***** */ |
39 /* $Id: ssl3gthr.c,v 1.9.20.1 2010/07/31 04:33:52 wtc%google.com Exp $ */ | 39 /* $Id: ssl3gthr.c,v 1.12 2012/02/11 12:57:28 kaie%kuix.de Exp $ */ |
40 | 40 |
41 #include "cert.h" | 41 #include "cert.h" |
42 #include "ssl.h" | 42 #include "ssl.h" |
43 #include "sslimpl.h" | 43 #include "sslimpl.h" |
44 #include "ssl3prot.h" | 44 #include "ssl3prot.h" |
45 | 45 |
46 /* | 46 /* |
47 * Attempt to read in an entire SSL3 record. | 47 * Attempt to read in an entire SSL3 record. |
48 * Blocks here for blocking sockets, otherwise returns -1 with | 48 * Blocks here for blocking sockets, otherwise returns -1 with |
49 * PR_WOULD_BLOCK_ERROR when socket would block. | 49 * PR_WOULD_BLOCK_ERROR when socket would block. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 */ | 185 */ |
186 int | 186 int |
187 ssl3_GatherCompleteHandshake(sslSocket *ss, int flags) | 187 ssl3_GatherCompleteHandshake(sslSocket *ss, int flags) |
188 { | 188 { |
189 SSL3Ciphertext cText; | 189 SSL3Ciphertext cText; |
190 int rv; | 190 int rv; |
191 PRBool canFalseStart = PR_FALSE; | 191 PRBool canFalseStart = PR_FALSE; |
192 | 192 |
193 PORT_Assert( ss->opt.noLocks || ssl_HaveRecvBufLock(ss) ); | 193 PORT_Assert( ss->opt.noLocks || ssl_HaveRecvBufLock(ss) ); |
194 do { | 194 do { |
195 » /* bring in the next sslv3 record. */ | 195 » /* Without this, we may end up wrongly reporting |
196 » rv = ssl3_GatherData(ss, &ss->gs, flags); | 196 » * SSL_ERROR_RX_UNEXPECTED_* errors if we receive any records from the |
197 » if (rv <= 0) { | 197 » * peer while we are waiting to be restarted. |
198 » return rv; | 198 » */ |
| 199 » ssl_GetSSL3HandshakeLock(ss); |
| 200 » rv = ss->ssl3.hs.restartTarget == NULL ? SECSuccess : SECFailure; |
| 201 » ssl_ReleaseSSL3HandshakeLock(ss); |
| 202 » if (rv != SECSuccess) { |
| 203 » PORT_SetError(PR_WOULD_BLOCK_ERROR); |
| 204 » return (int) SECFailure; |
199 } | 205 } |
200 » | 206 |
201 » /* decipher it, and handle it if it's a handshake. | 207 » /* Treat an empty msgState like a NULL msgState. (Most of the time |
202 » * If it's application data, ss->gs.buf will not be empty upon return. | 208 » * when ssl3_HandleHandshake returns SECWouldBlock, it leaves |
203 » * If it's a change cipher spec, alert, or handshake message, | 209 » * behind a non-NULL but zero-length msgState). |
204 » * ss->gs.buf.len will be 0 when ssl3_HandleRecord returns SECSuccess. | 210 » * Test: async_cert_restart_server_sends_hello_request_first_in_separate
_record |
205 */ | 211 */ |
206 » cText.type = (SSL3ContentType)ss->gs.hdr[0]; | 212 » if (ss->ssl3.hs.msgState.buf != NULL) { |
207 » cText.version = (ss->gs.hdr[1] << 8) | ss->gs.hdr[2]; | 213 » if (ss->ssl3.hs.msgState.len == 0) { |
208 » cText.buf = &ss->gs.inbuf; | 214 » » ss->ssl3.hs.msgState.buf = NULL; |
209 » rv = ssl3_HandleRecord(ss, &cText, &ss->gs.buf); | 215 » } |
| 216 » } |
| 217 |
| 218 » if (ss->ssl3.hs.msgState.buf != NULL) { |
| 219 » /* ssl3_HandleHandshake previously returned SECWouldBlock and the |
| 220 » * as-yet-unprocessed plaintext of that previous handshake record. |
| 221 » * We need to process it now before we overwrite it with the next |
| 222 » * handshake record. |
| 223 » */ |
| 224 » rv = ssl3_HandleRecord(ss, NULL, &ss->gs.buf); |
| 225 » } else { |
| 226 » /* bring in the next sslv3 record. */ |
| 227 » rv = ssl3_GatherData(ss, &ss->gs, flags); |
| 228 » if (rv <= 0) { |
| 229 » » return rv; |
| 230 » } |
| 231 |
| 232 » /* decipher it, and handle it if it's a handshake. |
| 233 » * If it's application data, ss->gs.buf will not be empty upon retur
n. |
| 234 » * If it's a change cipher spec, alert, or handshake message, |
| 235 » * ss->gs.buf.len will be 0 when ssl3_HandleRecord returns SECSucces
s. |
| 236 » */ |
| 237 » cText.type = (SSL3ContentType)ss->gs.hdr[0]; |
| 238 » cText.version = (ss->gs.hdr[1] << 8) | ss->gs.hdr[2]; |
| 239 » cText.buf = &ss->gs.inbuf; |
| 240 » rv = ssl3_HandleRecord(ss, &cText, &ss->gs.buf); |
| 241 » } |
210 if (rv < 0) { | 242 if (rv < 0) { |
211 return ss->recvdCloseNotify ? 0 : rv; | 243 return ss->recvdCloseNotify ? 0 : rv; |
212 } | 244 } |
213 | 245 |
214 /* If we kicked off a false start in ssl3_HandleServerHelloDone, break | 246 /* If we kicked off a false start in ssl3_HandleServerHelloDone, break |
215 * out of this loop early without finishing the handshake. | 247 * out of this loop early without finishing the handshake. |
216 */ | 248 */ |
217 if (ss->opt.enableFalseStart) { | 249 if (ss->opt.enableFalseStart) { |
218 ssl_GetSSL3HandshakeLock(ss); | 250 ssl_GetSSL3HandshakeLock(ss); |
219 canFalseStart = (ss->ssl3.hs.ws == wait_change_cipher || | 251 canFalseStart = (ss->ssl3.hs.ws == wait_change_cipher || |
(...skipping 26 matching lines...) Expand all Loading... |
246 { | 278 { |
247 int rv; | 279 int rv; |
248 | 280 |
249 PORT_Assert( ss->opt.noLocks || ssl_HaveRecvBufLock(ss) ); | 281 PORT_Assert( ss->opt.noLocks || ssl_HaveRecvBufLock(ss) ); |
250 do { | 282 do { |
251 rv = ssl3_GatherCompleteHandshake(ss, flags); | 283 rv = ssl3_GatherCompleteHandshake(ss, flags); |
252 } while (rv > 0 && ss->gs.buf.len == 0); | 284 } while (rv > 0 && ss->gs.buf.len == 0); |
253 | 285 |
254 return rv; | 286 return rv; |
255 } | 287 } |
OLD | NEW |