openssl ssl_connect永远阻止-如何设置超时时间? [英] openssl ssl_connect blocks forever - how to set timeout?

查看:1848
本文介绍了openssl ssl_connect永远阻止-如何设置超时时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用openssl编写的服务器未调用SSL_accept时,客户端的SSL_connect会永远阻塞. openssl -SSL_CTX_set_timeout和SSL_SESSION_set_timeout中有一些超时功能,但这些功能对SSL_connect无效.

when server written in openssl is'nt calling SSL_accept, client's SSL_connect blocks forever. There are some timeout functions in openssl -SSL_CTX_set_timeout , SSL_SESSION_set_timeout but these have no effect on SSL_connect.

例如,是否确实没有办法为SSL_connect设置超时时间? ssl服务器有问题,并在进行SSL握手之前进入循环?

Is there really no way of setting timeout for SSL_connect when e.g. ssl server is buggy and goes into loop before doing SSL handshake?

推荐答案

OpenSSL库在处理套接字相关问题方面为您提供了最大的灵活性.在您的情况下,SSL_connect会阻塞,因为您必须将其与阻塞套接字一起使用.请与非阻塞套接字一起使用,在这种情况下,它将返回-1.如果调用SSL_get_error函数,该函数将根据tcp recv或send无法分别完成操作的时间而给您SSL_ERROR_WANT_READSSL_ERROR_WANT_WRITE错误.

The OpenSSL Library gives you the maximum flexibility in terms of handling socket related issues. The SSL_connect blocks in your case because you must be using it with a blocking socket. Please use it with a non-blocking socket, in which case it will return with a -1. If you call SSL_get_error function which will give you SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE error depending on when the tcp recv or send is unable to complete the operation respectively.

获得SSL_ERROR_WANT_WRITE/SSL_ERROR_WANT_READ时,必须通过将套接字传递给适当的fd_set并超时来调用select函数.如果选择超时,则可以认为您的SSL_connect已超时.

When SSL_ERROR_WANT_WRITE/SSL_ERROR_WANT_READ is obtained, you must call select function by passing the socket to appropriate fd_set and a timeout. If the select times out, you can consider your SSL_connect to have timed out.

注意:SSL_SESSION_set_timeout用于设置链接到SSL恢复的会话超时值.它们与超时连接无关.

Note: The SSL_SESSION_set_timeout is used for setting session timeout values which are linked to SSL resumption. They have nothing to do with timing out a connection.

以下链接应为您提供帮助(尤其是第二个链接,第6节多路复用I/O"):

The below links should help you (especially the second link, Section 6 which talks about Multiplexed I/O):

  • Part 1
  • Part 2

这篇关于openssl ssl_connect永远阻止-如何设置超时时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆