125 #ifndef OPENSSL_NO_DH
129 static const SSL_METHOD *dtls1_get_server_method(
int ver);
130 static int dtls1_send_hello_verify_request(
SSL *s);
132 static const SSL_METHOD *dtls1_get_server_method(
int ver)
143 dtls1_get_server_method)
148 unsigned long Time=(
unsigned long)time(NULL);
152 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;
168 listen = s->d1->listen;
174 s->d1->listen = listen;
175 #ifndef OPENSSL_NO_SCTP
189 #ifndef OPENSSL_NO_HEARTBEATS
194 if (s->tlsext_hb_pending)
197 s->tlsext_hb_pending = 0;
227 if (s->init_buf == NULL)
256 #ifndef OPENSSL_NO_SCTP
263 s->ctx->stats.sess_accept++;
269 s->ctx->stats.sess_accept_renegotiate++;
281 if (ret <= 0)
goto end;
299 if (ret <= 0)
goto end;
312 memcpy(s->s3->write_sequence, s->s3->read_sequence,
sizeof(s->s3->write_sequence));
323 s->d1->handshake_read_seq = 2;
324 s->d1->handshake_write_seq = 1;
325 s->d1->next_handshake_write_seq = 1;
334 ret = dtls1_send_hello_verify_request(s);
335 if ( ret <= 0)
goto end;
344 #ifndef OPENSSL_NO_SCTP
349 s->s3->in_read_app_data=2;
362 if (ret < 0)
goto end;
368 s->s3->in_read_app_data=2;
377 s->state=s->d1->next_state;
386 if (ret <= 0)
goto end;
390 #ifndef OPENSSL_NO_SCTP
398 sizeof(sctpauthkey), labelbuffer,
399 sizeof(labelbuffer), NULL, 0, 0);
402 sizeof(sctpauthkey), sctpauthkey);
404 #ifndef OPENSSL_NO_TLSEXT
405 if (s->tlsext_ticket_expected)
421 if (!(s->s3->tmp.new_cipher->algorithm_auth &
SSL_aNULL)
422 && !(s->s3->tmp.new_cipher->algorithm_mkey &
SSL_kPSK))
426 if (ret <= 0)
goto end;
427 #ifndef OPENSSL_NO_TLSEXT
428 if (s->tlsext_status_expected)
450 alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
463 s->s3->tmp.use_rsa_tmp=1;
465 s->s3->tmp.use_rsa_tmp=0;
469 if (s->s3->tmp.use_rsa_tmp
472 #ifndef OPENSSL_NO_PSK
473 || ((alg_k &
SSL_kPSK) && s->ctx->psk_identity_hint)
488 if (ret <= 0)
goto end;
503 ((s->session->peer != NULL) &&
508 ((s->s3->tmp.new_cipher->algorithm_auth &
SSL_aNULL) &&
513 (s->s3->tmp.new_cipher->algorithm_auth &
SSL_aKRB5)
516 || (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK))
520 s->s3->tmp.cert_request=0;
522 #ifndef OPENSSL_NO_SCTP
532 s->s3->tmp.cert_request=1;
535 if (ret <= 0)
goto end;
536 #ifndef NETSCAPE_HANG_BUG
538 #ifndef OPENSSL_NO_SCTP
548 #ifndef OPENSSL_NO_SCTP
551 s->d1->next_state = s->s3->tmp.next_state;
564 if (ret <= 0)
goto end;
578 s->state=s->s3->tmp.next_state;
585 s->state=s->s3->tmp.next_state;
603 if (ret <= 0)
goto end;
612 if (ret <= 0)
goto end;
613 #ifndef OPENSSL_NO_SCTP
621 sizeof(sctpauthkey), labelbuffer,
622 sizeof(labelbuffer), NULL, 0, 0);
625 sizeof(sctpauthkey), sctpauthkey);
648 s->method->ssl3_enc->cert_verify_mac(s,
650 &(s->s3->tmp.cert_verify_md[0]));
651 s->method->ssl3_enc->cert_verify_mac(s,
660 s->d1->change_cipher_spec_ok = 1;
663 if (ret <= 0)
goto end;
664 #ifndef OPENSSL_NO_SCTP
676 s->d1->change_cipher_spec_ok = 1;
679 if (ret <= 0)
goto end;
683 #ifndef OPENSSL_NO_TLSEXT
684 else if (s->tlsext_ticket_expected)
692 #ifndef OPENSSL_NO_TLSEXT
696 if (ret <= 0)
goto end;
704 if (ret <= 0)
goto end;
714 s->session->cipher=s->s3->tmp.new_cipher;
715 if (!s->method->ssl3_enc->setup_key_block(s))
716 { ret= -1;
goto end; }
721 if (ret <= 0)
goto end;
723 #ifndef OPENSSL_NO_SCTP
733 if (!s->method->ssl3_enc->change_cipher_state(s,
747 s->method->ssl3_enc->server_finished_label,
748 s->method->ssl3_enc->server_finished_label_len);
749 if (ret <= 0)
goto end;
756 #ifndef OPENSSL_NO_SCTP
759 s->d1->next_state = s->s3->tmp.next_state;
781 if (s->renegotiate == 2)
788 s->ctx->stats.sess_accept_good++;
798 s->d1->handshake_read_seq = 0;
800 s->d1->handshake_write_seq = 0;
801 s->d1->next_handshake_write_seq = 0;
812 if (!s->s3->tmp.reuse_message && !skip)
821 if ((
cb != NULL) && (s->state != state))
835 #ifndef OPENSSL_NO_SCTP
870 int dtls1_send_hello_verify_request(
SSL *s)
872 unsigned int msg_len;
873 unsigned char *msg, *buf, *
p;
915 unsigned long l,Time;
921 Time=(
unsigned long)time(NULL);
962 #ifdef OPENSSL_NO_COMP
971 #ifndef OPENSSL_NO_TLSEXT
1024 #ifndef OPENSSL_NO_RSA
1031 #ifndef OPENSSL_NO_DH
1034 #ifndef OPENSSL_NO_ECDH
1035 EC_KEY *ecdh=NULL, *ecdhp;
1036 unsigned char *encodedPoint = NULL;
1042 unsigned char *
p,*d;
1060 r[0]=r[1]=r[2]=r[3]=NULL;
1062 #ifndef OPENSSL_NO_RSA
1092 #ifndef OPENSSL_NO_DH
1121 if ((dhp->pub_key == NULL ||
1122 dhp->priv_key == NULL ||
1149 #ifndef OPENSSL_NO_ECDH
1235 encodedPoint = (
unsigned char *)
1238 if ((encodedPoint == NULL) || (bn_ctx == NULL))
1248 encodedPoint, encodedlen, bn_ctx);
1250 if (encodedlen == 0)
1276 #ifndef OPENSSL_NO_PSK
1289 for (i=0; r[i] != NULL; i++)
1318 p= &(d[DTLS1_HM_HEADER_LENGTH]);
1320 for (i=0; r[i] != NULL; i++)
1327 #ifndef OPENSSL_NO_ECDH
1328 if (type & SSL_kEECDH)
1344 memcpy((
unsigned char*)p,
1345 (
unsigned char *)encodedPoint,
1352 #ifndef OPENSSL_NO_PSK
1353 if (type & SSL_kPSK)
1368 #ifndef OPENSSL_NO_RSA
1373 for (num=2; num > 0; num--)
1381 (
unsigned int *)&i);
1386 &(p[2]), &u, pkey->
pkey.
rsa) <= 0)
1396 #if !defined(OPENSSL_NO_DSA)
1405 (
unsigned int *)&i,pkey))
1415 #if !defined(OPENSSL_NO_ECDSA)
1424 (
unsigned int *)&i,pkey))
1460 #ifndef OPENSSL_NO_ECDH
1470 unsigned char *
p,*d;
1475 unsigned int msg_len;
1481 d=p=(
unsigned char *)&(buf->
data[DTLS1_HM_HEADER_LENGTH]);
1494 sk=SSL_get_client_CA_list(s);
1501 j=i2d_X509_NAME(name,NULL);
1507 p=(
unsigned char *)&(buf->
data[DTLS1_HM_HEADER_LENGTH+n]);
1511 i2d_X509_NAME(name,&p);
1518 i2d_X509_NAME(name,&p);
1519 j-=2;
s2n(j,d); j+=2;
1526 p=(
unsigned char *)&(buf->
data[DTLS1_HM_HEADER_LENGTH+off]);
1529 d=(
unsigned char *)buf->
data;
1540 #ifdef NETSCAPE_HANG_BUG
1601 #ifndef OPENSSL_NO_TLSEXT
1606 unsigned char *
p, *senc, *macstart;
1608 unsigned int hlen, msg_len;
1613 unsigned char key_name[16];
1639 p=(
unsigned char *)&(s->
init_buf->
data[DTLS1_HM_HEADER_LENGTH]);
1669 memcpy(p, key_name, 16);
1690 p=(
unsigned char *)&(s->
init_buf->
data[DTLS1_HM_HEADER_LENGTH]) + 4;
1691 s2n(len - DTLS1_HM_HEADER_LENGTH - 6, p);