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 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <time.h>
#include <usbmuxd.h>
#ifdef HAVE_OPENSSL
@@ -866,11 +867,6 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_conne
return IDEVICE_E_INVALID_ARG;
idevice_error_t ret = IDEVICE_E_SSL_ERROR;
-#ifdef HAVE_OPENSSL
- uint32_t return_me = 0;
-#else
- int return_me = 0;
-#endif
plist_t pair_record = NULL;
userpref_read_pair_record(connection->device->udid, &pair_record);
@@ -958,9 +954,22 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_conne
SSL_set_verify(ssl, 0, ssl_verify_callback);
SSL_set_bio(ssl, ssl_bio, ssl_bio);
- return_me = SSL_do_handshake(ssl);
- if (return_me != 1) {
- debug_info("ERROR in SSL_do_handshake: %s", ssl_error_to_string(SSL_get_error(ssl, return_me)));
+ debug_info("Performing SSL handshake");
+ int ssl_error = 0;
+ do {
+ ssl_error = SSL_get_error(ssl, SSL_do_handshake(ssl));
+ if (ssl_error == 0 || ssl_error != SSL_ERROR_WANT_READ) {
+ break;
+ }
+#ifdef WIN32
+ Sleep(100);
+#else
+ struct timespec ts = { 0, 100000000 };
+ nanosleep(&ts, NULL);
+#endif
+ } while (1);
+ if (ssl_error != 0) {
+ debug_info("ERROR during SSL handshake: %s", ssl_error_to_string(ssl_error));
SSL_free(ssl);
SSL_CTX_free(ssl_ctx);
} else {
@@ -1014,6 +1023,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_conne
debug_info("WARNING: errno says %s before handshake!", strerror(errno));
}
+ int return_me = 0;
do {
return_me = gnutls_handshake(ssl_data_loc->session);
} while(return_me == GNUTLS_E_AGAIN || return_me == GNUTLS_E_INTERRUPTED);