appium / appium-ios-device

Tools for interacting with iOS devices

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feat: Add instruments service

YueChen-C opened this issue · comments

Adapted from https://github.com/YueChen-C/py-ios-device to https://github.com/appium/appium-ios-device
I have completed 90% of the work for the instruments protocol. And the test is successful above version 14. you can get fps, performance, netstat, etc.
but i have a problem on devices under version 14. After the ssl protocol is successfully handshake, I need to close the ssl protocol channel and use clear text transmission. I searched a lot of information, but I couldn't succeed.

Python:
https://github.com/YueChen-C/py-ios-device/blob/71267a1ac472db53fa84497312f0a4cdc0fdee17/ios_device/servers/Instrument.py#L29

nodejs:
https://github.com/YueChen-C/appium-ios-device/blob/b6f0fb42258f04ecc28509f756b089412b440db8/lib/services.js#L89

@KazuCocoa @mykola-mokhnach Could you spare some time to help me ?

Let me check. I don't have much knowledge about that, but probably I can help something after checking this code.

It would be great if @umutuzgur or @dvdmssmnn could share their knowledge.

I assume you could first create a raw socket connection and then call upgradeToSSL on it. The following commands could be still sent to the initial socket instead of the wrapped one if you want them to go unencrypted.

As far as I can see this should/may be handled automatically:

if (service.EnableServiceSSL) {

Yea, my understanding for ssl/non-ssl is EnableServiceSSL in its initial lockdown handshake.
It seems like instruments service differ from existing service's ssl(?). The EnableServiceSSL should be true over ios 13.

Then, probably we need to add an option to skip

return upgradeToSSL(socket, pairRecord.HostPrivateKey, pairRecord.HostCertificate);
for instrument?

After the ssl protocol is successfully handshake, I need to close the ssl protocol channel and use clear text transmission. I searched a lot of information, but I couldn't succeed.

Not sure if I get the question right. From what I understand you pretty much understood already what's going on with the services that do a SSL handshake, but continue the communication in plaintext.

And as @mykola-mokhnach said

I assume you could first create a raw socket connection and then call upgradeToSSL on it. The following commands could be still sent to the initial socket instead of the wrapped one if you want them to go unencrypted.

that should do the trick.

I can only point to the project https://github.com/danielpaulus/go-ios/ (which is anyways a great reference for everything in that area 🙂 )

There are a few services that behave like this: https://github.com/danielpaulus/go-ios/blob/a84a0cfbb66273ee78878bc0719451d389231b35/ios/connect.go#L49

And the handshake only part is done here:
https://github.com/danielpaulus/go-ios/blob/a84a0cfbb66273ee78878bc0719451d389231b35/ios/deviceconnection.go#L167

I tried it before,but it doesn't work.

I assume you could first create a raw socket connection and then call upgradeToSSL on it. The following commands could be still sent to the initial socket instead of the wrapped one if you want them to go unencrypted.

Through packet capture analysis. call upgradeToSSL does not start the ssl handshake. The ssl handshake is not started until data needs to be sent.
And after the ssl handshake is successful, the service will immediately return plaintext data instead of encrypted data, which will cause the socket to disconnect.

Is there a way to send and receive only ssl handshake packets?
@mykola-mokhnach @dvdmssmnn @KazuCocoa

I assume this needs some experimenting. I would try to call https://nodejs.org/api/tls.html#tlssocketrenegotiateoptions-callback or https://nodejs.org/api/net.html#socketconnect on the TLSSocket object and then continue sending data over the initial raw socket. Also, the TLSSocket has a non-documented destroySSL method. Maybe this is something that you need

In the worst case we can just drop the support of devices below iOS 14 🤷

will also take a look at the branch when i find time (btw, feel free to open a pr as draft :))

@YueChen-C Thanks for adding the new service. Do you have any plans about creating wrappers over other py-ios-device features, like profiles management, performance counters, etc?