SSL_accept() fails with return value -1

前端 未结 1 1947
难免孤独
难免孤独 2021-01-27 14:28

In order to understand SSL/TLS, I downloaded OpenSSL-1.0.2k on Windows-7 and compiled with Cygwin gcc 64 b

相关标签:
1条回答
  • 2021-01-27 15:01
    1. When you don't hit one of the SSL_ERROR_ cases you have enumerated, you should trace the value of SSL_get_error() so you can start debugging. Rather than just throwing up your hands.
    2. In this case the value was SSL_ERROR_SYSCALL. You didn't catch it where you thought you should because case (SSL_ERROR_SYSCALL || SSL_ERROR_SSL || SSL_ERROR_WANT_CONNECT || SSL_ERROR_WANT_ACCEPT): doesn't do what you think. It will turn into case 1 because of the semantics of ||. There should be separate case statements for each value.
    3. SSL_ERROR_SYSCALL means that the underlying error is in errno, as per the documentation you quoted yourself, which means that you should then trace that. Rather than just throwing up your hands. And note that you must do so before calling any other system calls (such as write() via printf()), so it might help to save errno immediately.
    4. You can either print errno directly with printf("errno=%d\n", errno), but it would be more useful to print the error message, which you can do with either perror() or printf("error=%s\n", syserror(errno)).
    5. The value of SSL_get_error() is not an errno value, and neither is the original -1 you started with. An errno value comes from the errno variable.
    6. However you shouldn't do any of these things unless SSL_accept() returned -1, for which there is no actual evidence here.

    So it is entirely possible that there is no error here at all.

    0 讨论(0)
提交回复
热议问题