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
685685
686686 static int dtls_handshake(URLContext *h)
687687 {
688− int ret = 0, r0, r1;
688+ int ret = 1, r0, r1;
689689 TLSContext *p = h->priv_data;
690690
691+ int was_nonblock = h->flags & AVIO_FLAG_NONBLOCK;
692+ h->flags &= ~AVIO_FLAG_NONBLOCK;
693+
691694 r0 = SSL_do_handshake(p->ssl);
692− r1 = SSL_get_error(p->ssl, r0);
693695 if (r0 <= 0) {
696+ r1 = SSL_get_error(p->ssl, r0);
697+
694698 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));
696− ret = AVERROR(EIO);
699+ av_log(p, AV_LOG_ERROR, "Handshake failed, r0=%d, r1=%d\n", r0, r1);
700+ ret = print_ssl_error(h, r0);
697701 goto end;
698702 }
699703 } 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);
701705 }
702706
703− /* Check whether the DTLS is completed. */
704707 if (SSL_is_init_finished(p->ssl) != 1)
705708 goto end;
706709
710+ ret = 0;
707711 p->tls_shared.state = DTLS_STATE_FINISHED;
708712 end:
713+ if (was_nonblock)
714+ h->flags |= AVIO_FLAG_NONBLOCK;
709715 return ret;
710716 }
711717

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