summaryrefslogtreecommitdiff
path: root/src/lib/libssl/s3_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/s3_lib.c')
-rw-r--r--src/lib/libssl/s3_lib.c88
1 files changed, 64 insertions, 24 deletions
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c
index cee2021b6b..c32c06de32 100644
--- a/src/lib/libssl/s3_lib.c
+++ b/src/lib/libssl/s3_lib.c
@@ -55,6 +55,59 @@
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58/* ====================================================================
59 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
58 111
59#include <stdio.h> 112#include <stdio.h>
60#include <openssl/md5.h> 113#include <openssl/md5.h>
@@ -638,10 +691,9 @@ SSL_CIPHER *ssl3_get_cipher(unsigned int u)
638 return(NULL); 691 return(NULL);
639 } 692 }
640 693
641/* The problem is that it may not be the correct record type */
642int ssl3_pending(SSL *s) 694int ssl3_pending(SSL *s)
643 { 695 {
644 return(s->s3->rrec.length); 696 return (s->s3->rrec.type == SSL3_RT_APPLICATION_DATA) ? s->s3->rrec.length : 0;
645 } 697 }
646 698
647int ssl3_new(SSL *s) 699int ssl3_new(SSL *s)
@@ -1189,7 +1241,7 @@ int ssl3_shutdown(SSL *s)
1189 else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN)) 1241 else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN))
1190 { 1242 {
1191 /* If we are waiting for a close from our peer, we are closed */ 1243 /* If we are waiting for a close from our peer, we are closed */
1192 ssl3_read_bytes(s,0,NULL,0); 1244 ssl3_read_bytes(s,0,NULL,0,0);
1193 } 1245 }
1194 1246
1195 if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) && 1247 if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) &&
@@ -1252,14 +1304,14 @@ int ssl3_write(SSL *s, const void *buf, int len)
1252 return(ret); 1304 return(ret);
1253 } 1305 }
1254 1306
1255int ssl3_read(SSL *s, void *buf, int len) 1307static int ssl3_read_internal(SSL *s, void *buf, int len, int peek)
1256 { 1308 {
1257 int ret; 1309 int ret;
1258 1310
1259 clear_sys_error(); 1311 clear_sys_error();
1260 if (s->s3->renegotiate) ssl3_renegotiate_check(s); 1312 if (s->s3->renegotiate) ssl3_renegotiate_check(s);
1261 s->s3->in_read_app_data=1; 1313 s->s3->in_read_app_data=1;
1262 ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len); 1314 ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek);
1263 if ((ret == -1) && (s->s3->in_read_app_data == 0)) 1315 if ((ret == -1) && (s->s3->in_read_app_data == 0))
1264 { 1316 {
1265 /* ssl3_read_bytes decided to call s->handshake_func, which 1317 /* ssl3_read_bytes decided to call s->handshake_func, which
@@ -1269,7 +1321,7 @@ int ssl3_read(SSL *s, void *buf, int len)
1269 * by resetting 'in_read_app_data', strangely); so disable 1321 * by resetting 'in_read_app_data', strangely); so disable
1270 * handshake processing and try to read application data again. */ 1322 * handshake processing and try to read application data again. */
1271 s->in_handshake++; 1323 s->in_handshake++;
1272 ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len); 1324 ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek);
1273 s->in_handshake--; 1325 s->in_handshake--;
1274 } 1326 }
1275 else 1327 else
@@ -1278,26 +1330,14 @@ int ssl3_read(SSL *s, void *buf, int len)
1278 return(ret); 1330 return(ret);
1279 } 1331 }
1280 1332
1281int ssl3_peek(SSL *s, char *buf, int len) 1333int ssl3_read(SSL *s, void *buf, int len)
1282 { 1334 {
1283 SSL3_RECORD *rr; 1335 return ssl3_read_internal(s, buf, len, 0);
1284 int n; 1336 }
1285
1286 rr= &(s->s3->rrec);
1287 if ((rr->length == 0) || (rr->type != SSL3_RT_APPLICATION_DATA))
1288 {
1289 n=ssl3_read(s,buf,1);
1290 if (n <= 0) return(n);
1291 rr->length++;
1292 rr->off--;
1293 }
1294 1337
1295 if ((unsigned int)len > rr->length) 1338int ssl3_peek(SSL *s, void *buf, int len)
1296 n=rr->length; 1339 {
1297 else 1340 return ssl3_read_internal(s, buf, len, 1);
1298 n=len;
1299 memcpy(buf,&(rr->data[rr->off]),(unsigned int)n);
1300 return(n);
1301 } 1341 }
1302 1342
1303int ssl3_renegotiate(SSL *s) 1343int ssl3_renegotiate(SSL *s)