summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2020-05-15 03:06:10 +0200
committerGravatar Nikias Bassen2020-05-15 03:06:10 +0200
commit916adfe3995152092d4d7cde3171d690292ffc51 (patch)
tree20df3ef8a394dc127b5b936e86cfc756e83eab37 /src
parent857fc15c2ce3e4c8b79511aa39934049ae5da906 (diff)
downloadlibimobiledevice-916adfe3995152092d4d7cde3171d690292ffc51.tar.gz
libimobiledevice-916adfe3995152092d4d7cde3171d690292ffc51.tar.bz2
idevice: [OpenSSL] Make sure SSL handshake works with non-blocking socket
Diffstat (limited to 'src')
-rw-r--r--src/idevice.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/idevice.c b/src/idevice.c
index 10d897f..3c312d2 100644
--- a/src/idevice.c
+++ b/src/idevice.c
@@ -28,6 +28,7 @@
28#include <stdlib.h> 28#include <stdlib.h>
29#include <string.h> 29#include <string.h>
30#include <errno.h> 30#include <errno.h>
31#include <time.h>
31 32
32#include <usbmuxd.h> 33#include <usbmuxd.h>
33#ifdef HAVE_OPENSSL 34#ifdef HAVE_OPENSSL
@@ -866,11 +867,6 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_conne
866 return IDEVICE_E_INVALID_ARG; 867 return IDEVICE_E_INVALID_ARG;
867 868
868 idevice_error_t ret = IDEVICE_E_SSL_ERROR; 869 idevice_error_t ret = IDEVICE_E_SSL_ERROR;
869#ifdef HAVE_OPENSSL
870 uint32_t return_me = 0;
871#else
872 int return_me = 0;
873#endif
874 plist_t pair_record = NULL; 870 plist_t pair_record = NULL;
875 871
876 userpref_read_pair_record(connection->device->udid, &pair_record); 872 userpref_read_pair_record(connection->device->udid, &pair_record);
@@ -958,9 +954,22 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_conne
958 SSL_set_verify(ssl, 0, ssl_verify_callback); 954 SSL_set_verify(ssl, 0, ssl_verify_callback);
959 SSL_set_bio(ssl, ssl_bio, ssl_bio); 955 SSL_set_bio(ssl, ssl_bio, ssl_bio);
960 956
961 return_me = SSL_do_handshake(ssl); 957 debug_info("Performing SSL handshake");
962 if (return_me != 1) { 958 int ssl_error = 0;
963 debug_info("ERROR in SSL_do_handshake: %s", ssl_error_to_string(SSL_get_error(ssl, return_me))); 959 do {
960 ssl_error = SSL_get_error(ssl, SSL_do_handshake(ssl));
961 if (ssl_error == 0 || ssl_error != SSL_ERROR_WANT_READ) {
962 break;
963 }
964#ifdef WIN32
965 Sleep(100);
966#else
967 struct timespec ts = { 0, 100000000 };
968 nanosleep(&ts, NULL);
969#endif
970 } while (1);
971 if (ssl_error != 0) {
972 debug_info("ERROR during SSL handshake: %s", ssl_error_to_string(ssl_error));
964 SSL_free(ssl); 973 SSL_free(ssl);
965 SSL_CTX_free(ssl_ctx); 974 SSL_CTX_free(ssl_ctx);
966 } else { 975 } else {
@@ -1014,6 +1023,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_conne
1014 debug_info("WARNING: errno says %s before handshake!", strerror(errno)); 1023 debug_info("WARNING: errno says %s before handshake!", strerror(errno));
1015 } 1024 }
1016 1025
1026 int return_me = 0;
1017 do { 1027 do {
1018 return_me = gnutls_handshake(ssl_data_loc->session); 1028 return_me = gnutls_handshake(ssl_data_loc->session);
1019 } while(return_me == GNUTLS_E_AGAIN || return_me == GNUTLS_E_INTERRUPTED); 1029 } while(return_me == GNUTLS_E_AGAIN || return_me == GNUTLS_E_INTERRUPTED);