summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libssl/d1_pkt.c31
-rw-r--r--src/lib/libssl/s3_pkt.c58
-rw-r--r--src/lib/libssl/ssl_locl.h5
3 files changed, 59 insertions, 35 deletions
diff --git a/src/lib/libssl/d1_pkt.c b/src/lib/libssl/d1_pkt.c
index f15b64364e..19853d2375 100644
--- a/src/lib/libssl/d1_pkt.c
+++ b/src/lib/libssl/d1_pkt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d1_pkt.c,v 1.58 2017/01/23 14:35:42 jsing Exp $ */ 1/* $OpenBSD: d1_pkt.c,v 1.59 2017/01/25 06:13:02 jsing Exp $ */
2/* 2/*
3 * DTLS implementation written by Nagendra Modadugu 3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. 4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -469,11 +469,11 @@ err:
469int 469int
470dtls1_get_record(SSL *s) 470dtls1_get_record(SSL *s)
471{ 471{
472 int i, n;
473 SSL3_RECORD *rr; 472 SSL3_RECORD *rr;
474 unsigned char *p = NULL; 473 unsigned char *p = NULL;
475 DTLS1_BITMAP *bitmap; 474 DTLS1_BITMAP *bitmap;
476 unsigned int is_next_epoch; 475 unsigned int is_next_epoch;
476 int n;
477 477
478 rr = &(S3I(s)->rrec); 478 rr = &(S3I(s)->rrec);
479 479
@@ -501,13 +501,12 @@ again:
501 uint16_t epoch, len, ssl_version; 501 uint16_t epoch, len, ssl_version;
502 uint8_t type; 502 uint8_t type;
503 503
504 n = ssl3_read_n(s, DTLS1_RT_HEADER_LENGTH, s->s3->rbuf.len, 0); 504 n = ssl3_packet_read(s, DTLS1_RT_HEADER_LENGTH);
505 /* read timeout is handled by dtls1_read_bytes */
506 if (n <= 0) 505 if (n <= 0)
507 return(n); /* error or non-blocking */ 506 return (n);
508 507
509 /* this packet contained a partial record, dump it */ 508 /* If this packet contained a partial record, dump it. */
510 if (s->internal->packet_length != DTLS1_RT_HEADER_LENGTH) 509 if (n != DTLS1_RT_HEADER_LENGTH)
511 goto again; 510 goto again;
512 511
513 s->internal->rstate = SSL_ST_READ_BODY; 512 s->internal->rstate = SSL_ST_READ_BODY;
@@ -553,20 +552,14 @@ again:
553 552
554 /* s->internal->rstate == SSL_ST_READ_BODY, get and decode the data */ 553 /* s->internal->rstate == SSL_ST_READ_BODY, get and decode the data */
555 554
556 if (rr->length > s->internal->packet_length - DTLS1_RT_HEADER_LENGTH) { 555 n = ssl3_packet_extend(s, DTLS1_RT_HEADER_LENGTH + rr->length);
557 /* now s->internal->packet_length == DTLS1_RT_HEADER_LENGTH */ 556 if (n <= 0)
558 i = rr->length; 557 return (n);
559 n = ssl3_read_n(s, i, i, 1);
560 if (n <= 0)
561 return(n); /* error or non-blocking io */
562 558
563 /* this packet contained a partial record, dump it */ 559 /* If this packet contained a partial record, dump it. */
564 if (n != i) 560 if (n != DTLS1_RT_HEADER_LENGTH + rr->length)
565 goto again; 561 goto again;
566 562
567 /* now n == rr->length,
568 * and s->internal->packet_length == DTLS1_RT_HEADER_LENGTH + rr->length */
569 }
570 s->internal->rstate = SSL_ST_READ_HEADER; /* set state for later operations */ 563 s->internal->rstate = SSL_ST_READ_HEADER; /* set state for later operations */
571 564
572 /* match epochs. NULL means the packet is dropped on the floor */ 565 /* match epochs. NULL means the packet is dropped on the floor */
diff --git a/src/lib/libssl/s3_pkt.c b/src/lib/libssl/s3_pkt.c
index a9737a7f40..152e384a4b 100644
--- a/src/lib/libssl/s3_pkt.c
+++ b/src/lib/libssl/s3_pkt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_pkt.c,v 1.68 2017/01/23 14:35:42 jsing Exp $ */ 1/* $OpenBSD: s3_pkt.c,v 1.69 2017/01/25 06:13:02 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -130,7 +130,7 @@ static int ssl3_get_record(SSL *s);
130 * (If s->internal->read_ahead is set, 'max' bytes may be stored in rbuf 130 * (If s->internal->read_ahead is set, 'max' bytes may be stored in rbuf
131 * [plus s->internal->packet_length bytes if extend == 1].) 131 * [plus s->internal->packet_length bytes if extend == 1].)
132 */ 132 */
133int 133static int
134ssl3_read_n(SSL *s, int n, int max, int extend) 134ssl3_read_n(SSL *s, int n, int max, int extend)
135{ 135{
136 int i, len, left; 136 int i, len, left;
@@ -263,9 +263,42 @@ ssl3_read_n(SSL *s, int n, int max, int extend)
263 rb->left = left - n; 263 rb->left = left - n;
264 s->internal->packet_length += n; 264 s->internal->packet_length += n;
265 s->internal->rwstate = SSL_NOTHING; 265 s->internal->rwstate = SSL_NOTHING;
266
266 return (n); 267 return (n);
267} 268}
268 269
270int
271ssl3_packet_read(SSL *s, int plen)
272{
273 int n;
274
275 n = ssl3_read_n(s, plen, s->s3->rbuf.len, 0);
276 if (n <= 0)
277 return n;
278 if (s->internal->packet_length < plen)
279 return s->internal->packet_length;
280
281 return plen;
282}
283
284int
285ssl3_packet_extend(SSL *s, int plen)
286{
287 int rlen, n;
288
289 if (s->internal->packet_length >= plen)
290 return plen;
291 rlen = plen - s->internal->packet_length;
292
293 n = ssl3_read_n(s, rlen, rlen, 1);
294 if (n <= 0)
295 return n;
296 if (s->internal->packet_length < plen)
297 return s->internal->packet_length;
298
299 return plen;
300}
301
269/* Call this to get a new input record. 302/* Call this to get a new input record.
270 * It will return <= 0 if more data is needed, normally due to an error 303 * It will return <= 0 if more data is needed, normally due to an error
271 * or non-blocking IO. 304 * or non-blocking IO.
@@ -296,9 +329,10 @@ again:
296 uint16_t len, ssl_version; 329 uint16_t len, ssl_version;
297 uint8_t type; 330 uint8_t type;
298 331
299 n = ssl3_read_n(s, SSL3_RT_HEADER_LENGTH, s->s3->rbuf.len, 0); 332 n = ssl3_packet_read(s, SSL3_RT_HEADER_LENGTH);
300 if (n <= 0) 333 if (n <= 0)
301 return(n); /* error or non-blocking */ 334 return (n);
335
302 s->internal->rstate = SSL_ST_READ_BODY; 336 s->internal->rstate = SSL_ST_READ_BODY;
303 337
304 CBS_init(&header, s->internal->packet, n); 338 CBS_init(&header, s->internal->packet, n);
@@ -345,17 +379,13 @@ again:
345 379
346 /* s->internal->rstate == SSL_ST_READ_BODY, get and decode the data */ 380 /* s->internal->rstate == SSL_ST_READ_BODY, get and decode the data */
347 381
348 if (rr->length > s->internal->packet_length - SSL3_RT_HEADER_LENGTH) { 382 n = ssl3_packet_extend(s, SSL3_RT_HEADER_LENGTH + rr->length);
349 /* now s->internal->packet_length == SSL3_RT_HEADER_LENGTH */ 383 if (n <= 0)
350 i = rr->length; 384 return (n);
351 n = ssl3_read_n(s, i, i, 1); 385 if (n != SSL3_RT_HEADER_LENGTH + rr->length)
352 if (n <= 0) 386 return (n);
353 return(n); /* error or non-blocking io */
354 /* now n == rr->length,
355 * and s->internal->packet_length == SSL3_RT_HEADER_LENGTH + rr->length */
356 }
357 387
358 s->internal->rstate=SSL_ST_READ_HEADER; /* set state for later operations */ 388 s->internal->rstate = SSL_ST_READ_HEADER; /* set state for later operations */
359 389
360 /* At this point, s->internal->packet_length == SSL3_RT_HEADER_LNGTH + rr->length, 390 /* At this point, s->internal->packet_length == SSL3_RT_HEADER_LNGTH + rr->length,
361 * and we have that many bytes in s->internal->packet 391 * and we have that many bytes in s->internal->packet
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h
index 0cda709da6..9cad2bc50d 100644
--- a/src/lib/libssl/ssl_locl.h
+++ b/src/lib/libssl/ssl_locl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_locl.h,v 1.164 2017/01/24 09:03:21 jsing Exp $ */ 1/* $OpenBSD: ssl_locl.h,v 1.165 2017/01/25 06:13:02 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -1198,7 +1198,8 @@ long ssl23_default_timeout(void);
1198 1198
1199long tls1_default_timeout(void); 1199long tls1_default_timeout(void);
1200int dtls1_do_write(SSL *s, int type); 1200int dtls1_do_write(SSL *s, int type);
1201int ssl3_read_n(SSL *s, int n, int max, int extend); 1201int ssl3_packet_read(SSL *s, int plen);
1202int ssl3_packet_extend(SSL *s, int plen);
1202int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek); 1203int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek);
1203int ssl3_write_pending(SSL *s, int type, const unsigned char *buf, 1204int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
1204 unsigned int len); 1205 unsigned int len);