doronz88 / pymobiledevice3

Pure python3 implementation for working with iDevices (iPhone, etc...).

Home Page:https://discord.gg/52mZGC3JXJ

Repository from Github https://github.comdoronz88/pymobiledevice3Repository from Github https://github.comdoronz88/pymobiledevice3

SSL: WRONG_VERSION_NUMBER occurs when launch WDA on iOS13

ethanx40 opened this issue · comments

Test environment

  • Host OS version: MacOS 14.5
  • iOS13.6.

Describe the bug
In a Python 3.8 environment, using the pymobiledevice3 developer dvt command to launch WDA on an iOS 13 device will result in an SSL WRONG_VERSION_NUMBER related error.

To Reproduce
Steps to reproduce the behavior:

  1. launch WDA by pymobiledevice3 developer dvt

Expected behavior
start WDA successfully.

Logs
(python3.8.0) ➜ ~ pymobiledevice3 developer dvt com.facebook.WebDriverAgentRunner.xctrunner -v
2024-09-02 11:50:29 VM-9-218-centos pymobiledevice3.services.dvt.testmanaged.xcuitest[32216] DEBUG remove /tmp/7F0CA6CB-A7E7-266F-419B-6E9D5C1AB01F.xctestconfiguration
Traceback (most recent call last):
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/pymobiledevice3/services/remote_server.py", line 466, in _recv_packet_fragments
message = self.channel_messages[channel].get()
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/pymobiledevice3/services/remote_server.py", line 294, in get
return self._messages.get_nowait()
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/queue.py", line 198, in get_nowait
return self.get(block=False)
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/queue.py", line 167, in get
raise Empty
_queue.Empty

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/data/miniconda3/envs/python3.8.0/bin/pymobiledevice3", line 8, in
sys.exit(main())
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/pymobiledevice3/main.py", line 100, in main
cli()
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/click/core.py", line 1157, in call
return self.main(*args, **kwargs)
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/pymobiledevice3/cli/cli_common.py", line 146, in wrap_callback_calling
callback(service_provider=service_provider, **kwargs)
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/pymobiledevice3/cli/developer.py", line 292, in xcuitest
XCUITestService(service_provider).run(bundle_id)
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/pymobiledevice3/services/dvt/testmanaged/xcuitest.py", line 53, in run
dvt1, chan1, dvt2, chan2 = self.init_ide_channels(session_identifier)
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/pymobiledevice3/services/dvt/testmanaged/xcuitest.py", line 127, in init_ide_channels
dvt1.perform_handshake()
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/pymobiledevice3/services/remote_server.py", line 387, in perform_handshake
ret, aux = self.recv_plist()
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/pymobiledevice3/services/remote_server.py", line 435, in recv_plist
data, aux = self.recv_message(channel)
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/pymobiledevice3/services/remote_server.py", line 447, in recv_message
packet_stream = self._recv_packet_fragments(channel)
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/pymobiledevice3/services/remote_server.py", line 471, in _recv_packet_fragments
data = self.service.recvall(dtx_message_header_struct.sizeof())
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/pymobiledevice3/service_connection.py", line 131, in recvall
chunk = self.recv(size - len(data))
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/site-packages/pymobiledevice3/service_connection.py", line 116, in recv
return self.socket.recv(length)
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/ssl.py", line 1226, in recv
return self.read(buflen)
File "/data/miniconda3/envs/python3.8.0/lib/python3.8/ssl.py", line 1101, in read
return self._sslobj.read(len)
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:2560)

Additional context
Add any other context about the problem here.

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

I don't have an iOS 13 device to test it with, but can you try removing the following line and test if this solves?
https://github.com/doronz88/pymobiledevice3/blob/master/pymobiledevice3/service_connection.py#L60

Also, please print: import ssl; print(ssl.OPENSSL_VERSION))

I don't have an iOS 13 device to test it with, but can you try removing the following line and test if this solves? https://github.com/doronz88/pymobiledevice3/blob/master/pymobiledevice3/service_connection.py#L60

I tried this way, but it still not work.

Also, please print: import ssl; print(ssl.OPENSSL_VERSION))

Also, please print: import ssl; print(ssl.OPENSSL_VERSION))

I created my envs with conda, and the default version is: OpenSSL 1.1.1w which do not work.
Then I upgrade openssl to OpenSSL 3.0.14 4 Jun 2024, but it still not work.

@doronz88 I found that this exception always occurs below iOS 14. Debugging revealed that it's caused by com.apple.testmanagerd.lockdown not removing the SSL context after the handshake. I create a PR to fix the bug.

#1176

Merged! Thanks for your contribution! :)