diff options
author | jsing <> | 2017-01-25 06:13:02 +0000 |
---|---|---|
committer | jsing <> | 2017-01-25 06:13:02 +0000 |
commit | 994be17488e885953ca1fef89bbc4d5fb24eba71 (patch) | |
tree | fa8c6cb9fb6d55c7422e8539eed63d9c115a282d /src/lib/libssl/s3_pkt.c | |
parent | 0bc052b366fc7f6e3f38271d4294ce4217f86f4d (diff) | |
download | openbsd-994be17488e885953ca1fef89bbc4d5fb24eba71.tar.gz openbsd-994be17488e885953ca1fef89bbc4d5fb24eba71.tar.bz2 openbsd-994be17488e885953ca1fef89bbc4d5fb24eba71.zip |
Provide ssl3_packet_read() and ssl3_packet_extend() functions that improve
the awkward API provided by ssl3_read_n(). Call these when we need to
read or extend a packet.
ok beck@
Diffstat (limited to 'src/lib/libssl/s3_pkt.c')
-rw-r--r-- | src/lib/libssl/s3_pkt.c | 58 |
1 files changed, 44 insertions, 14 deletions
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 | */ |
133 | int | 133 | static int |
134 | ssl3_read_n(SSL *s, int n, int max, int extend) | 134 | ssl3_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 | ||
270 | int | ||
271 | ssl3_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 | |||
284 | int | ||
285 | ssl3_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 |