History

avformat/tls_openssl: force dtls handshake to be blocking

There is no sensible way to handle this otherwise anyway, one just has to loop over this function until it succeeds.

Timo Rothenpieler committed 1 year ago

Commit 951013e1 parent 87b09f31 file · +12 −6Browse files

Unified · Split

libavformat/tls_openssl.c+12−6
@@ -685,27 +685,33 @@ static int openssl_dtls_verify_callback(int preverify_ok, X509_STORE_CTX *ctx) · 684 unmodified lines
685 685
686static int dtls_handshake(URLContext *h)686static int dtls_handshake(URLContext *h)
687{687{
688 int ret = 0, r0, r1;688 int ret = 1, r0, r1;
689 TLSContext *p = h->priv_data;689 TLSContext *p = h->priv_data;
690 690
691 int was_nonblock = h->flags & AVIO_FLAG_NONBLOCK;
692 h->flags &= ~AVIO_FLAG_NONBLOCK;
693
691 r0 = SSL_do_handshake(p->ssl);694 r0 = SSL_do_handshake(p->ssl);
692 r1 = SSL_get_error(p->ssl, r0);
693 if (r0 <= 0) {695 if (r0 <= 0) {
696 r1 = SSL_get_error(p->ssl, r0);
697
694 if (r1 != SSL_ERROR_WANT_READ && r1 != SSL_ERROR_WANT_WRITE && r1 != SSL_ERROR_ZERO_RETURN) {698 if (r1 != SSL_ERROR_WANT_READ && r1 != SSL_ERROR_WANT_WRITE && r1 != SSL_ERROR_ZERO_RETURN) {
695 av_log(p, AV_LOG_ERROR, "TLS: Read failed, r0=%d, r1=%d %s\n", r0, r1, openssl_get_error(p));699 av_log(p, AV_LOG_ERROR, "Handshake failed, r0=%d, r1=%d\n", r0, r1);
696 ret = AVERROR(EIO);700 ret = print_ssl_error(h, r0);
697 goto end;701 goto end;
698 }702 }
699 } else {703 } else {
700 av_log(p, AV_LOG_TRACE, "TLS: Read %d bytes, r0=%d, r1=%d\n", r0, r0, r1);704 av_log(p, AV_LOG_TRACE, "Handshake success, r0=%d\n", r0);
701 }705 }
702 706
703 /* Check whether the DTLS is completed. */
704 if (SSL_is_init_finished(p->ssl) != 1)707 if (SSL_is_init_finished(p->ssl) != 1)
705 goto end;708 goto end;
706 709
710 ret = 0;
707 p->tls_shared.state = DTLS_STATE_FINISHED;711 p->tls_shared.state = DTLS_STATE_FINISHED;
708end:712end:
713 if (was_nonblock)
714 h->flags |= AVIO_FLAG_NONBLOCK;
709 return ret;715 return ret;
710}716}
711 717

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t