From: Jack Lau <jacklau1222gm@gmail.com> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: Re: [FFmpeg-devel] [PATCH 02/14] avformat/tls_openssl: force dtls handshake to be blocking Date: Wed, 16 Jul 2025 11:08:15 +0800 Message-ID: <724034C9-296E-4353-9915-58F873DB404D@gmail.com> (raw) In-Reply-To: <20250713192512.928390-2-timo@rothenpieler.org> > On Jul 14, 2025, at 03:24, Timo Rothenpieler <timo@rothenpieler.org> wrote: > > There is no sensible way to handle this otherwise anyway, one just has > to loop over this function until it succeeds. > --- > libavformat/tls_openssl.c | 18 ++++++++++++------ > 1 file changed, 12 insertions(+), 6 deletions(-) > > diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c > index f6826222f9..54213c4090 100644 > --- a/libavformat/tls_openssl.c > +++ b/libavformat/tls_openssl.c > @@ -685,27 +685,33 @@ static int openssl_dtls_verify_callback(int preverify_ok, X509_STORE_CTX *ctx) > > static int dtls_handshake(URLContext *h) > { > - int ret = 0, r0, r1; > + int ret = 1, r0, r1; > TLSContext *p = h->priv_data; > > + int was_nonblock = h->flags & AVIO_FLAG_NONBLOCK; > + h->flags &= ~AVIO_FLAG_NONBLOCK; > + > r0 = SSL_do_handshake(p->ssl); > - r1 = SSL_get_error(p->ssl, r0); > if (r0 <= 0) { > + r1 = SSL_get_error(p->ssl, r0); > + > if (r1 != SSL_ERROR_WANT_READ && r1 != SSL_ERROR_WANT_WRITE && r1 != SSL_ERROR_ZERO_RETURN) { > - av_log(p, AV_LOG_ERROR, "TLS: Read failed, r0=%d, r1=%d %s\n", r0, r1, openssl_get_error(p)); > - ret = AVERROR(EIO); > + av_log(p, AV_LOG_ERROR, "Handshake failed, r0=%d, r1=%d\n", r0, r1); > + ret = print_ssl_error(h, r0); > goto end; > } > } else { > - av_log(p, AV_LOG_TRACE, "TLS: Read %d bytes, r0=%d, r1=%d\n", r0, r0, r1); > + av_log(p, AV_LOG_TRACE, "Handshake success, r0=%d\n", r0); > } > > - /* Check whether the DTLS is completed. */ > if (SSL_is_init_finished(p->ssl) != 1) > goto end; > > + ret = 0; > p->tls_shared.state = DTLS_STATE_FINISHED; > end: > + if (was_nonblock) > + h->flags |= AVIO_FLAG_NONBLOCK; > return ret; > } > > -- > 2.49.0 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe”. The flag of DTLS didn’t pass into udp, so maybe you should add this diff: diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c index 07d1af40d8..62f0df2202 100644 --- a/libavformat/tls_openssl.c +++ b/libavformat/tls_openssl.c @@ -701,9 +701,10 @@ static int dtls_handshake(URLContext *h) { int ret = 1, r0, r1; TLSContext *p = h->priv_data; - + TLSShared *c = &p->tls_shared; + URLContext *uc = c->is_dtls ? c->udp : c->tcp; int was_nonblock = h->flags & AVIO_FLAG_NONBLOCK; - h->flags &= ~AVIO_FLAG_NONBLOCK; + uc->flags &= ~AVIO_FLAG_NONBLOCK; r0 = SSL_do_handshake(p->ssl); if (r0 <= 0) { @@ -725,7 +726,7 @@ static int dtls_handshake(URLContext *h) p->tls_shared.state = DTLS_STATE_FINISHED; end: if (was_nonblock) - h->flags |= AVIO_FLAG_NONBLOCK; + uc->flags |= AVIO_FLAG_NONBLOCK; return ret; } Thanks Jack _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2025-07-16 3:08 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-07-13 19:24 [FFmpeg-devel] [PATCH 01/14] avformat/tls_openssl: set dtls remote addr in listen mode Timo Rothenpieler 2025-07-13 19:24 ` [FFmpeg-devel] [PATCH 02/14] avformat/tls_openssl: force dtls handshake to be blocking Timo Rothenpieler 2025-07-16 3:08 ` Jack Lau [this message] 2025-07-13 19:24 ` [FFmpeg-devel] [PATCH 03/14] avformat/tls_openssl: don't abort if dtls has no key/cert set Timo Rothenpieler 2025-07-13 19:24 ` [FFmpeg-devel] [PATCH 04/14] avformat/tls_openssl: initialize DTLS context with correct method Timo Rothenpieler 2025-07-13 19:24 ` [FFmpeg-devel] [PATCH 05/14] avformat/tls_openssl: set default MTU if none is set Timo Rothenpieler 2025-07-13 19:24 ` [FFmpeg-devel] [PATCH 06/14] avformat/tls_openssl: properly limit written size to data mtu Timo Rothenpieler 2025-07-13 19:24 ` [FFmpeg-devel] [PATCH 07/14] avformat/tls_openssl: don't hardcode ciphers and curves for dtls Timo Rothenpieler 2025-07-13 19:24 ` [FFmpeg-devel] [PATCH 08/14] avformat/tls_openssl: clean up peer verify logic in dtls mode Timo Rothenpieler 2025-07-13 19:24 ` [FFmpeg-devel] [PATCH 09/14] avformar/tls_openssl: use correct info callback in DTLS mode Timo Rothenpieler 2025-07-13 19:24 ` [FFmpeg-devel] [PATCH 10/14] avformat/tls_openssl: don't enable read_ahead in dtls mode Timo Rothenpieler 2025-07-13 19:24 ` [FFmpeg-devel] [PATCH 11/14] avformat/tls_openssl: properly free generated/read keys and certificates Timo Rothenpieler 2025-07-13 19:24 ` [FFmpeg-devel] [PATCH 12/14] avformat/tls_openssl: don't expose deprecated EC_KEY outside of its function Timo Rothenpieler 2025-07-13 19:24 ` [FFmpeg-devel] [PATCH 13/14] avformat/tls_openssl: make generating fingerprints optional Timo Rothenpieler 2025-07-13 19:24 ` [FFmpeg-devel] [PATCH 14/14] avformat/tls_openssl: automatically generate self-signed certificate when none is provided in listen mode Timo Rothenpieler 2025-07-15 11:57 ` [FFmpeg-devel] [PATCH 01/14] avformat/tls_openssl: set dtls remote addr " Timo Rothenpieler
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=724034C9-296E-4353-9915-58F873DB404D@gmail.com \ --to=jacklau1222gm@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git