1/* ssl/d1_both.c */ 2/* 3 * DTLS implementation written by Nagendra Modadugu 4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. 5 */ 6/* ==================================================================== 7 * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. 8 * --- 505 unchanged lines hidden (view full) --- 514 item = pqueue_peek(s->d1->buffered_messages); 515 if ( item == NULL) 516 return 0; 517 518 frag = (hm_fragment *)item->data; 519 520 if ( s->d1->handshake_read_seq == frag->msg_header.seq) 521 { |
522 unsigned long frag_len = frag->msg_header.frag_len; |
523 pqueue_pop(s->d1->buffered_messages); 524 525 al=dtls1_preprocess_fragment(s,&frag->msg_header,max); 526 527 if (al==0) /* no alert */ 528 { 529 unsigned char *p = (unsigned char *)s->init_buf->data+DTLS1_HM_HEADER_LENGTH; 530 memcpy(&p[frag->msg_header.frag_off], 531 frag->fragment,frag->msg_header.frag_len); 532 } 533 534 dtls1_hm_fragment_free(frag); 535 pitem_free(item); 536 537 if (al==0) 538 { 539 *ok = 1; |
540 return frag_len; |
541 } 542 543 ssl3_send_alert(s,SSL3_AL_FATAL,al); 544 s->init_num = 0; 545 *ok = 0; 546 return -1; 547 } 548 else --- 8 unchanged lines hidden (view full) --- 557 hm_fragment *frag = NULL; 558 pitem *item = NULL; 559 PQ_64BIT seq64; 560 unsigned long frag_len = msg_hdr->frag_len; 561 562 if ((msg_hdr->frag_off+frag_len) > msg_hdr->msg_len) 563 goto err; 564 |
565 /* Try to find item in queue, to prevent duplicate entries */ 566 pq_64bit_init(&seq64); 567 pq_64bit_assign_word(&seq64, msg_hdr->seq); 568 item = pqueue_find(s->d1->buffered_messages, seq64); 569 pq_64bit_free(&seq64); 570 571 /* Discard the message if sequence number was already there, is 572 * too far in the future or the fragment is already in the queue */ 573 if (msg_hdr->seq <= s->d1->handshake_read_seq || 574 msg_hdr->seq > s->d1->handshake_read_seq + 10 || item != NULL) |
575 { 576 unsigned char devnull [256]; 577 578 while (frag_len) 579 { 580 i = s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE, 581 devnull, 582 frag_len>sizeof(devnull)?sizeof(devnull):frag_len,0); 583 if (i<=0) goto err; 584 frag_len -= i; 585 } 586 } 587 |
588 if (frag_len) 589 { 590 frag = dtls1_hm_fragment_new(frag_len); 591 if ( frag == NULL) 592 goto err; |
593 |
594 memcpy(&(frag->msg_header), msg_hdr, sizeof(*msg_hdr)); |
595 |
596 /* read the body of the fragment (header has already been read) */ |
597 i = s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE, 598 frag->fragment,frag_len,0); 599 if (i<=0 || (unsigned long)i!=frag_len) 600 goto err; |
601 |
602 pq_64bit_init(&seq64); 603 pq_64bit_assign_word(&seq64, msg_hdr->seq); |
604 |
605 item = pitem_new(seq64, frag); 606 pq_64bit_free(&seq64); 607 if ( item == NULL) 608 goto err; |
609 |
610 pqueue_insert(s->d1->buffered_messages, item); 611 } 612 |
613 return DTLS1_HM_FRAGMENT_RETRY; 614 615err: 616 if ( frag != NULL) dtls1_hm_fragment_free(frag); 617 if ( item != NULL) OPENSSL_free(item); 618 *ok = 0; 619 return i; 620 } --- 584 unchanged lines hidden --- |