120 static int do_ssl3_write(
SSL *s,
int type,
const unsigned char *buf,
121 unsigned int len,
int create_empty_fragment);
122 static int ssl3_get_record(
SSL *s);
138 if (n <= 0)
return n;
146 #if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0
162 && (pkt[3]<<8|pkt[4]) >= 128)
171 memmove (rb->
buf+align,pkt,left);
185 if (left > 0 && n > left)
207 memmove(pkt, s->
packet, len+left);
284 static int ssl3_get_record(
SSL *s)
286 int ssl_major,ssl_minor,al;
287 int enc_err,n,i,ret= -1;
296 int decryption_failed_or_bad_record_mac = 0;
297 unsigned char *mac = NULL;
320 if (n <= 0)
return(n);
329 version=(ssl_major<<8)|ssl_minor;
332 fprintf(stderr,
"Record type=%d, Length=%d\n", rr->
type, rr->
length);
341 if ((s->
version & 0xFF00) == (version & 0xFF00))
343 s->
version = (
unsigned short)version;
372 if (n <= 0)
return(n);
416 decryption_failed_or_bad_record_mac = 1;
420 printf(
"dec %d\n",rr->
length);
421 {
unsigned int z;
for (z=0; z<rr->
length; z++) printf(
"%02X%c",rr->
data[z],((z+1)%16)?
' ':
'\n'); }
426 if ( (sess == NULL) ||
444 decryption_failed_or_bad_record_mac = 1;
448 if (rr->
length >= (
unsigned int)mac_size)
461 decryption_failed_or_bad_record_mac = 1;
466 if (i < 0 || mac == NULL || memcmp(md, mac, (
size_t)mac_size) != 0)
468 decryption_failed_or_bad_record_mac = 1;
472 if (decryption_failed_or_bad_record_mac)
521 if (rr->
length == 0)
goto again;
524 fprintf(stderr,
"Ultimate Record type=%d, Length=%d\n", rr->
type, rr->
length);
537 #ifndef OPENSSL_NO_COMP
555 #ifndef OPENSSL_NO_COMP
578 const unsigned char *buf=buf_;
579 unsigned int tot,n,nw;
589 if (i < 0)
return(i);
605 i=do_ssl3_write(s, type, &(buf[tot]), nw, 0);
628 static int do_ssl3_write(
SSL *s,
int type,
const unsigned char *buf,
629 unsigned int len,
int create_empty_fragment)
631 unsigned char *
p,*plen;
632 int i,mac_size,clear=0;
658 if (len == 0 && !create_empty_fragment)
664 if ( (sess == NULL) ||
694 prefix_len = do_ssl3_write(s, type, buf, 0, 1);
710 if (create_empty_fragment)
712 #if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0
729 #if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0
777 wr->
input=(
unsigned char *)buf;
830 if (create_empty_fragment)
878 (
unsigned int)wb->
left);
941 void (*
cb)(
const SSL *ssl,
int type2,
int val)=NULL;
958 unsigned char *dst = buf;
981 if (i < 0)
return(i);
1000 ret=ssl3_get_record(s);
1001 if (ret <= 0)
return(ret);
1025 if (type == rr->
type)
1037 if (len <= 0)
return(len);
1039 if ((
unsigned int)len > rr->
length)
1042 n = (
unsigned int)len;
1044 memcpy(buf,&(rr->
data[rr->
off]),n);
1068 unsigned int dest_maxlen = 0;
1069 unsigned char *dest = NULL;
1070 unsigned int *dest_len = NULL;
1084 #ifndef OPENSSL_NO_HEARTBEATS
1098 if (dest_maxlen > 0)
1100 n = dest_maxlen - *dest_len;
1107 dest[(*dest_len)++] = rr->
data[rr->
off++];
1111 if (*dest_len < dest_maxlen)
1148 if (i < 0)
return(i);
1213 j = (alert_level << 8) | alert_descr;
1217 if (alert_level == 1)
1240 #ifdef SSL_AD_MISSING_SRP_USERNAME
1241 if (alert_descr == SSL_AD_MISSING_SRP_USERNAME)
1245 else if (alert_level == 2)
1279 if ( (rr->
length != 1) || (rr->
off != 0) ||
1326 if (i < 0)
return(i);
1355 #ifndef OPENSSL_NO_TLS
1469 if (desc < 0)
return -1;
1471 if ((level == 2) && (s->
session != NULL))