libimobiledevice / usbmuxd

A socket daemon to multiplex connections from and to iOS devices
https://libimobiledevice.org
GNU General Public License v2.0
1.46k stars 352 forks source link

if no network device, first power on, connect very slow #146

Open yeahtoo opened 4 years ago

yeahtoo commented 4 years ago

Hi, my application use "usbmuxd_get_device_list" to get the device counts, if counts > 0 will connect the device. And i found the first power on(has no avliable network device), it almous wait 20~80 seconds to be connect successful,but the phone is always pluged on the hardware, and if i use plug a usb wifi or usb phy device, first power on, the connection will be very faster. and after first power on connect successful, i plug out and plug in the iphone, the connection is normal(not slow), if has network device or not. here is my application log:

Jul  7 12:00:04 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:05 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:06 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:07 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:08 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:09 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:10 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:11 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:12 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:13 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:14 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:15 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:16 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:17 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:18 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:19 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:20 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:21 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:22 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :0
Jul  7 12:00:23 (coco) user.debug syslog: [phone.c main_loop 244] usbmuxd_get_device_list :1
Jul  7 12:00:23 (coco) user.info syslog: [phone.c main_loop 276] connect port[62222] success!
Jul  7 12:00:23 (coco) user.info syslog: [phone.c main_loop 279] iphone connect success
yeahtoo commented 4 years ago

ok, at last i found the problem is in openssl, if no mac address the system entropy is generate very slow, so the program is block in openssl initial,so change the /dev/random to /dev/urandom,here is my modify in openssl: diff --git a/crypto/rand/rand_unix.c b/crypto/rand/rand_unix.c

index fe457ca..7059e94 100644
--- a/crypto/rand/rand_unix.c
+++ b/crypto/rand/rand_unix.c
@@ -633,7 +633,9 @@ size_t rand_pool_acquire_entropy(RAND_POOL *pool)
         bytes_needed = rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
         while (bytes_needed != 0 && attempts-- > 0) {
             buffer = rand_pool_add_begin(pool, bytes_needed);
-            bytes = syscall_random(buffer, bytes_needed);
+            memset(buffer, 0x26, bytes_needed);
+            bytes = bytes_needed;
+            // bytes = syscall_random(buffer, bytes_needed);
             if (bytes > 0) {
                 rand_pool_add_end(pool, bytes, 8 * bytes);
                 bytes_needed -= bytes;
diff --git a/e_os.h b/e_os.h
index 34223a0..94df2af 100644
--- a/e_os.h
+++ b/e_os.h
@@ -30,7 +30,7 @@
 #  define DEVRANDOM "/dev/urandom", "/dev/random", "/dev/hwrng", "/dev/srandom"
 #  if defined(__linux) && !defined(__ANDROID__)
 #   ifndef DEVRANDOM_WAIT
-#    define DEVRANDOM_WAIT   "/dev/random"
+#    define DEVRANDOM_WAIT   "/dev/urandom"
 #   endif
 /*
  * Linux kernels 4.8 and later changes how their random device works and there
mexmer commented 4 years ago

what you did is removing entropy from ssl generation, so it will have same initialization everytime, which is bad, because you need to catch communication only once, and then you will be able to decrypt it always.

first of, since this issue is with openssl, send it to openssl authors, second ... you really should not use openssl library patched with your "fix" if you care about your system security.

yeahtoo commented 4 years ago

what you did is removing entropy from ssl generation, so it will have same initialization everytime, which is bad, because you need to catch communication only once, and then you will be able to decrypt it always.

first of, since this issue is with openssl, send it to openssl authors, second ... you really should not use openssl library patched with your "fix" if you care about your system security.

ok, thanks for your advise