diff options
Diffstat (limited to 'src/lib/libssl/d1_clnt.c')
| -rw-r--r-- | src/lib/libssl/d1_clnt.c | 194 |
1 files changed, 184 insertions, 10 deletions
diff --git a/src/lib/libssl/d1_clnt.c b/src/lib/libssl/d1_clnt.c index 089fa4c7f8..a6ed09c51d 100644 --- a/src/lib/libssl/d1_clnt.c +++ b/src/lib/libssl/d1_clnt.c | |||
| @@ -150,7 +150,11 @@ int dtls1_connect(SSL *s) | |||
| 150 | unsigned long Time=(unsigned long)time(NULL); | 150 | unsigned long Time=(unsigned long)time(NULL); |
| 151 | void (*cb)(const SSL *ssl,int type,int val)=NULL; | 151 | void (*cb)(const SSL *ssl,int type,int val)=NULL; |
| 152 | int ret= -1; | 152 | int ret= -1; |
| 153 | int new_state,state,skip=0;; | 153 | int new_state,state,skip=0; |
| 154 | #ifndef OPENSSL_NO_SCTP | ||
| 155 | unsigned char sctpauthkey[64]; | ||
| 156 | char labelbuffer[sizeof(DTLS1_SCTP_AUTH_LABEL)]; | ||
| 157 | #endif | ||
| 154 | 158 | ||
| 155 | RAND_add(&Time,sizeof(Time),0); | 159 | RAND_add(&Time,sizeof(Time),0); |
| 156 | ERR_clear_error(); | 160 | ERR_clear_error(); |
| @@ -164,6 +168,27 @@ int dtls1_connect(SSL *s) | |||
| 164 | s->in_handshake++; | 168 | s->in_handshake++; |
| 165 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); | 169 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); |
| 166 | 170 | ||
| 171 | #ifndef OPENSSL_NO_SCTP | ||
| 172 | /* Notify SCTP BIO socket to enter handshake | ||
| 173 | * mode and prevent stream identifier other | ||
| 174 | * than 0. Will be ignored if no SCTP is used. | ||
| 175 | */ | ||
| 176 | BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE, s->in_handshake, NULL); | ||
| 177 | #endif | ||
| 178 | |||
| 179 | #ifndef OPENSSL_NO_HEARTBEATS | ||
| 180 | /* If we're awaiting a HeartbeatResponse, pretend we | ||
| 181 | * already got and don't await it anymore, because | ||
| 182 | * Heartbeats don't make sense during handshakes anyway. | ||
| 183 | */ | ||
| 184 | if (s->tlsext_hb_pending) | ||
| 185 | { | ||
| 186 | dtls1_stop_timer(s); | ||
| 187 | s->tlsext_hb_pending = 0; | ||
| 188 | s->tlsext_hb_seq++; | ||
| 189 | } | ||
| 190 | #endif | ||
| 191 | |||
| 167 | for (;;) | 192 | for (;;) |
| 168 | { | 193 | { |
| 169 | state=s->state; | 194 | state=s->state; |
| @@ -171,7 +196,7 @@ int dtls1_connect(SSL *s) | |||
| 171 | switch(s->state) | 196 | switch(s->state) |
| 172 | { | 197 | { |
| 173 | case SSL_ST_RENEGOTIATE: | 198 | case SSL_ST_RENEGOTIATE: |
| 174 | s->new_session=1; | 199 | s->renegotiate=1; |
| 175 | s->state=SSL_ST_CONNECT; | 200 | s->state=SSL_ST_CONNECT; |
| 176 | s->ctx->stats.sess_connect_renegotiate++; | 201 | s->ctx->stats.sess_connect_renegotiate++; |
| 177 | /* break */ | 202 | /* break */ |
| @@ -226,6 +251,42 @@ int dtls1_connect(SSL *s) | |||
| 226 | s->hit = 0; | 251 | s->hit = 0; |
| 227 | break; | 252 | break; |
| 228 | 253 | ||
| 254 | #ifndef OPENSSL_NO_SCTP | ||
| 255 | case DTLS1_SCTP_ST_CR_READ_SOCK: | ||
| 256 | |||
| 257 | if (BIO_dgram_sctp_msg_waiting(SSL_get_rbio(s))) | ||
| 258 | { | ||
| 259 | s->s3->in_read_app_data=2; | ||
| 260 | s->rwstate=SSL_READING; | ||
| 261 | BIO_clear_retry_flags(SSL_get_rbio(s)); | ||
| 262 | BIO_set_retry_read(SSL_get_rbio(s)); | ||
| 263 | ret = -1; | ||
| 264 | goto end; | ||
| 265 | } | ||
| 266 | |||
| 267 | s->state=s->s3->tmp.next_state; | ||
| 268 | break; | ||
| 269 | |||
| 270 | case DTLS1_SCTP_ST_CW_WRITE_SOCK: | ||
| 271 | /* read app data until dry event */ | ||
| 272 | |||
| 273 | ret = BIO_dgram_sctp_wait_for_dry(SSL_get_wbio(s)); | ||
| 274 | if (ret < 0) goto end; | ||
| 275 | |||
| 276 | if (ret == 0) | ||
| 277 | { | ||
| 278 | s->s3->in_read_app_data=2; | ||
| 279 | s->rwstate=SSL_READING; | ||
| 280 | BIO_clear_retry_flags(SSL_get_rbio(s)); | ||
| 281 | BIO_set_retry_read(SSL_get_rbio(s)); | ||
| 282 | ret = -1; | ||
| 283 | goto end; | ||
| 284 | } | ||
| 285 | |||
| 286 | s->state=s->d1->next_state; | ||
| 287 | break; | ||
| 288 | #endif | ||
| 289 | |||
| 229 | case SSL3_ST_CW_CLNT_HELLO_A: | 290 | case SSL3_ST_CW_CLNT_HELLO_A: |
| 230 | case SSL3_ST_CW_CLNT_HELLO_B: | 291 | case SSL3_ST_CW_CLNT_HELLO_B: |
| 231 | 292 | ||
| @@ -248,9 +309,17 @@ int dtls1_connect(SSL *s) | |||
| 248 | 309 | ||
| 249 | s->init_num=0; | 310 | s->init_num=0; |
| 250 | 311 | ||
| 251 | /* turn on buffering for the next lot of output */ | 312 | #ifndef OPENSSL_NO_SCTP |
| 252 | if (s->bbio != s->wbio) | 313 | /* Disable buffering for SCTP */ |
| 253 | s->wbio=BIO_push(s->bbio,s->wbio); | 314 | if (!BIO_dgram_is_sctp(SSL_get_wbio(s))) |
| 315 | { | ||
| 316 | #endif | ||
| 317 | /* turn on buffering for the next lot of output */ | ||
| 318 | if (s->bbio != s->wbio) | ||
| 319 | s->wbio=BIO_push(s->bbio,s->wbio); | ||
| 320 | #ifndef OPENSSL_NO_SCTP | ||
| 321 | } | ||
| 322 | #endif | ||
| 254 | 323 | ||
| 255 | break; | 324 | break; |
| 256 | 325 | ||
| @@ -260,9 +329,25 @@ int dtls1_connect(SSL *s) | |||
| 260 | if (ret <= 0) goto end; | 329 | if (ret <= 0) goto end; |
| 261 | else | 330 | else |
| 262 | { | 331 | { |
| 263 | dtls1_stop_timer(s); | ||
| 264 | if (s->hit) | 332 | if (s->hit) |
| 333 | { | ||
| 334 | #ifndef OPENSSL_NO_SCTP | ||
| 335 | /* Add new shared key for SCTP-Auth, | ||
| 336 | * will be ignored if no SCTP used. | ||
| 337 | */ | ||
| 338 | snprintf((char*) labelbuffer, sizeof(DTLS1_SCTP_AUTH_LABEL), | ||
| 339 | DTLS1_SCTP_AUTH_LABEL); | ||
| 340 | |||
| 341 | SSL_export_keying_material(s, sctpauthkey, | ||
| 342 | sizeof(sctpauthkey), labelbuffer, | ||
| 343 | sizeof(labelbuffer), NULL, 0, 0); | ||
| 344 | |||
| 345 | BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY, | ||
| 346 | sizeof(sctpauthkey), sctpauthkey); | ||
| 347 | #endif | ||
| 348 | |||
| 265 | s->state=SSL3_ST_CR_FINISHED_A; | 349 | s->state=SSL3_ST_CR_FINISHED_A; |
| 350 | } | ||
| 266 | else | 351 | else |
| 267 | s->state=DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A; | 352 | s->state=DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A; |
| 268 | } | 353 | } |
| @@ -354,12 +439,20 @@ int dtls1_connect(SSL *s) | |||
| 354 | case SSL3_ST_CR_SRVR_DONE_B: | 439 | case SSL3_ST_CR_SRVR_DONE_B: |
| 355 | ret=ssl3_get_server_done(s); | 440 | ret=ssl3_get_server_done(s); |
| 356 | if (ret <= 0) goto end; | 441 | if (ret <= 0) goto end; |
| 442 | dtls1_stop_timer(s); | ||
| 357 | if (s->s3->tmp.cert_req) | 443 | if (s->s3->tmp.cert_req) |
| 358 | s->state=SSL3_ST_CW_CERT_A; | 444 | s->s3->tmp.next_state=SSL3_ST_CW_CERT_A; |
| 359 | else | 445 | else |
| 360 | s->state=SSL3_ST_CW_KEY_EXCH_A; | 446 | s->s3->tmp.next_state=SSL3_ST_CW_KEY_EXCH_A; |
| 361 | s->init_num=0; | 447 | s->init_num=0; |
| 362 | 448 | ||
| 449 | #ifndef OPENSSL_NO_SCTP | ||
| 450 | if (BIO_dgram_is_sctp(SSL_get_wbio(s)) && | ||
| 451 | state == SSL_ST_RENEGOTIATE) | ||
| 452 | s->state=DTLS1_SCTP_ST_CR_READ_SOCK; | ||
| 453 | else | ||
| 454 | #endif | ||
| 455 | s->state=s->s3->tmp.next_state; | ||
| 363 | break; | 456 | break; |
| 364 | 457 | ||
| 365 | case SSL3_ST_CW_CERT_A: | 458 | case SSL3_ST_CW_CERT_A: |
| @@ -378,6 +471,22 @@ int dtls1_connect(SSL *s) | |||
| 378 | dtls1_start_timer(s); | 471 | dtls1_start_timer(s); |
| 379 | ret=dtls1_send_client_key_exchange(s); | 472 | ret=dtls1_send_client_key_exchange(s); |
| 380 | if (ret <= 0) goto end; | 473 | if (ret <= 0) goto end; |
| 474 | |||
| 475 | #ifndef OPENSSL_NO_SCTP | ||
| 476 | /* Add new shared key for SCTP-Auth, | ||
| 477 | * will be ignored if no SCTP used. | ||
| 478 | */ | ||
| 479 | snprintf((char*) labelbuffer, sizeof(DTLS1_SCTP_AUTH_LABEL), | ||
| 480 | DTLS1_SCTP_AUTH_LABEL); | ||
| 481 | |||
| 482 | SSL_export_keying_material(s, sctpauthkey, | ||
| 483 | sizeof(sctpauthkey), labelbuffer, | ||
| 484 | sizeof(labelbuffer), NULL, 0, 0); | ||
| 485 | |||
| 486 | BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY, | ||
| 487 | sizeof(sctpauthkey), sctpauthkey); | ||
| 488 | #endif | ||
| 489 | |||
| 381 | /* EAY EAY EAY need to check for DH fix cert | 490 | /* EAY EAY EAY need to check for DH fix cert |
| 382 | * sent back */ | 491 | * sent back */ |
| 383 | /* For TLS, cert_req is set to 2, so a cert chain | 492 | /* For TLS, cert_req is set to 2, so a cert chain |
| @@ -388,7 +497,15 @@ int dtls1_connect(SSL *s) | |||
| 388 | } | 497 | } |
| 389 | else | 498 | else |
| 390 | { | 499 | { |
| 391 | s->state=SSL3_ST_CW_CHANGE_A; | 500 | #ifndef OPENSSL_NO_SCTP |
| 501 | if (BIO_dgram_is_sctp(SSL_get_wbio(s))) | ||
| 502 | { | ||
| 503 | s->d1->next_state=SSL3_ST_CW_CHANGE_A; | ||
| 504 | s->state=DTLS1_SCTP_ST_CW_WRITE_SOCK; | ||
| 505 | } | ||
| 506 | else | ||
| 507 | #endif | ||
| 508 | s->state=SSL3_ST_CW_CHANGE_A; | ||
| 392 | s->s3->change_cipher_spec=0; | 509 | s->s3->change_cipher_spec=0; |
| 393 | } | 510 | } |
| 394 | 511 | ||
| @@ -400,7 +517,15 @@ int dtls1_connect(SSL *s) | |||
| 400 | dtls1_start_timer(s); | 517 | dtls1_start_timer(s); |
| 401 | ret=dtls1_send_client_verify(s); | 518 | ret=dtls1_send_client_verify(s); |
| 402 | if (ret <= 0) goto end; | 519 | if (ret <= 0) goto end; |
| 403 | s->state=SSL3_ST_CW_CHANGE_A; | 520 | #ifndef OPENSSL_NO_SCTP |
| 521 | if (BIO_dgram_is_sctp(SSL_get_wbio(s))) | ||
| 522 | { | ||
| 523 | s->d1->next_state=SSL3_ST_CW_CHANGE_A; | ||
| 524 | s->state=DTLS1_SCTP_ST_CW_WRITE_SOCK; | ||
| 525 | } | ||
| 526 | else | ||
| 527 | #endif | ||
| 528 | s->state=SSL3_ST_CW_CHANGE_A; | ||
| 404 | s->init_num=0; | 529 | s->init_num=0; |
| 405 | s->s3->change_cipher_spec=0; | 530 | s->s3->change_cipher_spec=0; |
| 406 | break; | 531 | break; |
| @@ -412,6 +537,14 @@ int dtls1_connect(SSL *s) | |||
| 412 | ret=dtls1_send_change_cipher_spec(s, | 537 | ret=dtls1_send_change_cipher_spec(s, |
| 413 | SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B); | 538 | SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B); |
| 414 | if (ret <= 0) goto end; | 539 | if (ret <= 0) goto end; |
| 540 | |||
| 541 | #ifndef OPENSSL_NO_SCTP | ||
| 542 | /* Change to new shared key of SCTP-Auth, | ||
| 543 | * will be ignored if no SCTP used. | ||
| 544 | */ | ||
| 545 | BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY, 0, NULL); | ||
| 546 | #endif | ||
| 547 | |||
| 415 | s->state=SSL3_ST_CW_FINISHED_A; | 548 | s->state=SSL3_ST_CW_FINISHED_A; |
| 416 | s->init_num=0; | 549 | s->init_num=0; |
| 417 | 550 | ||
| @@ -457,9 +590,23 @@ int dtls1_connect(SSL *s) | |||
| 457 | if (s->hit) | 590 | if (s->hit) |
| 458 | { | 591 | { |
| 459 | s->s3->tmp.next_state=SSL_ST_OK; | 592 | s->s3->tmp.next_state=SSL_ST_OK; |
| 593 | #ifndef OPENSSL_NO_SCTP | ||
| 594 | if (BIO_dgram_is_sctp(SSL_get_wbio(s))) | ||
| 595 | { | ||
| 596 | s->d1->next_state = s->s3->tmp.next_state; | ||
| 597 | s->s3->tmp.next_state=DTLS1_SCTP_ST_CW_WRITE_SOCK; | ||
| 598 | } | ||
| 599 | #endif | ||
| 460 | if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED) | 600 | if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED) |
| 461 | { | 601 | { |
| 462 | s->state=SSL_ST_OK; | 602 | s->state=SSL_ST_OK; |
| 603 | #ifndef OPENSSL_NO_SCTP | ||
| 604 | if (BIO_dgram_is_sctp(SSL_get_wbio(s))) | ||
| 605 | { | ||
| 606 | s->d1->next_state = SSL_ST_OK; | ||
| 607 | s->state=DTLS1_SCTP_ST_CW_WRITE_SOCK; | ||
| 608 | } | ||
| 609 | #endif | ||
| 463 | s->s3->flags|=SSL3_FLAGS_POP_BUFFER; | 610 | s->s3->flags|=SSL3_FLAGS_POP_BUFFER; |
| 464 | s->s3->delay_buf_pop_ret=0; | 611 | s->s3->delay_buf_pop_ret=0; |
| 465 | } | 612 | } |
| @@ -508,6 +655,16 @@ int dtls1_connect(SSL *s) | |||
| 508 | s->state=SSL3_ST_CW_CHANGE_A; | 655 | s->state=SSL3_ST_CW_CHANGE_A; |
| 509 | else | 656 | else |
| 510 | s->state=SSL_ST_OK; | 657 | s->state=SSL_ST_OK; |
| 658 | |||
| 659 | #ifndef OPENSSL_NO_SCTP | ||
| 660 | if (BIO_dgram_is_sctp(SSL_get_wbio(s)) && | ||
| 661 | state == SSL_ST_RENEGOTIATE) | ||
| 662 | { | ||
| 663 | s->d1->next_state=s->state; | ||
| 664 | s->state=DTLS1_SCTP_ST_CW_WRITE_SOCK; | ||
| 665 | } | ||
| 666 | #endif | ||
| 667 | |||
| 511 | s->init_num=0; | 668 | s->init_num=0; |
| 512 | break; | 669 | break; |
| 513 | 670 | ||
| @@ -515,6 +672,13 @@ int dtls1_connect(SSL *s) | |||
| 515 | s->rwstate=SSL_WRITING; | 672 | s->rwstate=SSL_WRITING; |
| 516 | if (BIO_flush(s->wbio) <= 0) | 673 | if (BIO_flush(s->wbio) <= 0) |
| 517 | { | 674 | { |
| 675 | /* If the write error was fatal, stop trying */ | ||
| 676 | if (!BIO_should_retry(s->wbio)) | ||
| 677 | { | ||
| 678 | s->rwstate=SSL_NOTHING; | ||
| 679 | s->state=s->s3->tmp.next_state; | ||
| 680 | } | ||
| 681 | |||
| 518 | ret= -1; | 682 | ret= -1; |
| 519 | goto end; | 683 | goto end; |
| 520 | } | 684 | } |
| @@ -541,6 +705,7 @@ int dtls1_connect(SSL *s) | |||
| 541 | /* else do it later in ssl3_write */ | 705 | /* else do it later in ssl3_write */ |
| 542 | 706 | ||
| 543 | s->init_num=0; | 707 | s->init_num=0; |
| 708 | s->renegotiate=0; | ||
| 544 | s->new_session=0; | 709 | s->new_session=0; |
| 545 | 710 | ||
| 546 | ssl_update_cache(s,SSL_SESS_CACHE_CLIENT); | 711 | ssl_update_cache(s,SSL_SESS_CACHE_CLIENT); |
| @@ -587,6 +752,15 @@ int dtls1_connect(SSL *s) | |||
| 587 | } | 752 | } |
| 588 | end: | 753 | end: |
| 589 | s->in_handshake--; | 754 | s->in_handshake--; |
| 755 | |||
| 756 | #ifndef OPENSSL_NO_SCTP | ||
| 757 | /* Notify SCTP BIO socket to leave handshake | ||
| 758 | * mode and allow stream identifier other | ||
| 759 | * than 0. Will be ignored if no SCTP is used. | ||
| 760 | */ | ||
| 761 | BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE, s->in_handshake, NULL); | ||
| 762 | #endif | ||
| 763 | |||
| 590 | if (buf != NULL) | 764 | if (buf != NULL) |
| 591 | BUF_MEM_free(buf); | 765 | BUF_MEM_free(buf); |
| 592 | if (cb != NULL) | 766 | if (cb != NULL) |
