118 #ifndef OPENSSL_NO_KRB5
127 #ifndef OPENSSL_NO_DH
131 static const SSL_METHOD *dtls1_get_client_method(
int ver);
132 static int dtls1_get_hello_verify(
SSL *s);
134 static const SSL_METHOD *dtls1_get_client_method(
int ver)
145 dtls1_get_client_method)
150 unsigned long Time=(
unsigned long)time(NULL);
153 int new_state,state,skip=0;
154 #ifndef OPENSSL_NO_SCTP
155 unsigned char sctpauthkey[64];
163 if (s->info_callback != NULL)
165 else if (s->ctx->info_callback != NULL)
166 cb=s->ctx->info_callback;
171 #ifndef OPENSSL_NO_SCTP
179 #ifndef OPENSSL_NO_HEARTBEATS
184 if (s->tlsext_hb_pending)
187 s->tlsext_hb_pending = 0;
201 s->ctx->stats.sess_connect_renegotiate++;
222 if (s->init_buf == NULL)
246 s->ctx->stats.sess_connect++;
249 memset(s->s3->client_random,0,
sizeof(s->s3->client_random));
250 s->d1->send_cookie = 0;
254 #ifndef OPENSSL_NO_SCTP
259 s->s3->in_read_app_data=2;
267 s->state=s->s3->tmp.next_state;
274 if (ret < 0)
goto end;
278 s->s3->in_read_app_data=2;
286 s->state=s->d1->next_state;
300 if (ret <= 0)
goto end;
302 if ( s->d1->send_cookie)
312 #ifndef OPENSSL_NO_SCTP
318 if (s->bbio != s->wbio)
320 #ifndef OPENSSL_NO_SCTP
329 if (ret <= 0)
goto end;
334 #ifndef OPENSSL_NO_SCTP
342 sizeof(sctpauthkey), labelbuffer,
343 sizeof(labelbuffer), NULL, 0, 0);
346 sizeof(sctpauthkey), sctpauthkey);
360 ret = dtls1_get_hello_verify(s);
364 if ( s->d1->send_cookie)
373 #ifndef OPENSSL_NO_TLSEXT
375 if (ret <= 0)
goto end;
379 if (s->tlsext_ticket_expected)
388 if (!(s->s3->tmp.new_cipher->algorithm_auth &
SSL_aNULL) &&
389 !(s->s3->tmp.new_cipher->algorithm_mkey &
SSL_kPSK))
392 if (ret <= 0)
goto end;
393 #ifndef OPENSSL_NO_TLSEXT
394 if (s->tlsext_status_expected)
417 if (ret <= 0)
goto end;
433 if (ret <= 0)
goto end;
441 if (ret <= 0)
goto end;
443 if (s->s3->tmp.cert_req)
449 #ifndef OPENSSL_NO_SCTP
455 s->state=s->s3->tmp.next_state;
464 if (ret <= 0)
goto end;
473 if (ret <= 0)
goto end;
475 #ifndef OPENSSL_NO_SCTP
483 sizeof(sctpauthkey), labelbuffer,
484 sizeof(labelbuffer), NULL, 0, 0);
487 sizeof(sctpauthkey), sctpauthkey);
494 if (s->s3->tmp.cert_req == 1)
500 #ifndef OPENSSL_NO_SCTP
509 s->s3->change_cipher_spec=0;
519 if (ret <= 0)
goto end;
520 #ifndef OPENSSL_NO_SCTP
530 s->s3->change_cipher_spec=0;
539 if (ret <= 0)
goto end;
541 #ifndef OPENSSL_NO_SCTP
551 s->session->cipher=s->s3->tmp.new_cipher;
552 #ifdef OPENSSL_NO_COMP
553 s->session->compress_meth=0;
555 if (s->s3->tmp.new_compression == NULL)
556 s->session->compress_meth=0;
558 s->session->compress_meth=
559 s->s3->tmp.new_compression->id;
561 if (!s->method->ssl3_enc->setup_key_block(s))
567 if (!s->method->ssl3_enc->change_cipher_state(s,
583 s->method->ssl3_enc->client_finished_label,
584 s->method->ssl3_enc->client_finished_label_len);
585 if (ret <= 0)
goto end;
593 #ifndef OPENSSL_NO_SCTP
596 s->d1->next_state = s->s3->tmp.next_state;
603 #ifndef OPENSSL_NO_SCTP
611 s->s3->delay_buf_pop_ret=0;
616 #ifndef OPENSSL_NO_TLSEXT
618 if (s->tlsext_ticket_expected)
628 #ifndef OPENSSL_NO_TLSEXT
632 if (ret <= 0)
goto end;
640 if (ret <= 0)
goto end;
648 s->d1->change_cipher_spec_ok = 1;
651 if (ret <= 0)
goto end;
659 #ifndef OPENSSL_NO_SCTP
663 s->d1->next_state=s->state;
679 s->state=s->s3->tmp.next_state;
686 s->state=s->s3->tmp.next_state;
694 if (s->init_buf != NULL)
712 if (s->hit) s->ctx->stats.sess_hit++;
717 s->ctx->stats.sess_connect_good++;
722 s->d1->handshake_read_seq = 0;
723 s->d1->next_handshake_write_seq = 0;
735 if (!s->s3->tmp.reuse_message && !skip)
743 if ((
cb != NULL) && (s->state != state))
756 #ifndef OPENSSL_NO_SCTP
776 unsigned long Time,l;
785 #ifdef OPENSSL_NO_TLSEXT
804 Time=(
unsigned long)time(NULL);
858 if (s->
ctx->comp_methods == NULL)
870 #ifndef OPENSSL_NO_TLSEXT
898 static int dtls1_get_hello_verify(
SSL *s)
902 unsigned int cookie_len;
911 if (!ok)
return((
int)n);
920 data = (
unsigned char *)s->
init_msg;
931 cookie_len = *(data++);
932 if ( cookie_len >
sizeof(s->
d1->
cookie))
938 memcpy(s->
d1->
cookie, data, cookie_len);
954 #ifndef OPENSSL_NO_RSA
958 #ifndef OPENSSL_NO_KRB5
961 #ifndef OPENSSL_NO_ECDH
963 const EC_POINT *srvr_ecpoint = NULL;
965 unsigned char *encodedPoint = NULL;
966 int encoded_pt_len = 0;
979 #ifndef OPENSSL_NO_RSA
990 if ((pkey == NULL) ||
1003 if (
RAND_bytes(&(tmp_buf[2]),
sizeof tmp_buf-2) <= 0)
1034 tmp_buf,
sizeof tmp_buf);
1038 #ifndef OPENSSL_NO_KRB5
1041 krb5_error_code krb5rc;
1044 krb5_data *enc_ticket;
1045 krb5_data authenticator, *authp = NULL;
1052 int padl, outl =
sizeof(epms);
1057 printf(
"ssl3_send_client_key_exchange(%lx & %lx)\n",
1073 printf(
"kssl_cget_tkt rtn %d\n", krb5rc);
1074 if (krb5rc && kssl_err.
text)
1075 printf(
"kssl_cget_tkt kssl_err=%s\n", kssl_err.
text);
1108 s2n(enc_ticket->length,p);
1109 memcpy(p, enc_ticket->data, enc_ticket->length);
1110 p+= enc_ticket->length;
1111 n = enc_ticket->length + 2;
1114 if (authp && authp->length)
1116 s2n(authp->length,p);
1117 memcpy(p, authp->data, authp->length);
1119 n+= authp->length + 2;
1141 memset(iv, 0,
sizeof iv);
1148 if (outl > (
int)
sizeof epms)
1157 memcpy(p, epms, outl);
1164 tmp_buf,
sizeof tmp_buf);
1170 #ifndef OPENSSL_NO_DH
1173 DH *dh_srvr,*dh_clnt;
1226 #ifndef OPENSSL_NO_ECDH
1231 int ecdh_clnt_cert = 0;
1271 if ((srvr_pub_pkey == NULL) ||
1273 (srvr_pub_pkey->
pkey.
ec == NULL))
1280 tkey = srvr_pub_pkey->
pkey.
ec;
1286 if ((srvr_group == NULL) || (srvr_ecpoint == NULL))
1313 if (priv_key == NULL)
1339 if (field_size <= 0)
1355 -> generate_master_secret(s,
1377 encodedPoint = (
unsigned char *)
1379 sizeof(
unsigned char));
1381 if ((encodedPoint == NULL) ||
1392 encodedPoint, encoded_pt_len, bn_ctx);
1398 memcpy((
unsigned char *)p, encodedPoint, n);
1406 if (clnt_ecdh != NULL)
1412 #ifndef OPENSSL_NO_PSK
1416 unsigned char *
t = NULL;
1418 unsigned int pre_ms_len = 0, psk_len = 0;
1431 psk_or_pre_ms,
sizeof(psk_or_pre_ms));
1438 else if (psk_len == 0)
1446 pre_ms_len = 2+psk_len+2+psk_len;
1448 memmove(psk_or_pre_ms+psk_len+4, psk_or_pre_ms, psk_len);
1450 memset(t, 0, psk_len);
1478 psk_or_pre_ms, pre_ms_len);
1479 n = strlen(identity);
1481 memcpy(p, identity, n);
1522 #ifndef OPENSSL_NO_ECDH
1525 if (clnt_ecdh != NULL)
1534 unsigned char *
p,*d;
1537 #ifndef OPENSSL_NO_RSA
1541 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)
1555 #ifndef OPENSSL_NO_RSA
1563 &(p[2]), &u, pkey->
pkey.
rsa) <= 0 )
1573 #ifndef OPENSSL_NO_DSA
1577 &(data[MD5_DIGEST_LENGTH]),
1579 (
unsigned int *)&j,pkey->
pkey.
dsa))
1589 #ifndef OPENSSL_NO_ECDSA
1593 &(data[MD5_DIGEST_LENGTH]),
1595 (
unsigned int *)&j,pkey->
pkey.
ec))
1614 s->
init_num=(int)n+DTLS1_HM_HEADER_LENGTH;
1638 if ((s->
cert == NULL) ||
1660 if ((i == 1) && (pkey != NULL) && (x509 != NULL))
1673 if (x509 != NULL) X509_free(x509);